From d6d4eda80ef12f9e9f71921d0d4acee2faf0ccb0 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 2 Feb 2007 12:02:39 +0100 Subject: [PATCH] Use uintptr_t instead of addr_int_t. No need to use our own type when we already rely on C99 anyway. --- images/image-test.c | 2 +- lib/bigalloc.c | 2 +- lib/conf-dump.c | 2 +- lib/conf-intr.c | 8 ++++---- lib/conf-section.c | 10 +++++----- lib/fastbuf.h | 2 +- lib/hashfunc.h | 2 +- lib/kmp-test.c | 2 +- lib/kmp.h | 2 +- lib/mempool.c | 2 +- lib/mempool.h | 2 +- lib/redblack.h | 8 ++++---- lib/shell/config.c | 4 ++-- lib/sorter.h | 2 +- lib/wildmatch.c | 6 +++--- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/images/image-test.c b/images/image-test.c index 0a22d479..043da30a 100644 --- a/images/image-test.c +++ b/images/image-test.c @@ -64,7 +64,7 @@ test_image_iface(void) ASSERT(i1->pixel_size == 4); ASSERT(IMAGE_SSE_ALIGN_SIZE >= 16); ASSERT(!(i1->row_size & (IMAGE_SSE_ALIGN_SIZE - 1))); - ASSERT(!((addr_int_t)i1->pixels & (IMAGE_SSE_ALIGN_SIZE - 1))); + ASSERT(!((uintptr_t)i1->pixels & (IMAGE_SSE_ALIGN_SIZE - 1))); image_destroy(i1); i1 = image_new(&ctx, 283, 329, COLOR_SPACE_RGB, NULL); diff --git a/lib/bigalloc.c b/lib/bigalloc.c index e2be03a2..ad6aeff0 100644 --- a/lib/bigalloc.c +++ b/lib/bigalloc.c @@ -39,7 +39,7 @@ void big_free(void *start, unsigned int len) { byte *p = start; - ASSERT(!((addr_int_t) p & (CPU_PAGE_SIZE-1))); + ASSERT(!((uintptr_t) p & (CPU_PAGE_SIZE-1))); len = big_round(len); #ifdef CONFIG_DEBUG p -= CPU_PAGE_SIZE; diff --git a/lib/conf-dump.c b/lib/conf-dump.c index 073bf129..c4ac16bb 100644 --- a/lib/conf-dump.c +++ b/lib/conf-dump.c @@ -53,7 +53,7 @@ static byte *class_names[] = { "end", "static", "dynamic", "parser", "section", static void dump_item(struct fastbuf *fb, struct cf_item *item, int level, void *ptr) { - ptr += (addr_int_t) item->ptr; + ptr += (uintptr_t) item->ptr; enum cf_type type = item->type; uns size = cf_type_size(item->type, item->u.utype); int i; diff --git a/lib/conf-intr.c b/lib/conf-intr.c index b90640f1..9777e571 100644 --- a/lib/conf-intr.c +++ b/lib/conf-intr.c @@ -151,7 +151,7 @@ interpret_section(struct cf_section *sec, int number, byte **pars, int *processe for (struct cf_item *ci=sec->cfg; ci->cls; ci++) { int taken; - byte *msg = interpret_set_item(ci, number, pars, &taken, ptr + (addr_int_t) ci->ptr, allow_dynamic && !ci[1].cls); + byte *msg = interpret_set_item(ci, number, pars, &taken, ptr + (uintptr_t) ci->ptr, allow_dynamic && !ci[1].cls); if (msg) return cf_printf("Item %s: %s", ci->name, msg); *processed += taken; @@ -333,8 +333,8 @@ static int cmp_items(void *i1, void *i2, struct cf_item *item) { ASSERT(item->cls == CC_STATIC); - i1 += (addr_int_t) item->ptr; - i2 += (addr_int_t) item->ptr; + i1 += (uintptr_t) item->ptr; + i2 += (uintptr_t) item->ptr; if (item->type == CT_STRING) return strcmp(* (byte**) i1, * (byte**) i2); else // all numeric types @@ -504,7 +504,7 @@ find_item(struct cf_section *curr_sec, byte *name, byte **msg, void **ptr) *msg = cf_printf("Unknown item %s", name); return NULL; } - *ptr += (addr_int_t) ci->ptr; + *ptr += (uintptr_t) ci->ptr; if (!c) return ci; if (ci->cls != CC_SECTION) diff --git a/lib/conf-section.c b/lib/conf-section.c index b06b9fd6..bbd34164 100644 --- a/lib/conf-section.c +++ b/lib/conf-section.c @@ -140,11 +140,11 @@ cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero) } for (struct cf_item *ci=sec->cfg; ci->cls; ci++) if (ci->cls == CC_SECTION) - cf_init_section(ci->name, ci->u.sec, ptr + (addr_int_t) ci->ptr, 0); + cf_init_section(ci->name, ci->u.sec, ptr + (uintptr_t) ci->ptr, 0); else if (ci->cls == CC_LIST) - clist_init(ptr + (addr_int_t) ci->ptr); + clist_init(ptr + (uintptr_t) ci->ptr); else if (ci->cls == CC_DYNAMIC) { - void **dyn = ptr + (addr_int_t) ci->ptr; + void **dyn = ptr + (uintptr_t) ci->ptr; if (!*dyn) { // replace NULL by an empty array static uns zero = 0; *dyn = (&zero) + 1; @@ -163,13 +163,13 @@ commit_section(struct cf_section *sec, void *ptr, uns commit_all) byte *err; for (struct cf_item *ci=sec->cfg; ci->cls; ci++) if (ci->cls == CC_SECTION) { - if ((err = commit_section(ci->u.sec, ptr + (addr_int_t) ci->ptr, commit_all))) { + if ((err = commit_section(ci->u.sec, ptr + (uintptr_t) ci->ptr, commit_all))) { log(L_ERROR, "Cannot commit section %s: %s", ci->name, err); return "commit of a subsection failed"; } } else if (ci->cls == CC_LIST) { uns idx = 0; - CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (addr_int_t) ci->ptr)) + CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (uintptr_t) ci->ptr)) if (idx++, err = commit_section(ci->u.sec, n, commit_all)) { log(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err); return "commit of a list failed"; diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 28328107..598a21d9 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -402,7 +402,7 @@ static inline int bskip(struct fastbuf *f, uns len) return bskip_slow(f, len); } -/* I/O on addr_int_t */ +/* I/O on uintptr_t */ #ifdef CPU_64BIT_POINTERS #define bputa(x,p) bputq(x,p) diff --git a/lib/hashfunc.h b/lib/hashfunc.h index fc836b38..5f40c3d6 100644 --- a/lib/hashfunc.h +++ b/lib/hashfunc.h @@ -38,6 +38,6 @@ uns hash_string_nocase(const byte *str) PURE; */ static inline uns CONST hash_u32(uns x) { return 0x01008041*x; } static inline uns CONST hash_u64(u64 x) { return hash_u32((uns)x ^ (uns)(x >> 32)); } -static inline uns CONST hash_pointer(void *x) { return ((sizeof(x) <= 4) ? hash_u32((uns)(addr_int_t)x) : hash_u64((u64)(addr_int_t)x)); } +static inline uns CONST hash_pointer(void *x) { return ((sizeof(x) <= 4) ? hash_u32((uns)(uintptr_t)x) : hash_u64((u64)(uintptr_t)x)); } #endif diff --git a/lib/kmp-test.c b/lib/kmp-test.c index e245fcff..fcbc96ef 100644 --- a/lib/kmp-test.c +++ b/lib/kmp-test.c @@ -167,7 +167,7 @@ kmp4_eq(struct kmp4_struct *kmp UNUSED, byte *a, byte *b) static inline uns kmp4_hash(struct kmp4_struct *kmp UNUSED, struct kmp4_state *s, byte *c) { - return (c ? (*c << 16) : 0) + (uns)(addr_int_t)s; + return (c ? (*c << 16) : 0) + (uns)(uintptr_t)s; } #define KMP_PREFIX(x) kmp4_##x diff --git a/lib/kmp.h b/lib/kmp.h index 67889a17..aa889f69 100644 --- a/lib/kmp.h +++ b/lib/kmp.h @@ -168,7 +168,7 @@ P(hash_hash) (struct P(hash_table) *t, struct P(state) *f, P(char_t) c) static inline uns P(hash_hash) (struct P(hash_table) *t UNUSED, struct P(state) *f, P(char_t) c) { - return (((uns)c) << 16) + (uns)(addr_int_t)f; + return (((uns)c) << 16) + (uns)(uintptr_t)f; } #endif diff --git a/lib/mempool.c b/lib/mempool.c index af65b285..fffbbd29 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -68,7 +68,7 @@ mp_alloc(struct mempool *p, uns s) { if (s <= p->threshold) { - byte *x = (byte *)(((addr_int_t) p->free + POOL_ALIGN - 1) & ~(addr_int_t)(POOL_ALIGN - 1)); + byte *x = (byte *)(((uintptr_t) p->free + POOL_ALIGN - 1) & ~(uintptr_t)(POOL_ALIGN - 1)); if (x + s > p->last) { struct memchunk *c; diff --git a/lib/mempool.h b/lib/mempool.h index efb5fa1b..d16fa6e0 100644 --- a/lib/mempool.h +++ b/lib/mempool.h @@ -30,7 +30,7 @@ void *mp_alloc_zero(struct mempool *, uns) LIKE_MALLOC; static inline void * LIKE_MALLOC mp_alloc_fast(struct mempool *p, uns l) { - byte *f = (void *) (((addr_int_t) p->free + POOL_ALIGN - 1) & ~(addr_int_t)(POOL_ALIGN - 1)); + byte *f = (void *) (((uintptr_t) p->free + POOL_ALIGN - 1) & ~(uintptr_t)(POOL_ALIGN - 1)); byte *ee = f + l; if (ee > p->last) return mp_alloc(p, l); diff --git a/lib/redblack.h b/lib/redblack.h index 1776bedb..e2782048 100644 --- a/lib/redblack.h +++ b/lib/redblack.h @@ -263,13 +263,13 @@ typedef struct P(stack_entry) { #else /* Pointers are aligned, hence we can use lower bits. */ static inline uns P(red_flag) (P(bucket) *node) - { return ((addr_int_t) node->son[0]) & 1L; } + { return ((uintptr_t) node->son[0]) & 1L; } static inline void P(set_red_flag) (P(bucket) *node, uns flag) - { node->son[0] = (void*) ( (((addr_int_t) node->son[0]) & ~1L) | (flag & 1L) ); } + { node->son[0] = (void*) ( (((uintptr_t) node->son[0]) & ~1L) | (flag & 1L) ); } static inline P(bucket) * P(tree_son) (P(bucket) *node, uns id) - { return (void *) (((addr_int_t) node->son[id]) & ~1L); } + { return (void *) (((uintptr_t) node->son[id]) & ~1L); } static inline void P(set_tree_son) (P(bucket) *node, uns id, P(bucket) *son) - { node->son[id] = (void *) ((addr_int_t) son | (((addr_int_t) node->son[id]) & 1L) ); } + { node->son[id] = (void *) ((uintptr_t) son | (((uintptr_t) node->son[id]) & 1L) ); } #endif /* Defaults for missing parameters. */ diff --git a/lib/shell/config.c b/lib/shell/config.c index df53a408..02d89dd8 100644 --- a/lib/shell/config.c +++ b/lib/shell/config.c @@ -274,7 +274,7 @@ parse_section(struct section *section) } if (section->item.cf.cls == CC_LIST) { - item->cf.ptr = (void *)(addr_int_t)section->size; + item->cf.ptr = (void *)(uintptr_t)section->size; section->size += sizeof(union value); } else @@ -375,7 +375,7 @@ dump_item(struct item *item, void *ptr, uns path_len) { if (item->flags & FLAG_HIDE) return; - byte *val = (byte *)((addr_int_t)ptr + (addr_int_t)item->cf.ptr); + byte *val = (byte *)((uintptr_t)ptr + (uintptr_t)item->cf.ptr); if (item->cf.cls == CC_LIST) { uns len = strlen(item->cf.name); diff --git a/lib/sorter.h b/lib/sorter.h index ed82eb34..71fcff1e 100644 --- a/lib/sorter.h +++ b/lib/sorter.h @@ -401,7 +401,7 @@ P(presort)(struct fastbuf **fb1, struct fastbuf **fb2) } for(;;) { - current = (byte *) ALIGN_TO((addr_int_t) current, CPU_STRUCT_ALIGN); + current = (byte *) ALIGN_TO((uintptr_t) current, CPU_STRUCT_ALIGN); if (current + sizeof(*this) > bufend) break; this = (SORT_NODE *) current; diff --git a/lib/wildmatch.c b/lib/wildmatch.c index a5eb76ed..fed2ddb9 100644 --- a/lib/wildmatch.c +++ b/lib/wildmatch.c @@ -29,7 +29,7 @@ struct nfa_state { }; struct dfa_state { - addr_int_t edge[256]; /* Outgoing DFA edges. Bit 0 is set for incomplete edges which + uintptr_t edge[256]; /* Outgoing DFA edges. Bit 0 is set for incomplete edges which * contain just state set and clear for complete ones which point * to other states. NULL means `no match'. */ @@ -157,12 +157,12 @@ wp_match(struct wildpatt *w, byte *s) d = w->dfa_start; while (*s) { - addr_int_t next = d->edge[*s]; + uintptr_t next = d->edge[*s]; if (next & 1) { /* Need to lookup/create the destination state */ struct dfa_state *new = wp_new_state(w, next & ~1); - d->edge[*s] = (addr_int_t) new; + d->edge[*s] = (uintptr_t) new; d = new; } else if (!next) -- 2.39.5