jmap: just use unsigned long, not size_t
authorRusty Russell <rusty@rustcorp.com.au>
Sun, 7 Nov 2010 01:45:10 +0000 (12:15 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Sun, 7 Nov 2010 01:45:10 +0000 (12:15 +1030)
Judy.h uses "Word_t" which it defines to an "unsigned long", so just use that.

If I were writing Judy from scratch, I'd use size_t or uintptr_t.

ccan/jmap/_info
ccan/jmap/jmap.c
ccan/jmap/jmap.h
ccan/jmap/jmap_type.h
ccan/jmap/test/run-access-count.c
ccan/jmap/test/run-uintidx-type.c
ccan/jmap/test/run.c

index 03aa4ca8fd471227882477aa793fa57eee880bbc..b7347f738858891bb751c30f8a4c6d2e21eb90a8 100644 (file)
@@ -55,7 +55,7 @@
  *             jmap_opt_add(opt, argv[i], d);
  *     }
  * 
- *     printf("Found %u options:\n", jmap_opt_count(opt));
+ *     printf("Found %lu options:\n", jmap_opt_count(opt));
  *     for (i = jmap_arg_first(arg,-1); i!=-1; i = jmap_arg_next(arg,i,-1)) {
  *             char *a = jmap_arg_get(arg, i);
  *             d = jmap_opt_get(opt, a);
index afac2fc9ff3adb1bc83f44ee26566be5c439f182..1773d56f5ddecc8afe4420fb17bc106ffe601025 100644 (file)
@@ -7,8 +7,10 @@ struct jmap *jmap_new(void)
 {
        struct jmap *map;
 
-       /* Judy uses unsigned long for Word_t, we use size_t. */
-       BUILD_ASSERT(sizeof(size_t) == sizeof(unsigned long));
+       /* Judy uses unsigned long for Word_t, we use unsigned long. */
+       BUILD_ASSERT(sizeof(Word_t) == sizeof(unsigned long));
+       /* We also put pointers into Judy, in jmap_types.h */
+       BUILD_ASSERT(sizeof(Word_t) >= sizeof(void *));
 
        map = malloc(sizeof(*map));
        if (map) {
index 93c03b9b03bbf3b0f043bf8d5cc456160f5adbe7..0b389b6079300fb6872b5ea67889acaf141821dc 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef CCAN_JMAP_H
 #define CCAN_JMAP_H
 #include <stddef.h>
-#define _WORD_T
-typedef size_t Word_t, *PWord_t;
 #include <Judy.h>
 #include <stdbool.h>
 #include <string.h>
@@ -42,15 +40,16 @@ struct jmap {
        /* Used if !NDEBUG */
        int num_accesses;
        /* Used if DEBUG */
-       size_t *acc_value;
-       size_t acc_index;
+       unsigned long *acc_value;
+       unsigned long acc_index;
        const char *funcname;
 };
 const char *COLD_ATTRIBUTE jmap_error_(struct jmap *map);
 
 /* Debugging checks. */
 static inline void jmap_debug_add_access(const struct jmap *map,
-                                        size_t index, size_t *val,
+                                        unsigned long index,
+                                        unsigned long *val,
                                         const char *funcname)
 {
 #ifdef DEBUG
@@ -64,7 +63,7 @@ static inline void jmap_debug_add_access(const struct jmap *map,
                assert(++((struct jmap *)map)->num_accesses);
 }
 
-static inline void jmap_debug_del_access(struct jmap *map, size_t **val)
+static inline void jmap_debug_del_access(struct jmap *map, unsigned long **val)
 {
        assert(--map->num_accesses >= 0);
 #ifdef DEBUG
@@ -80,7 +79,7 @@ static inline void jmap_debug_access(struct jmap *map)
 #ifdef DEBUG
        if (map->num_accesses && map->acc_value)
                fprintf(stderr,
-                       "jmap: still got index %zu, val %zu (%p) from %s\n",
+                       "jmap: still got index %lu, val %lu (%p) from %s\n",
                        map->acc_index, *map->acc_value, map->acc_value,
                        map->funcname);
 #endif
@@ -128,11 +127,12 @@ static inline const char *jmap_error(struct jmap *map)
  *     if (!jmap_add(map, 0, 1))
  *             err(1, "jmap_add failed!");
  */
-static inline bool jmap_add(struct jmap *map, size_t index, size_t value)
+static inline bool jmap_add(struct jmap *map,
+                           unsigned long index, unsigned long value)
 {
-       size_t *val;
+       unsigned long *val;
        jmap_debug_access(map);
-       val = (size_t *)JudyLIns(&map->judy, index, &map->err);
+       val = (unsigned long *)JudyLIns(&map->judy, index, &map->err);
        if (val == PJERR)
                return false;
        *val = value;
@@ -152,10 +152,12 @@ static inline bool jmap_add(struct jmap *map, size_t index, size_t value)
  *     if (!jmap_set(map, 0, 2))
  *             err(1, "jmap_set: index 0 not found");
  */
-static inline bool jmap_set(const struct jmap *map, size_t index, size_t value)
+static inline bool jmap_set(const struct jmap *map,
+                           unsigned long index, unsigned long value)
 {
-       size_t *val;
-       val = (size_t *)JudyLGet(map->judy, index, (JError_t *)&map->err);
+       unsigned long *val;
+       val = (unsigned long *)JudyLGet(map->judy, index,
+                                       (JError_t *)&map->err);
        if (val && val != PJERR) {
                *val = value;
                return true;
@@ -172,7 +174,7 @@ static inline bool jmap_set(const struct jmap *map, size_t index, size_t value)
  *     if (!jmap_del(map, 0))
  *             err(1, "jmap_del failed!");
  */
-static inline bool jmap_del(struct jmap *map, size_t index)
+static inline bool jmap_del(struct jmap *map, unsigned long index)
 {
        jmap_debug_access(map);
        return JudyLDel(&map->judy, index, &map->err) == 1;
@@ -187,7 +189,7 @@ static inline bool jmap_del(struct jmap *map, size_t index)
  *     jmap_add(map, 0, 1);
  *     assert(jmap_test(map, 0));
  */
-static inline bool jmap_test(const struct jmap *map, size_t index)
+static inline bool jmap_test(const struct jmap *map, unsigned long index)
 {
        return JudyLGet(map->judy, index, (JError_t *)&map->err) != NULL;
 }
@@ -205,11 +207,13 @@ static inline bool jmap_test(const struct jmap *map, size_t index)
  * See Also:
  *     jmap_getval()
  */
-static inline size_t jmap_get(const struct jmap *map, size_t index,
-                             size_t invalid)
+static inline unsigned long jmap_get(const struct jmap *map,
+                                    unsigned long index,
+                                    unsigned long invalid)
 {
-       size_t *val;
-       val = (size_t *)JudyLGet(map->judy, index, (JError_t *)&map->err);
+       unsigned long *val;
+       val = (unsigned long *)JudyLGet(map->judy, index,
+                                       (JError_t *)&map->err);
        if (!val || val == PJERR)
                return invalid;
        return *val;
@@ -224,8 +228,9 @@ static inline size_t jmap_get(const struct jmap *map, size_t index,
  * Example:
  *     assert(jmap_popcount(map, 0, 1000) <= jmap_popcount(map, 0, 2000));
  */
-static inline size_t jmap_popcount(const struct jmap *map,
-                                  size_t start, size_t end_incl)
+static inline unsigned long jmap_popcount(const struct jmap *map,
+                                         unsigned long start,
+                                         unsigned long end_incl)
 {
        return JudyLCount(map->judy, start, end_incl, (JError_t *)&map->err);
 }
@@ -241,22 +246,22 @@ static inline size_t jmap_popcount(const struct jmap *map,
  * map).  Otherwise you can use jmap_nthval().
  *
  * Example:
- *     size_t i, index;
+ *     unsigned long i, index;
  *
  *     // We know 0 isn't in map.
  *     assert(!jmap_test(map, 0));
  *     for (i = 0; (index = jmap_nth(map, i, 0)) != 0; i++) {
  *             assert(jmap_popcount(map, 0, index) == i);
- *             printf("Index %zu = %zu\n", i, index);
+ *             printf("Index %lu = %lu\n", i, index);
  *     }
  *
  * See Also:
  *     jmap_nthval();
  */
-static inline size_t jmap_nth(const struct jmap *map,
-                             size_t n, size_t invalid)
+static inline unsigned long jmap_nth(const struct jmap *map,
+                                    unsigned long n, unsigned long invalid)
 {
-       size_t index;
+       unsigned long index;
        if (!JudyLByCount(map->judy, n+1, &index, (JError_t *)&map->err))
                index = invalid;
        return index;
@@ -273,15 +278,16 @@ static inline size_t jmap_nth(const struct jmap *map,
  *     assert(!jmap_test(map, 0));
  *     printf("Map indices (increasing order):");
  *     for (i = jmap_first(map, 0); i; i = jmap_next(map, i, 0))
- *             printf(" %zu", i);
+ *             printf(" %lu", i);
  *     printf("\n");
  *
  * See Also:
  *     jmap_firstval()
  */
-static inline size_t jmap_first(const struct jmap *map, size_t invalid)
+static inline unsigned long jmap_first(const struct jmap *map,
+                                      unsigned long invalid)
 {
-       size_t index = 0;
+       unsigned long index = 0;
        if (!JudyLFirst(map->judy, &index, (JError_t *)&map->err))
                index = invalid;
        else
@@ -299,8 +305,9 @@ static inline size_t jmap_first(const struct jmap *map, size_t invalid)
  * See Also:
  *     jmap_nextval()
  */
-static inline size_t jmap_next(const struct jmap *map, size_t prev,
-                              size_t invalid)
+static inline unsigned long jmap_next(const struct jmap *map,
+                                     unsigned long prev,
+                                     unsigned long invalid)
 {
        if (!JudyLNext(map->judy, &prev, (JError_t *)&map->err))
                prev = invalid;
@@ -318,14 +325,15 @@ static inline size_t jmap_next(const struct jmap *map, size_t prev,
  *     assert(!jmap_test(map, 0));
  *     printf("Map indices (increasing order):");
  *     for (i = jmap_last(map, 0); i; i = jmap_prev(map, i, 0))
- *             printf(" %zu", i);
+ *             printf(" %lu", i);
  *     printf("\n");
  * See Also:
  *     jmap_lastval()
  */
-static inline size_t jmap_last(const struct jmap *map, size_t invalid)
+static inline unsigned long jmap_last(const struct jmap *map,
+                                     unsigned long invalid)
 {
-       size_t index = -1;
+       unsigned long index = -1;
        if (!JudyLLast(map->judy, &index, (JError_t *)&map->err))
                index = invalid;
        else
@@ -343,8 +351,9 @@ static inline size_t jmap_last(const struct jmap *map, size_t invalid)
  * See Also:
  *     jmap_prevval()
  */
-static inline size_t jmap_prev(const struct jmap *map, size_t prev,
-                              size_t invalid)
+static inline unsigned long jmap_prev(const struct jmap *map,
+                                     unsigned long prev,
+                                     unsigned long invalid)
 {
        if (!JudyLPrev(map->judy, &prev, (JError_t *)&map->err))
                prev = invalid;
@@ -367,7 +376,7 @@ static inline size_t jmap_prev(const struct jmap *map, size_t prev,
  * have called jmap_putval().
  *
  * Example:
- *     size_t *p;
+ *     unsigned long *p;
  *     jmap_add(map, 0, 1);
  *     p = jmap_getval(map, 0);
  *     if (!p)
@@ -381,10 +390,11 @@ static inline size_t jmap_prev(const struct jmap *map, size_t prev,
  * See Also:
  *     jmap_putval(), jmap_firstval()
  */
-static inline size_t *jmap_getval(struct jmap *map, size_t index)
+static inline unsigned long *jmap_getval(struct jmap *map, unsigned long index)
 {
-       size_t *val;
-       val = (size_t *)JudyLGet(map->judy, index, (JError_t *)&map->err);
+       unsigned long *val;
+       val = (unsigned long *)JudyLGet(map->judy, index,
+                                       (JError_t *)&map->err);
        jmap_debug_add_access(map, index, val, "jmap_getval");
        return val;
 }
@@ -404,7 +414,7 @@ static inline size_t *jmap_getval(struct jmap *map, size_t index)
  *     jmap_getval(), jmap_nthval(), jmap_firstval(), jmap_nextval(),
  *             jmap_lastval(), jmap_prevval().
  */
-static inline void jmap_putval(struct jmap *map, size_t **p)
+static inline void jmap_putval(struct jmap *map, unsigned long **p)
 {
        jmap_debug_del_access(map, p);
 }
@@ -419,24 +429,24 @@ static inline void jmap_putval(struct jmap *map, size_t **p)
  * You must use jmap_putval() on the pointer once you are done with it.
  *
  * Example:
- *     size_t *val;
+ *     unsigned long *val;
  *
  *     // We know 0 isn't in map.
  *     assert(!jmap_test(map, 0));
  *     for (i = 0; (val = jmap_nthval(map, i, &index)) != NULL; i++) {
  *             assert(jmap_popcount(map, 0, index) == i);
- *             printf("Index %zu = %zu, value = %zu\n", i, index, *val);
+ *             printf("Index %lu = %lu, value = %lu\n", i, index, *val);
  *             jmap_putval(map, &val);
  *     }
  *
  * See Also:
  *     jmap_nth();
  */
-static inline size_t *jmap_nthval(const struct jmap *map,
-                                 size_t n, size_t *index)
+static inline unsigned long *jmap_nthval(const struct jmap *map,
+                                        unsigned long n, unsigned long *index)
 {
-       size_t *val;
-       val = (size_t *)JudyLByCount(map->judy, n+1, index,
+       unsigned long *val;
+       val = (unsigned long *)JudyLByCount(map->judy, n+1, index,
                                     (JError_t *)&map->err);
        jmap_debug_add_access(map, *index, val, "jmap_nthval");
        return val;
@@ -461,11 +471,13 @@ static inline size_t *jmap_nthval(const struct jmap *map,
  * See Also:
  *     jmap_first, jmap_nextval()
  */
-static inline size_t *jmap_firstval(const struct jmap *map, size_t *index)
+static inline unsigned long *jmap_firstval(const struct jmap *map,
+                                          unsigned long *index)
 {
-       size_t *val;
+       unsigned long *val;
        *index = 0;
-       val = (size_t *)JudyLFirst(map->judy, index, (JError_t *)&map->err);
+       val = (unsigned long *)JudyLFirst(map->judy, index,
+                                         (JError_t *)&map->err);
        jmap_debug_add_access(map, *index, val, "jmap_firstval");
        return val;
 }
@@ -481,10 +493,12 @@ static inline size_t *jmap_firstval(const struct jmap *map, size_t *index)
  * See Also:
  *     jmap_firstval(), jmap_putval()
  */
-static inline size_t *jmap_nextval(const struct jmap *map, size_t *index)
+static inline unsigned long *jmap_nextval(const struct jmap *map,
+                                         unsigned long *index)
 {
-       size_t *val;
-       val = (size_t *)JudyLNext(map->judy, index, (JError_t *)&map->err);
+       unsigned long *val;
+       val = (unsigned long *)JudyLNext(map->judy, index,
+                                        (JError_t *)&map->err);
        jmap_debug_add_access(map, *index, val, "jmap_nextval");
        return val;
 }
@@ -497,11 +511,13 @@ static inline size_t *jmap_nextval(const struct jmap *map, size_t *index)
  * See Also:
  *     jmap_last(), jmap_putval()
  */
-static inline size_t *jmap_lastval(const struct jmap *map, size_t *index)
+static inline unsigned long *jmap_lastval(const struct jmap *map,
+                                         unsigned long *index)
 {
-       size_t *val;
+       unsigned long *val;
        *index = -1;
-       val = (size_t *)JudyLLast(map->judy, index, (JError_t *)&map->err);
+       val = (unsigned long *)JudyLLast(map->judy, index,
+                                        (JError_t *)&map->err);
        jmap_debug_add_access(map, *index, val, "jmap_lastval");
        return val;
 }
@@ -517,10 +533,12 @@ static inline size_t *jmap_lastval(const struct jmap *map, size_t *index)
  * See Also:
  *     jmap_lastval(), jmap_putval()
  */
-static inline size_t *jmap_prevval(const struct jmap *map, size_t *index)
+static inline unsigned long *jmap_prevval(const struct jmap *map,
+                                         unsigned long *index)
 {
-       size_t *val;
-       val = (size_t *)JudyLPrev(map->judy, index, (JError_t *)&map->err);
+       unsigned long *val;
+       val = (unsigned long *)JudyLPrev(map->judy, index,
+                                        (JError_t *)&map->err);
        jmap_debug_add_access(map, *index, val, "jmap_prevval");
        return val;
 }
index e61ba10946d260083c96207217b4d61eda2f2179..065526d79de7ca85d31f95eac7db19449d2f4c3e 100644 (file)
  * The following wrapper functions are defined; each one is the same as
  * the jmap.h generic equivalent except where noted:
  *
+ *     // Creating, errors and freeing.
  *     struct jmap_@name *jmap_@name_new(void);
  *     void jmap_@name_free(const struct jmap_@name *map);
  *     const char *jmap_@name_error(struct jmap_@name *map);
  *
+ *     // Add, set, delete, test and get.
  *     bool jmap_@name_add(const struct jmap_@name *map,
- *                         size_t index, const type *value);
+ *                         unsigned long idx, const type *value);
  *     bool jmap_@name_set(const struct jmap_@name *map,
- *                        size_t index, const type *value);
- *     bool jmap_@name_del(struct jmap_@name *map, size_t index);
- *     bool jmap_@name_test(const struct jmap_@name *map, size_t index);
+ *                        unsigned long idx, const type *value);
+ *     bool jmap_@name_del(struct jmap_@name *map, unsigned long idx);
+ *     bool jmap_@name_test(const struct jmap_@name *map, unsigned long idx);
+ *     type *jmap_@name_get(const struct jmap_@name *map, unsigned long idx);
  *
- *     type *jmap_@name_get(const struct jmap_@name *map, size_t index);
- *     size_t jmap_@name_popcount(const struct jmap_@name *map,
- *                                size_t start, size_t end_incl);
- *     size_t jmap_@name_nth(const struct jmap_@name *map,
- *                           size_t n, size_t invalid);
- *     size_t jmap_@name_first(const struct jmap_@name *map,
- *                             size_t invalid);
- *     size_t jmap_@name_next(const struct jmap_@name *map,
- *                             size_t prev, size_t invalid);
- *     size_t jmap_@name_last(const struct jmap_@name *map,
- *                             size_t invalid);
- *     size_t jmap_@name_prev(const struct jmap_@name *map,
- *                             size_t prev, size_t invalid);
+ *     // Counting and iteration.
+ *     unsigned long jmap_@name_popcount(const struct jmap_@name *map,
+ *                                       unsigned long start,
+ *                                       unsigned long end_incl);
+ *     unsigned long jmap_@name_nth(const struct jmap_@name *map,
+ *                                  unsigned long n, unsigned long invalid);
+ *     unsigned long jmap_@name_first(const struct jmap_@name *map,
+ *                                    unsigned long invalid);
+ *     unsigned long jmap_@name_next(const struct jmap_@name *map,
+ *                                   unsigned long prev,
+ *                                   unsigned long invalid);
+ *     unsigned long jmap_@name_last(const struct jmap_@name *map,
+ *                                   unsigned long invalid);
+ *     unsigned long jmap_@name_prev(const struct jmap_@name *map,
+ *                                   unsigned long prev,
+ *                                   unsigned long invalid);
  *
- *     type **jmap_@name_getval(const struct jmap_@name *map, size_t index);
+ *     // Get pointers to values to use.
+ *     type **jmap_@name_getval(const struct jmap_@name *map,
+ *                              unsigned long idx);
  *     void jmap_@name_putval(struct jmap_@name *map, type ***p);
  *     type **jmap_@name_nthval(struct jmap_@name *map,
- *                              size_t n, size_t *index);
+ *                              unsigned long n, unsigned long *idx);
  *     type **jmap_@name_firstval(const struct jmap_@name *map,
- *                                size_t *index);
- *     type **jmap_@name_nextval(const struct jmap_@name *map, size_t *index);
- *     type **jmap_@name_lastval(const struct jmap_@name *map, size_t *index);
- *     type **jmap_@name_prevval(const struct jmap_@name *map, size_t *index);
+ *                                unsigned long *idx);
+ *     type **jmap_@name_nextval(const struct jmap_@name *map,
+ *                              unsigned long *idx);
+ *     type **jmap_@name_lastval(const struct jmap_@name *map,
+ *                               unsigned long *idx);
+ *     type **jmap_@name_prevval(const struct jmap_@name *map,
+ *                               unsigned long *idx);
  */
 #define JMAP_DEFINE_UINTIDX_TYPE(type, name)                           \
 struct jmap_##name;                                                    \
@@ -63,109 +74,117 @@ static inline const char *jmap_##name##_error(struct jmap_##name *map)    \
        return jmap_error((struct jmap *)map);                          \
 }                                                                      \
 static inline bool jmap_##name##_add(struct jmap_##name *map,          \
-                                    size_t index, const type *value)   \
+                                    unsigned long idx, const type *value) \
 {                                                                      \
-       return jmap_add((struct jmap *)map, index, (size_t)value);      \
+       return jmap_add((struct jmap *)map, idx, (unsigned long)value); \
 }                                                                      \
 static inline bool jmap_##name##_set(const struct jmap_##name *map,    \
-                                    size_t index, const type *value)   \
+                                    unsigned long idx, const type *value) \
 {                                                                      \
-       return jmap_set((const struct jmap *)map, index, (size_t)value); \
+       return jmap_set((const struct jmap *)map, idx, (unsigned long)value); \
 }                                                                      \
-static inline bool jmap_##name##_del(struct jmap_##name *map, size_t index) \
+static inline bool jmap_##name##_del(struct jmap_##name *map,          \
+                                    unsigned long idx)                 \
 {                                                                      \
-       return jmap_del((struct jmap *)map, index);                     \
+       return jmap_del((struct jmap *)map, idx);                       \
 }                                                                      \
-static inline bool jmap_##name##_test(const struct jmap_##name *map,  \
-                                     size_t index)                     \
+static inline bool jmap_##name##_test(const struct jmap_##name *map,   \
+                                     unsigned long idx)                \
 {                                                                      \
-       return jmap_test((const struct jmap *)map, (size_t)index);      \
+       return jmap_test((const struct jmap *)map, (unsigned long)idx); \
 }                                                                      \
 static inline type *jmap_##name##_get(const struct jmap_##name *map,   \
-                                     size_t index)                     \
+                                     unsigned long idx)                \
 {                                                                      \
-       return (type *)jmap_get((const struct jmap *)map, index, 0);    \
+       return (type *)jmap_get((const struct jmap *)map, idx, 0);      \
 }                                                                      \
-static inline size_t jmap_##name##_popcount(const struct jmap_##name *map, \
-                                           size_t start, size_t end_incl) \
+static inline unsigned long                                            \
+jmap_##name##_popcount(const struct jmap_##name *map,                  \
+                      unsigned long start, unsigned long end_incl)     \
 {                                                                      \
        return jmap_popcount((const struct jmap *)map, start, end_incl); \
 }                                                                      \
-static inline size_t jmap_##name##_nth(const struct jmap_##name *map,  \
-                                      size_t n, size_t invalid)        \
+static inline unsigned long jmap_##name##_nth(const struct jmap_##name *map, \
+                                             unsigned long n,          \
+                                             unsigned long invalid)    \
 {                                                                      \
        return jmap_nth((const struct jmap *)map, n, invalid);          \
 }                                                                      \
-static inline size_t jmap_##name##_first(const struct jmap_##name *map,        \
-                                       size_t invalid)                 \
+static inline unsigned long                                            \
+jmap_##name##_first(const struct jmap_##name *map,                     \
+                   unsigned long invalid)                              \
 {                                                                      \
        return jmap_first((const struct jmap *)map, invalid);           \
 }                                                                      \
-static inline size_t jmap_##name##_next(const struct jmap_##name *map, \
-                                       size_t prev, size_t invalid)    \
+static inline unsigned long                                            \
+jmap_##name##_next(const struct jmap_##name *map,                      \
+                  unsigned long prev, unsigned long invalid)           \
 {                                                                      \
        return jmap_next((const struct jmap *)map, prev, invalid);      \
 }                                                                      \
-static inline size_t jmap_##name##_last(const struct jmap_##name *map, \
-                                       size_t invalid)                 \
+static inline unsigned long                                            \
+jmap_##name##_last(const struct jmap_##name *map,                      \
+                  unsigned long invalid)                               \
 {                                                                      \
        return jmap_last((const struct jmap *)map, invalid);            \
 }                                                                      \
