From: Karl Fleischmann Date: Fri, 24 Jun 2022 06:07:09 +0000 (+0200) Subject: lib: Use size of size_t instead of data-model for bit-widths X-Git-Tag: 2.4.0~3813 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccf94de6e3b5caea711d71ed47026e4626d738a6;p=thirdparty%2Fdovecot%2Fcore.git lib: Use size of size_t instead of data-model for bit-widths This commit drops the generic and confusing data-model check (that is a platform-specific value of bit-widths for various data types) in favor of checking the actually used size (i.e. size_t). --- diff --git a/configure.ac b/configure.ac index 9e561af10b..0f0f69d234 100644 --- a/configure.ac +++ b/configure.ac @@ -335,6 +335,7 @@ AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(void *) AC_CHECK_SIZEOF(long long) +AC_CHECK_SIZEOF(size_t) AC_SYS_LARGEFILE diff --git a/src/lib/bits.c b/src/lib/bits.c index 6366cf24cb..a76a815996 100644 --- a/src/lib/bits.c +++ b/src/lib/bits.c @@ -6,7 +6,7 @@ * We could use bits_required64() unconditionally, but that's unnecessary * and way more heavy weight on 32-bit systems. */ -#ifdef _LP64 +#if SIZEOF_SIZE_T > 4 #define BITS_REQUIRED(x) bits_required64(x) #else #define BITS_REQUIRED(x) bits_required32(x) diff --git a/src/lib/compat.h b/src/lib/compat.h index 7ab1340af3..869732d08e 100644 --- a/src/lib/compat.h +++ b/src/lib/compat.h @@ -1,34 +1,6 @@ #ifndef COMPAT_H #define COMPAT_H -/* - * - * - * - * This block decides whether 32 or 64 bit pointers are used. - * Shallow research indicates, that ILP32 is used for x32 and arm64ilp32 modes - * but is it still necessary? - * https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models - * - * - * - */ -/* _ILP32 and _LP64 are common but not universal, make sure that exactly one - of them is defined. */ -#if !defined(_ILP32) && \ - (SIZEOF_INT == 4) && (SIZEOF_LONG == 4) && (SIZEOF_VOID_P == 4) -# define _ILP32 -#endif -#if !defined(_LP64) && \ - (SIZEOF_INT == 4) && (SIZEOF_LONG == 8) && (SIZEOF_VOID_P == 8) -# define _LP64 -#endif -#if defined(_ILP32) && defined(_LP64) -# error "Cannot have both _ILP32 and _LP64 defined" -#elif !defined(_ILP32) && !defined(_LP64) -# error "Must have one of _ILP32 and _LP64 defined" -#endif - #if defined(HAVE_TYPEOF) && !defined(__cplusplus) # define HAVE_TYPE_CHECKS #endif diff --git a/src/lib/test-mempool-allocfree.c b/src/lib/test-mempool-allocfree.c index 6fd69dc001..82d4304d18 100644 --- a/src/lib/test-mempool-allocfree.c +++ b/src/lib/test-mempool-allocfree.c @@ -114,7 +114,7 @@ enum fatal_test_state fatal_mempool_allocfree(unsigned int stage) (void)p_malloc(pool, POOL_MAX_ALLOC_SIZE + 1ULL); return FATAL_TEST_FAILURE; -#ifdef _LP64 /* malloc(POOL_MAX_ALLOC_SIZE) may succeed with 32bit */ +#if SIZEOF_SIZE_T > 4 /* malloc(POOL_MAX_ALLOC_SIZE) may succeed with 32bit */ case 2: /* physically impossible size */ test_expect_fatal_string("Out of memory"); (void)p_malloc(pool, POOL_MAX_ALLOC_SIZE); diff --git a/src/lib/test-mempool-alloconly.c b/src/lib/test-mempool-alloconly.c index c3b0001b79..e014be75f0 100644 --- a/src/lib/test-mempool-alloconly.c +++ b/src/lib/test-mempool-alloconly.c @@ -73,7 +73,7 @@ enum fatal_test_state fatal_mempool_alloconly(unsigned int stage) (void)p_malloc(pool, POOL_MAX_ALLOC_SIZE + 1ULL); return FATAL_TEST_FAILURE; -#ifdef _LP64 /* malloc(POOL_MAX_ALLOC_SIZE) may succeed with 32bit */ +#if SIZEOF_SIZE_T > 4 /* malloc(POOL_MAX_ALLOC_SIZE) may succeed with 32bit */ case 2: /* physically impossible size */ test_expect_fatal_string("Out of memory"); (void)p_malloc(pool, POOL_MAX_ALLOC_SIZE); diff --git a/src/lib/test-mempool.c b/src/lib/test-mempool.c index 7c707dd33a..35ea2d9668 100644 --- a/src/lib/test-mempool.c +++ b/src/lib/test-mempool.c @@ -10,7 +10,7 @@ typedef char uint32max_array_t[65535]; #define BIG_MAX POOL_MAX_ALLOC_SIZE -#if defined(_LP64) +#if SIZEOF_SIZE_T > 4 #define LITTLE_MAX ((unsigned long long) INT32_MAX) #else #define LITTLE_MAX ((unsigned long long) INT16_MAX)