From 23e72941ff560f75e398975daee28f3e7db9b37c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 9 May 2025 15:00:34 +0200 Subject: [PATCH] fix: fix building with PostgreSQL v18 libpq Use 64 bits support from C99 types. Fix #1082 --- docs/news.rst | 1 + psycopg_c/psycopg_c/types/numutils.c | 38 +++++++--------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index e253078ff..151e8114d 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -26,6 +26,7 @@ Psycopg 3.2.8 (unreleased) returns `None` (:ticket:`#1073`). - Fix `ConnectionInfo.port` when the port is specified as an empty string (:ticket:`#1078`). +- Add support for PostgreSQL 18 libpq (:ticket:`#1082`). Current release diff --git a/psycopg_c/psycopg_c/types/numutils.c b/psycopg_c/psycopg_c/types/numutils.c index 4be7108bb..2be6b3973 100644 --- a/psycopg_c/psycopg_c/types/numutils.c +++ b/psycopg_c/psycopg_c/types/numutils.c @@ -15,32 +15,10 @@ /* * 64-bit integers */ -#ifdef HAVE_LONG_INT_64 -/* Plain "long int" fits, use it */ - -# ifndef HAVE_INT64 -typedef long int int64; -# endif -# ifndef HAVE_UINT64 -typedef unsigned long int uint64; -# endif -# define INT64CONST(x) (x##L) -# define UINT64CONST(x) (x##UL) -#elif defined(HAVE_LONG_LONG_INT_64) -/* We have working support for "long long int", use that */ - -# ifndef HAVE_INT64 -typedef long long int int64; -# endif -# ifndef HAVE_UINT64 -typedef unsigned long long int uint64; -# endif -# define INT64CONST(x) (x##LL) -# define UINT64CONST(x) (x##ULL) -#else -/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */ -# error must have a working 64-bit integer datatype -#endif +typedef uint64_t uint64; +typedef int64_t int64; + +#define UINT64CONST(x) UINT64_C(x) #ifndef HAVE__BUILTIN_CLZ @@ -90,13 +68,15 @@ static inline int pg_leftmost_one_pos64(uint64_t word) { #ifdef HAVE__BUILTIN_CLZ -#if defined(HAVE_LONG_INT_64) + +#if SIZEOF_LONG == 8 return 63 - __builtin_clzl(word); -#elif defined(HAVE_LONG_LONG_INT_64) +#elif SIZEOF_LONG_LONG == 8 return 63 - __builtin_clzll(word); #else -#error must have a working 64-bit integer datatype +#error "cannot find integer type of the same size as uint64_t" #endif + #else /* !HAVE__BUILTIN_CLZ */ int shift = 64 - 8; -- 2.47.3