-static inline size_t jmap_##name##_prev(const struct jmap_##name *map, \
-                                       size_t prev, size_t invalid)    \
+static inline unsigned long                                            \
+jmap_##name##_prev(const struct jmap_##name *map,                      \
+                  unsigned long prev, unsigned long invalid)           \
 {                                                                      \
        return jmap_prev((const struct jmap *)map, prev, invalid);      \
 }                                                                      \
 static inline type **jmap_##name##_getval(const struct jmap_##name *map, \
-                                         size_t index)                 \
+                                         unsigned long idx)            \
 {                                                                      \
-       return (type **)jmap_getval((struct jmap *)map, index);         \
+       return (type **)jmap_getval((struct jmap *)map, idx);           \
 }                                                                      \
 static inline void jmap_##name##_putval(struct jmap_##name *map,       \
                                          type ***p)                    \
 {                                                                      \
-       return jmap_putval((struct jmap *)map, (size_t **)p);           \
+       return jmap_putval((struct jmap *)map, (unsigned long **)p);    \
 }                                                                      \
 static inline type **jmap_##name##_nthval(struct jmap_##name *map,     \
-                                         size_t n, size_t *index)      \
+                                         unsigned long n,              \
+                                         unsigned long *idx)           \
 {                                                                      \
-       return (type **)jmap_nthval((struct jmap *)map, n, index);      \
+       return (type **)jmap_nthval((struct jmap *)map, n, idx);        \
 }                                                                      \
 static inline type **jmap_##name##_firstval(const struct jmap_##name *map, \
