From: Rusty Russell Date: Thu, 13 Jan 2011 08:55:01 +0000 (+1030) Subject: htable: fix type of cmpfn in htable_type X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=23e4603462692031a29ea4b2a882f957de4f2922 htable: fix type of cmpfn in htable_type It in fact takes an object and a key to compare, not two keys. The test case had the key as first element of the object, so it worked, but ccanlint lost track of module dependencies due to this bug, and thus would build submodules multiple times. --- diff --git a/ccan/htable/htable_type.h b/ccan/htable/htable_type.h index 6fe05e2f..0d9e3fbb 100644 --- a/ccan/htable/htable_type.h +++ b/ccan/htable/htable_type.h @@ -63,7 +63,7 @@ static inline type *htable_##name##_get(const struct htable_##name *ht, \ const HTABLE_KTYPE(keyof) k) \ { \ /* Typecheck for cmpfn */ \ - (void)sizeof(cmpfn(keyof((const type *)NULL), \ + (void)sizeof(cmpfn((const type *)NULL, \ keyof((const type *)NULL))); \ return (type *)htable_get((const struct htable *)ht, \ hashfn(k), \ diff --git a/ccan/htable/test/run-type.c b/ccan/htable/test/run-type.c index 1ef42a4c..02dac29e 100644 --- a/ccan/htable/test/run-type.c +++ b/ccan/htable/test/run-type.c @@ -7,6 +7,8 @@ #define NUM_VALS (1 << HTABLE_BASE_BITS) struct obj { + /* Makes sure we don't try to treat and obj as a key or vice versa */ + unsigned char unused; unsigned int key; }; @@ -25,9 +27,9 @@ static size_t objhash(const unsigned int *key) return h; } -static bool cmp(const unsigned int *key1, const unsigned int *key2) +static bool cmp(const struct obj *obj, const unsigned int *key) { - return *key1 == *key2; + return obj->key == *key; } HTABLE_DEFINE_TYPE(struct obj, objkey, objhash, cmp, obj); diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c index 7b2565a9..14b2631e 100644 --- a/tools/ccanlint/file_analysis.c +++ b/tools/ccanlint/file_analysis.c @@ -33,9 +33,9 @@ static const char *manifest_name(const struct manifest *m) return m->dir; } -static bool dir_cmp(const char *dir1, const char *dir2) +static bool dir_cmp(const struct manifest *m, const char *dir) { - return strcmp(dir1, dir2) == 0; + return strcmp(m->dir, dir) == 0; } HTABLE_DEFINE_TYPE(struct manifest, manifest_name, dir_hash, dir_cmp, manifest);