From 97cca6f921e5fcd8ea459b6ac3b76d3f7e19b3b6 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Thu, 6 Jan 2022 17:21:06 +1100 Subject: [PATCH] base: use uintptr_t for hash type Use uintptr_t for hash type; this is consistent with CoreFoundation, which uses 32-bit integers on 32-bit platforms for the hash code, and 64-bit integers on 64-bit platforms. (libheimbase is modelled on CoreFoundation.) Previously we used unsigned long, which would have the same behavior on LP32/LP64 systems, but not on Windows (where unsigned long is 32-bits on 64-bit platforms). --- lib/base/data.c | 2 +- lib/base/dict.c | 4 ++-- lib/base/error.c | 2 +- lib/base/heimbase.c | 8 ++++---- lib/base/heimbase.h | 2 +- lib/base/heimbasepriv.h | 2 +- lib/base/number.c | 4 ++-- lib/base/string.c | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/base/data.c b/lib/base/data.c index 4aa6efc66..f1b117b03 100644 --- a/lib/base/data.c +++ b/lib/base/data.c @@ -61,7 +61,7 @@ data_cmp(void *a, void *b) return memcmp(osa->data, osb->data, osa->length); } -static unsigned long +static uintptr_t data_hash(void *ptr) { heim_octet_string *os = ptr; diff --git a/lib/base/dict.c b/lib/base/dict.c index 8d73846b2..5c8396cc9 100644 --- a/lib/base/dict.c +++ b/lib/base/dict.c @@ -149,7 +149,7 @@ heim_dict_get_type_id(void) static struct hashentry * _search(heim_dict_t dict, heim_object_t ptr) { - unsigned long v = heim_get_hash(ptr); + uintptr_t v = heim_get_hash(ptr); struct hashentry *p; for (p = dict->tab[v % dict->size]; p != NULL; p = p->next) @@ -219,7 +219,7 @@ heim_dict_set_value(heim_dict_t dict, heim_object_t key, heim_object_t value) heim_release(h->value); h->value = heim_retain(value); } else { - unsigned long v; + uintptr_t v; h = malloc(sizeof(*h)); if (h == NULL) diff --git a/lib/base/error.c b/lib/base/error.c index 8ae65de49..9b4136b68 100644 --- a/lib/base/error.c +++ b/lib/base/error.c @@ -58,7 +58,7 @@ error_cmp(void *a, void *b) return heim_cmp(ap->msg, bp->msg); } -static unsigned long +static uintptr_t error_hash(void *ptr) { struct heim_error *p = ptr; diff --git a/lib/base/heimbase.c b/lib/base/heimbase.c index 351c208c7..3666b5d58 100644 --- a/lib/base/heimbase.c +++ b/lib/base/heimbase.c @@ -210,13 +210,13 @@ heim_get_tid(heim_object_t ptr) * @return a hash value */ -unsigned long +uintptr_t heim_get_hash(heim_object_t ptr) { heim_type_t isa = _heim_get_isa(ptr); if (isa->hash) return isa->hash(ptr); - return (unsigned long)ptr; + return (uintptr_t)ptr; } /** @@ -609,10 +609,10 @@ autorel_cmp(void *a, void *b) return (a == b); } -static unsigned long +static uintptr_t autorel_hash(void *ptr) { - return (unsigned long)ptr; + return (uintptr_t)ptr; } diff --git a/lib/base/heimbase.h b/lib/base/heimbase.h index 3a36d3eca..1c8b10315 100644 --- a/lib/base/heimbase.h +++ b/lib/base/heimbase.h @@ -184,7 +184,7 @@ heim_get_tid(heim_object_t object); int heim_cmp(heim_object_t a, heim_object_t b); -unsigned long +uintptr_t heim_get_hash(heim_object_t ptr); void diff --git a/lib/base/heimbasepriv.h b/lib/base/heimbasepriv.h index 8f8fad0fc..8c2b722cd 100644 --- a/lib/base/heimbasepriv.h +++ b/lib/base/heimbasepriv.h @@ -42,7 +42,7 @@ typedef void (*heim_type_init)(void *); typedef heim_object_t (*heim_type_copy)(void *); typedef int (*heim_type_cmp)(void *, void *); -typedef unsigned long (*heim_type_hash)(void *); +typedef uintptr_t (*heim_type_hash)(void *); typedef heim_string_t (*heim_type_description)(void *); typedef struct heim_type_data *heim_type_t; diff --git a/lib/base/number.c b/lib/base/number.c index f763c5085..5666d25ee 100644 --- a/lib/base/number.c +++ b/lib/base/number.c @@ -58,12 +58,12 @@ number_cmp(void *a, void *b) return na - nb; } -static unsigned long +static uintptr_t number_hash(void *ptr) { if (heim_base_is_tagged_object(ptr)) return heim_base_tagged_object_value(ptr); - return (unsigned long)*(int *)ptr; + return (uintptr_t)*(int64_t *)ptr; } struct heim_type_data _heim_number_object = { diff --git a/lib/base/string.c b/lib/base/string.c index 538499808..21cc91b0f 100644 --- a/lib/base/string.c +++ b/lib/base/string.c @@ -73,11 +73,11 @@ string_cmp(void *a, void *b) return strcmp(a, b); } -static unsigned long +static uintptr_t string_hash(void *ptr) { const char *s = ptr; - unsigned long n; + uintptr_t n; for (n = 0; *s; ++s) n += *s; -- 2.11.4.GIT