-                                           size_t *index)              \
+                                           unsigned long *idx)         \
 {                                                                      \
-       return (type **)jmap_firstval((const struct jmap *)map, index); \
+       return (type **)jmap_firstval((const struct jmap *)map, idx); \
 }                                                                      \
 static inline type **jmap_##name##_nextval(const struct jmap_##name *map, \
-                                          size_t *index)               \
+                                          unsigned long *idx)          \
 {                                                                      \
-       return (type **)jmap_nextval((const struct jmap *)map, index);  \
+       return (type **)jmap_nextval((const struct jmap *)map, idx);    \
 }                                                                      \
 static inline type **jmap_##name##_lastval(const struct jmap_##name *map, \
-                                           size_t *index)              \
+                                           unsigned long *idx)         \
 {                                                                      \
-       return (type **)jmap_lastval((const struct jmap *)map, index);  \
+       return (type **)jmap_lastval((const struct jmap *)map, idx);    \
 }                                                                      \
 static inline type **jmap_##name##_prevval(const struct jmap_##name *map, \
-                                          size_t *index)               \
+                                          unsigned long *idx)          \
 {                                                                      \
-       return (type **)jmap_prevval((const struct jmap *)map, index);  \
+       return (type **)jmap_prevval((const struct jmap *)map, idx);    \
 }
 
 /**
  * JMAP_DEFINE_PTRIDX_TYPE - create a map of jmap ops for ptr->ptr map
- * @itype: a type whose pointers will index into the map.
+ * @itype: a type whose pointers will idx into the map.
  * @type: a type whose pointers will be values in the map.
  * @name: a name for all the functions to define (of form jmap_<name>_*)
  *
  * This macro defines a map of inline functions for typesafe and
- * convenient usage of a pointer-indexed Judy map of pointers.  It is
- * assumed that a NULL pointer is never an index in the map, as
- * various functions return NULL for "invalid index".  Similarly,
- * jmap_@name_get will return NULL if an index isn't valid, so NULL indices
+ * convenient usage of a pointer-idxed Judy map of pointers.  It is
+ * assumed that a NULL pointer is never an idx in the map, as
+ * various functions return NULL for "invalid idx".  Similarly,
+ * jmap_@name_get will return NULL if an idx isn't valid, so NULL indices
  * are not recommended (though you can tell using jmap_@name_test).
  *
- * Since the ordering is by index pointer value, it's generally quite useless.
+ * Since the ordering is by idx pointer value, it's generally quite useless.
  * Thus we don't define order-specific functions, except first/next for
  * traversal.
  *
@@ -177,25 +196,25 @@ static inline type **jmap_##name##_prevval(const struct jmap_##name *map, \
  *     const char *jmap_@name_error(struct jmap_@name *map);
  *
  *     bool jmap_@name_add(const struct jmap_@name *map,
- *                         const itype *index, const type *value);
+ *                         const itype *idx, const type *value);
  *     bool jmap_@name_set(const struct jmap_@name *map,
- *                        const itype *index, const type *value);
- *     bool jmap_@name_del(struct jmap_@name *map, const itype *index);
- *     bool jmap_@name_test(const struct jmap_@name *map, const itype *index);
+ *                        const itype *idx, const type *value);
+ *     bool jmap_@name_del(struct jmap_@name *map, const itype *idx);
+ *     bool jmap_@name_test(const struct jmap_@name *map, const itype *idx);
  *
- *     type *jmap_@name_get(const struct jmap_@name *map, const itype *index);
+ *     type *jmap_@name_get(const struct jmap_@name *map, const itype *idx);
  *     itype *jmap_@name_count(const struct jmap_@name *map);
  *     itype *jmap_@name_first(const struct jmap_@name *map);
  *     itype *jmap_@name_next(const struct jmap_@name *map,
  *                            const itype *prev);
  *
  *     type **jmap_@name_getval(const struct jmap_@name *map,
- *                              const itype *index);
+ *                              const itype *idx);
  *     void jmap_@name_putval(struct jmap_@name *map, type ***p);
  *     type **jmap_@name_firstval(const struct jmap_@name *map,
- *                                const itype **index);
+ *                                const itype **idx);
  *     type **jmap_@name_nextval(const struct jmap_@name *map,
- *                               const itype **index);
+ *                               const itype **idx);
  */
 #define JMAP_DEFINE_PTRIDX_TYPE(itype, type, name)                     \
 struct jmap_##name;                                                    \
