From de9220ce161785a45cd3c0a82d5678dc3de3d10a Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Fri, 18 Oct 2013 15:25:11 -0400 Subject: [PATCH] ck_array: Change semantics of put_unique return values. More specifically, -1 should idiomatically indicate error. --- doc/Makefile.in | 7 ++++++- regressions/ck_array/validate/serial.c | 6 +++--- src/ck_array.c | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/Makefile.in b/doc/Makefile.in index d5939e5..57bea1a 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -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 \ diff --git a/regressions/ck_array/validate/serial.c b/regressions/ck_array/validate/serial.c index cc6a2d8..b6d7b56 100644 --- a/regressions/ck_array/validate/serial.c +++ b/regressions/ck_array/validate/serial.c @@ -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"); } diff --git a/src/ck_array.c b/src/ck_array.c index 390c595..bc58ed7 100644 --- a/src/ck_array.c +++ b/src/ck_array.c @@ -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