ck_array: Change semantics of put_unique return values.

More specifically, -1 should idiomatically indicate error.
ck_pring
Samy Al Bahra 11 years ago
parent 9be176959e
commit de9220ce16

@ -7,7 +7,12 @@ BUILD_DIR=@BUILD_DIR@
SRC_DIR=@SRC_DIR@
HTML_SUFFIX=.html
OBJECTS=ck_brlock \
OBJECTS=ck_array_commit \
ck_array_init \
ck_array_put \
ck_array_put_unique \
ck_array_remove \
ck_brlock \
ck_ht_count \
ck_ht_destroy \
ck_ht_get_spmc \

@ -124,10 +124,10 @@ main(void)
if (ck_array_put_unique(&array, (void *)UINTPTR_MAX) != 0)
ck_error("Unique value put failed.\n");
if (ck_array_put_unique(&array, (void *)(uintptr_t)4) != -1)
if (ck_array_put_unique(&array, (void *)(uintptr_t)4) != 1)
ck_error("put of 4 not detected as non-unique.\n");
if (ck_array_put_unique(&array, (void *)UINTPTR_MAX) != -1)
if (ck_array_put_unique(&array, (void *)UINTPTR_MAX) != 1)
ck_error("put of UINTPTR_MAX not detected as non-unique.\n");
ck_array_commit(&array);
@ -153,7 +153,7 @@ main(void)
for (i = 0; i < ITERATION * 128; i++) {
ck_array_put(&array, (void *)i);
if (ck_array_put_unique(&array, (void *)i) != -1)
if (ck_array_put_unique(&array, (void *)i) != 1)
ck_error("put_unique for non-unique value should fail.\n");
}

@ -140,10 +140,10 @@ ck_array_put_unique(struct ck_array *array, void *value)
for (i = 0; i < limit; i++) {
if (v[i] == value)
return -1;
return 1;
}
return !ck_array_put(array, value);
return -!ck_array_put(array, value);
}
bool

Loading…
Cancel
Save