@@ -212,33 +231,35 @@ static inline const char *jmap_##name##_error(struct jmap_##name *map)    \
        return jmap_error((struct jmap *)map);                          \
 }                                                                      \
 static inline bool jmap_##name##_add(struct jmap_##name *map,          \
-                                    const itype *index, const type *value) \
+                                    const itype *idx, const type *value) \
 {                                                                      \
-       return jmap_add((struct jmap *)map, (size_t)index,              \
-                       (size_t)value);                                 \
+       return jmap_add((struct jmap *)map, (unsigned long)idx,         \
+                       (unsigned long)value);                          \
 }                                                                      \
 static inline bool jmap_##name##_set(const struct jmap_##name *map,    \
-                                    const itype *index, const type *value) \
+                                    const itype *idx, const type *value) \
 {                                                                      \
-       return jmap_set((const struct jmap *)map, (size_t)index,        \
-                       (size_t)value);                                 \
+       return jmap_set((const struct jmap *)map, (unsigned long)idx,   \
+                       (unsigned long)value);                          \
 }                                                                      \
 static inline bool jmap_##name##_del(struct jmap_##name *map,          \
-                                    const itype *index)                \
+                                    const itype *idx)                  \
 {                                                                      \
-       return jmap_del((struct jmap *)map, (size_t)index);             \
+       return jmap_del((struct jmap *)map, (unsigned long)idx);        \
 }                                                                      \
 static inline bool jmap_##name##_test(const struct jmap_##name *map,   \
