]> git.ozlabs.org Git - ccan/commitdiff
htable: fix type of cmpfn in htable_type
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 13 Jan 2011 08:55:01 +0000 (19:25 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 13 Jan 2011 08:55:01 +0000 (19:25 +1030)
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.

ccan/htable/htable_type.h
ccan/htable/test/run-type.c
tools/ccanlint/file_analysis.c

index 6fe05e2fd8de9bf837451c1ba745b993e0e1c566..0d9e3fbb2dcce3ec7b183627d81fc577a3a82f24 100644 (file)
@@ -63,7 +63,7 @@ static inline type *htable_##name##_get(const struct htable_##name *ht,       \
                                        const HTABLE_KTYPE(keyof) k)    \
 {                                                                      \
        /* Typecheck for cmpfn */                                       \
                                        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),                            \
                           keyof((const type *)NULL)));                 \
        return (type *)htable_get((const struct htable *)ht,            \
                                  hashfn(k),                            \
index 1ef42a4c35e87858174666c80b760af2b686dde9..02dac29e10012f9f83f8451af73bfd05b545f10a 100644 (file)
@@ -7,6 +7,8 @@
 #define NUM_VALS (1 << HTABLE_BASE_BITS)
 
 struct obj {
 #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;
 };
 
        unsigned int key;
 };
 
@@ -25,9 +27,9 @@ static size_t objhash(const unsigned int *key)
        return h;
 }
 
        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);
 }
 
 HTABLE_DEFINE_TYPE(struct obj, objkey, objhash, cmp, obj);
index 7b2565a983377826fe1f8a9195744b83bbb713cb..14b2631e1ef630671748a78441e35995663659ce 100644 (file)
@@ -33,9 +33,9 @@ static const char *manifest_name(const struct manifest *m)
        return m->dir;
 }
 
        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);
 }
 
 HTABLE_DEFINE_TYPE(struct manifest, manifest_name, dir_hash, dir_cmp, manifest);