# HG changeset patch # User Mike Becker # Date 1734273678 -3600 # Node ID c773da859bad024b3ae92051ae4faca15c82ed28 # Parent b0098854071f81826ab3c12ea803b2a2f9967123 fix compilation for compilers which don't set __WORDSIZE diff -r b0098854071f -r c773da859bad src/array_list.c --- a/src/array_list.c Sun Dec 15 15:23:29 2024 +0100 +++ b/src/array_list.c Sun Dec 15 15:41:18 2024 +0100 @@ -108,7 +108,7 @@ size_t oldcap; size_t oldsize; size_t max_size; - if (width == 0 || width == __WORDSIZE) { + if (width == 0 || width == CX_WORDSIZE) { oldcap = *(size_t*) capacity; oldsize = *(size_t*) size; max_size = SIZE_MAX; @@ -121,7 +121,7 @@ oldsize = *(uint8_t*) size; max_size = UINT8_MAX; } -#if __WORDSIZE == 64 +#if CX_WORDSIZE == 64 else if (width == 32) { oldcap = *(uint32_t*) capacity; oldsize = *(uint32_t*) size; @@ -162,14 +162,14 @@ *array = newmem; // store new capacity - if (width == 0 || width == __WORDSIZE) { + if (width == 0 || width == CX_WORDSIZE) { *(size_t*) capacity = newcap; } else if (width == 16) { *(uint16_t*) capacity = newcap; } else if (width == 8) { *(uint8_t*) capacity = newcap; } -#if __WORDSIZE == 64 +#if CX_WORDSIZE == 64 else if (width == 32) { *(uint32_t*) capacity = newcap; } @@ -201,7 +201,7 @@ size_t oldcap; size_t oldsize; size_t max_size; - if (width == 0 || width == __WORDSIZE) { + if (width == 0 || width == CX_WORDSIZE) { oldcap = *(size_t*) capacity; oldsize = *(size_t*) size; max_size = SIZE_MAX; @@ -214,7 +214,7 @@ oldsize = *(uint8_t*) size; max_size = UINT8_MAX; } -#if __WORDSIZE == 64 +#if CX_WORDSIZE == 64 else if (width == 32) { oldcap = *(uint32_t*) capacity; oldsize = *(uint32_t*) size; @@ -278,7 +278,7 @@ // if any of size or capacity changed, store them back if (newsize != oldsize || newcap != oldcap) { - if (width == 0 || width == __WORDSIZE) { + if (width == 0 || width == CX_WORDSIZE) { *(size_t*) capacity = newcap; *(size_t*) size = newsize; } else if (width == 16) { @@ -288,7 +288,7 @@ *(uint8_t*) capacity = newcap; *(uint8_t*) size = newsize; } -#if __WORDSIZE == 64 +#if CX_WORDSIZE == 64 else if (width == 32) { *(uint32_t*) capacity = newcap; *(uint32_t*) size = newsize; diff -r b0098854071f -r c773da859bad src/cx/common.h --- a/src/cx/common.h Sun Dec 15 15:23:29 2024 +0100 +++ b/src/cx/common.h Sun Dec 15 15:41:18 2024 +0100 @@ -99,6 +99,18 @@ #include // --------------------------------------------------------------------------- +// Architecture Detection +// --------------------------------------------------------------------------- + +#if INTPTR_MAX == INT64_MAX +#define CX_WORDSIZE 64 +#elif INTPTR_MAX == INT32_MAX +#define CX_WORDSIZE 32 +#else +#error Unknown pointer size or missing size macros! +#endif + +// --------------------------------------------------------------------------- // Attribute definitions // ---------------------------------------------------------------------------