-                                     const itype *index)               \
+                                     const itype *idx)                 \
 {                                                                      \
-       return jmap_test((const struct jmap *)map, (size_t)index);      \
+       return jmap_test((const struct jmap *)map, (unsigned long)idx); \
 }                                                                      \
 static inline type *jmap_##name##_get(const struct jmap_##name *map,   \
-                                     const itype *index)               \
+                                     const itype *idx)                 \
 {                                                                      \
-       return (type *)jmap_get((const struct jmap *)map, (size_t)index, 0); \
+       return (type *)jmap_get((const struct jmap *)map,               \
+                               (unsigned long)idx, 0);                 \
 }                                                                      \
-static inline size_t jmap_##name##_count(const struct jmap_##name *map) \
+static inline unsigned long                                            \
+jmap_##name##_count(const struct jmap_##name *map)                     \
 {                                                                      \
        return jmap_popcount((const struct jmap *)map, 0, -1);          \
 }                                                                      \
@@ -249,31 +270,33 @@ static inline itype *jmap_##name##_first(const struct jmap_##name *map)   \
 static inline itype *jmap_##name##_next(const struct jmap_##name *map, \
                                        const itype *prev)              \
 {                                                                      \
-       return (itype *)jmap_next((const struct jmap *)map, (size_t)prev, 0); \
+       return (itype *)jmap_next((const struct jmap *)map,             \
+                                 (unsigned long)prev, 0);              \
 }                                                                      \
 static inline type **jmap_##name##_getval(const struct jmap_##name *map, \
