Skip to content

Commit

Permalink
Naming; ids[] for endids.
Browse files Browse the repository at this point in the history
  • Loading branch information
katef committed Jun 16, 2024
1 parent 99fa19c commit f663cd4
Show file tree
Hide file tree
Showing 21 changed files with 279 additions and 270 deletions.
8 changes: 4 additions & 4 deletions src/libfsm/endids.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ fsm_endid_count(const struct fsm *fsm,

int
fsm_endid_get(const struct fsm *fsm, fsm_state_t end_state,
size_t id_buf_count, fsm_end_id_t *id_buf)
size_t count, fsm_end_id_t *ids)
{
size_t i;
const struct endid_info *ei = NULL;
Expand All @@ -695,7 +695,7 @@ fsm_endid_get(const struct fsm *fsm, fsm_state_t end_state,
ei = fsm->endid_info;
assert(ei != NULL);

assert(id_buf != NULL);
assert(ids != NULL);

mask = ei->bucket_count - 1;
/* bucket count is a power of 2 */
Expand All @@ -721,7 +721,7 @@ fsm_endid_get(const struct fsm *fsm, fsm_state_t end_state,

if (b->state == end_state) {
size_t id_i;
if (b->ids->count > id_buf_count) {
if (b->ids->count > count) {
#if LOG_ENDIDS > 2
fprintf(stderr, "fsm_endid_get: insufficient space\n");
#endif
Expand All @@ -731,7 +731,7 @@ fsm_endid_get(const struct fsm *fsm, fsm_state_t end_state,
#if LOG_ENDIDS > 2
fprintf(stderr, "fsm_endid_get: writing id[%zu]: %d\n", id_i, b->ids->ids[id_i]);
#endif
id_buf[id_i] = b->ids->ids[id_i];
ids[id_i] = b->ids->ids[id_i];
}

/* todo: could sort them here, if it matters. */
Expand Down
26 changes: 13 additions & 13 deletions src/libfsm/minimise_test_oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
unsigned *endid_group_assignments = NULL;
size_t endid_group_count = 1; /* group 0 is the empty set */
unsigned *endid_group_leaders = NULL;
fsm_end_id_t *endid_buf_a = NULL;
fsm_end_id_t *endid_buf_b = NULL;
fsm_end_id_t *ids_a = NULL;
fsm_end_id_t *ids_b = NULL;

table = calloc(row_words * table_states, sizeof(table[0]));
if (table == NULL) { goto cleanup; }
Expand Down Expand Up @@ -165,10 +165,10 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
}
}

endid_buf_a = malloc(max_endid_count * sizeof(endid_buf_a[0]));
if (endid_buf_a == NULL) { goto cleanup; }
endid_buf_b = malloc(max_endid_count * sizeof(endid_buf_b[0]));
if (endid_buf_b == NULL) { goto cleanup; }
ids_a = malloc(max_endid_count * sizeof(ids_a[0]));
if (ids_a == NULL) { goto cleanup; }
ids_b = malloc(max_endid_count * sizeof(ids_b[0]));
if (ids_b == NULL) { goto cleanup; }

/* For every end state, check if it has endids. If not, assign it
* to endid group 0 (none). Otherwise, check if its endids match
Expand All @@ -187,7 +187,7 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
}

int eres = fsm_endid_get(fsm, i,
count_a, endid_buf_a);
count_a, ids_a);
assert(eres == 1);

bool found = false;
Expand All @@ -201,10 +201,10 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
assert(count_b > 0);
assert(count_b <= max_endid_count);
eres = fsm_endid_get(fsm, endid_group_leaders[eg_i],
count_b, endid_buf_b);
count_b, ids_b);
assert(eres == 1);

if (0 == memcmp(endid_buf_a, endid_buf_b, count_a * sizeof(endid_buf_a[0]))) {
if (0 == memcmp(ids_a, ids_b, count_a * sizeof(ids_a[0]))) {
found = true;
endid_group_assignments[i] = eg_i;
break;
Expand Down Expand Up @@ -361,8 +361,8 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
free(mapping);
free(endid_group_assignments);
free(endid_group_leaders);
free(endid_buf_a);
free(endid_buf_b);
free(ids_a);
free(ids_b);

return res;

Expand All @@ -372,8 +372,8 @@ fsm_minimise_test_oracle(const struct fsm *fsm)
if (mapping != NULL) { free(mapping); }
if (endid_group_assignments != NULL) { free(endid_group_assignments); }
if (endid_group_leaders != NULL) { free(endid_group_leaders); }
if (endid_buf_a != NULL) { free(endid_buf_a); }
if (endid_buf_b != NULL) { free(endid_buf_b); }
if (ids_a != NULL) { free(ids_a); }
if (ids_b != NULL) { free(ids_b); }
if (res != NULL) { fsm_free(res); }
return NULL;
}
39 changes: 24 additions & 15 deletions src/libfsm/walk2.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,45 +263,54 @@ fsm_walk2_tuple_new(struct fsm_walk2_data *data,
}

if (is_end) {
size_t num_a_endids = 0, num_b_endids = 0, total_num_endids;
size_t count_a = 0, count_b = 0, count_total;

if (fsm_a != NULL && fsm_isend(fsm_a,a)) {
num_a_endids = fsm_endid_count(fsm_a, a);
count_a = fsm_endid_count(fsm_a, a);
}

if (fsm_b != NULL && fsm_isend(fsm_b,b)) {
num_b_endids = fsm_endid_count(fsm_b, b);
count_b = fsm_endid_count(fsm_b, b);
}

total_num_endids = num_a_endids + num_b_endids;
count_total = count_a + count_b;

if (total_num_endids > 0) {
fsm_end_id_t *endids;
if (count_total > 0) {
const struct fsm_alloc *alloc;
fsm_end_id_t *ids;
int ret;

endids = calloc(total_num_endids, sizeof endids[0]);
if (endids == NULL) {
if (fsm_a != NULL) {
alloc = fsm_a->opt->alloc;
} else if (fsm_b != NULL) {
alloc = fsm_b->opt->alloc;
} else {
assert(!"unreached");
}

ids = f_malloc(alloc, count_total * sizeof *ids);
if (ids == NULL) {
return NULL;
}

if (num_a_endids > 0) {
ret = fsm_endid_get(fsm_a, a, num_a_endids, endids);
if (count_a > 0) {
ret = fsm_endid_get(fsm_a, a, count_a, ids);
assert(ret == 1);
}

if (num_b_endids > 0) {
ret = fsm_endid_get(fsm_b, b, num_b_endids, endids + num_a_endids);
if (count_b > 0) {
ret = fsm_endid_get(fsm_b, b, count_b, ids + count_a);
assert(ret == 1);
}

ret = fsm_endid_set_bulk(
data->new,
p->comb,
total_num_endids,
&endids[0],
count_total,
&ids[0],
FSM_ENDID_BULK_REPLACE);

free(endids);
f_free(alloc, ids);

if (!ret) {
int errsv = errno;
Expand Down
12 changes: 6 additions & 6 deletions tests/capture/captest.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ captest_run_single(const struct captest_single_fsm_test_info *info)
if (end != strlen(info->string)) { FAIL("exec end pos"); }

{
fsm_end_id_t id_buf[1] = { ~0 };
fsm_end_id_t ids[1] = { ~0 };
int gres;
if (1 != fsm_endid_count(fsm, end)) {
FAIL("did not have exactly one end ID");
}

gres = fsm_endid_get(fsm, end, 1, id_buf);
gres = fsm_endid_get(fsm, end, 1, ids);
if (gres != 1) {
FAIL("failed to get end IDs");
}

if (0 != id_buf[0]) {
if (0 != ids[0]) {
FAIL("failed to get end ID of 0");
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ int
captest_check_single_end_id(const struct fsm *fsm, fsm_state_t end_state,
unsigned expected_end_id, const char **msg)
{
fsm_end_id_t id_buf[1] = { ~0 };
fsm_end_id_t ids[1] = { ~0 };
int gres;
const char *unused;

Expand All @@ -193,13 +193,13 @@ captest_check_single_end_id(const struct fsm *fsm, fsm_state_t end_state,
return 0;
}

gres = fsm_endid_get(fsm, end_state, 1, id_buf);
gres = fsm_endid_get(fsm, end_state, 1, ids);
if (gres != 1) {
*msg = "failed to get end IDs";
return 0;
}

if (expected_end_id != id_buf[0]) {
if (expected_end_id != ids[0]) {
*msg = "failed to get expected end ID";
return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/capture/capture4.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,20 @@ check(const struct fsm *fsm, const char *string,

{
int gres;
fsm_end_id_t id_buf[2];
fsm_end_id_t ids[2];

gres = fsm_endid_get(fsm, end, 2, id_buf);
gres = fsm_endid_get(fsm, end, 2, ids);
if (gres != 1) {
assert(!"fsm_getendids failed");
}

if (expected_ends == 0x2) {
assert(fsm_endid_count(fsm, end) == 1);
assert(id_buf[0] == 1);
assert(ids[0] == 1);
} else if (expected_ends == 0x3) {
assert(fsm_endid_count(fsm, end) == 2);
assert(id_buf[0] == 0);
assert(id_buf[1] == 1);
assert(ids[0] == 0);
assert(ids[1] == 1);
} else {
assert(!"test not handled");
}
Expand Down
30 changes: 15 additions & 15 deletions tests/endids/endids0.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(void)
// memset(all_endids, 0, sizeof all_endids);
for (state_ind = 0; state_ind < nstates; state_ind++) {
if (fsm_isend(fsm, state_ind)) {
fsm_end_id_t endid = 0;
fsm_end_id_t id = 0;
int ret;

assert( fsm_endid_count(fsm, state_ind) == 1);
Expand All @@ -52,10 +52,10 @@ int main(void)
fsm,
state_ind,
1,
&endid);
&id);

assert(ret == 1);
assert(endid == 1);
assert(id == 1);

nend++;
}
Expand Down Expand Up @@ -84,26 +84,26 @@ int main(void)
};

for (i=0; i < sizeof matches / sizeof matches[0]; i++) {
fsm_end_id_t *end_ids;
size_t num_end_ids;
fsm_end_id_t *ids;
size_t count;

end_ids = NULL;
num_end_ids = 0;
ret = match_string(fsm, matches[i].s, NULL, &end_ids, &num_end_ids);
ids = NULL;
count = 0;
ret = match_string(fsm, matches[i].s, NULL, &ids, &count);

if (matches[i].should_match) {
assert( ret == 1 );
assert( end_ids != NULL );
assert( end_ids[0] = 1 );
assert( num_end_ids == 1 );
assert( end_ids[0] = matches[i].endid );
assert( ids != NULL );
assert( ids[0] = 1 );
assert( count == 1 );
assert( ids[0] = matches[i].endid );
} else {
assert( ret == 0 );
assert( end_ids == NULL );
assert( num_end_ids == 0 );
assert( ids == NULL );
assert( count == 0 );
}

free(end_ids);
free(ids);
}
}

Expand Down
Loading

0 comments on commit f663cd4

Please sign in to comment.