X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhtable%2Fhtable_type.h;h=14011676903807fed252318ef5884b55f14e9556;hp=9c20531f2ab184c8a0fb834862a00945b3863264;hb=e0b86f0ca416d757684e6d98532e1fadf839b830;hpb=fb92682e8b55b813fd4bcfad42b63e57cd9aae21 diff --git a/ccan/htable/htable_type.h b/ccan/htable/htable_type.h index 9c20531f..14011676 100644 --- a/ccan/htable/htable_type.h +++ b/ccan/htable/htable_type.h @@ -90,13 +90,17 @@ static inline UNNEEDED type *name##_get(const struct name *ht, \ const HTABLE_KTYPE(keyof, type) k) \ { \ - /* Typecheck for eqfn */ \ - (void)sizeof(eqfn((const type *)NULL, \ - keyof((const type *)NULL))); \ - return htable_get(&ht->raw, \ - hashfn(k), \ - (bool (*)(const void *, void *))(eqfn), \ - k); \ + struct htable_iter i; \ + size_t h = hashfn(k); \ + void *c; \ + \ + for (c = htable_firstval(&ht->raw,&i,h); \ + c; \ + c = htable_nextval(&ht->raw,&i,h)) { \ + if (eqfn(c, k)) \ + return c; \ + } \ + return NULL; \ } \ static inline UNNEEDED type *name##_getmatch_(const struct name *ht, \ const HTABLE_KTYPE(keyof, type) k, \ @@ -154,6 +158,9 @@ #if HAVE_TYPEOF #define HTABLE_KTYPE(keyof, type) typeof(keyof((const type *)NULL)) #else +/* Assumes keys are a pointer: if not, override. */ +#ifndef HTABLE_KTYPE #define HTABLE_KTYPE(keyof, type) void * #endif +#endif #endif /* CCAN_HTABLE_TYPE_H */