-                                         const itype *index)           \
+                                         const itype *idx)             \
 {                                                                      \
-       return (type **)jmap_getval((struct jmap *)map, (size_t)index); \
+       return (type **)jmap_getval((struct jmap *)map,                 \
+                                   (unsigned long)idx);                \
 }                                                                      \
 static inline void jmap_##name##_putval(struct jmap_##name *map,       \
                                        type ***p)                      \
 {                                                                      \
-       return jmap_putval((struct jmap *)map, (size_t **)p);           \
+       return jmap_putval((struct jmap *)map, (unsigned long **)p);    \
 }                                                                      \
 static inline type **jmap_##name##_firstval(const struct jmap_##name *map, \
-                                           itype **index)              \
+                                           itype **idx)                \
 {                                                                      \
-       size_t idx;                                                     \
+       unsigned long i;                                                \
        type **ret;                                                     \
-       ret = (type **)jmap_firstval((const struct jmap *)map, &idx);   \
-       *index = (void *)idx;                                           \
+       ret = (type **)jmap_firstval((const struct jmap *)map, &i);     \
+       *idx = (void *)i;                                               \
        return ret;                                                     \
 }                                                                      \
 static inline type **jmap_##name##_nextval(const struct jmap_##name *map, \
-                                          itype **index)               \
+                                          itype **idx)         \
 {                                                                      \
        return (type **)jmap_nextval((const struct jmap *)map,          \
-                                    (size_t *)index);                  \
+                                    (unsigned long *)idx);             \
 }
 #endif /* CCAN_JMAP_TYPE_H */
index c31f24ec93dad317c9605480fa8cc57bd7db24d2..288e894c6e4acf69d909bab97781af0aaef18230 100644 (file)
@@ -8,7 +8,7 @@
 int main(int argc, char *argv[])
 {
        struct jmap *map;
-       size_t *value;
+       unsigned long *value;
        int status;
 
        plan_tests(9);
index 1dcb8829048adf0f99cf3717f6eb2eb3b50214e2..0dda6eddfb7224ae54a946e02d30d9c17cd32c66 100644 (file)
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
 {
        struct jmap_foo *map;
        struct foo *foo[NUM], **foop;
-       unsigned int i;
+       unsigned long i;
 
        plan_tests(37 + NUM*2 + 19);
        for (i = 0; i < NUM; i++)
index 7f91489d15af32b822f3eec0783430fd1e0052c5..5f5c932f0ba8191baa0de6b5f0adcfdd68e696ef 100644 (file)
@@ -5,7 +5,7 @@
 int main(int argc, char *argv[])
 {
        struct jmap *map;
-       size_t i, *value;
+       unsigned long i, *value;
        const char *err;
 
        plan_tests(53);