diff options
author | Thomas Munro <tmunro@postgresql.org> | 2024-12-04 14:46:59 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2024-12-04 15:05:38 +1300 |
commit | 962da900ac8f0927f1af2fd811ca67fa163c873a (patch) | |
tree | 5839c22d2ad7bc68ddfd1e4debc734ef5df3a9d1 /src/interfaces/ecpg | |
parent | 3b08d5224d7df71cc111d8522cf6190fc02f6fb9 (diff) | |
download | postgresql-962da900ac8f0927f1af2fd811ca67fa163c873a.tar.gz postgresql-962da900ac8f0927f1af2fd811ca67fa163c873a.zip |
Use <stdint.h> and <inttypes.h> for c.h integers.
Redefine our exact width types with standard C99 types and macros,
including int64_t, INT64_MAX, INT64_C(), PRId64 etc. We were already
using <stdint.h> types in a few places.
One complication is that Windows' <inttypes.h> uses format strings like
"%I64d", "%I32", "%I" for PRI*64, PRI*32, PTR*PTR, instead of mapping to
other standardized format strings like "%lld" etc as seen on other known
systems. Teach our snprintf.c to understand them.
This removes a lot of configure clutter, and should also allow 64-bit
numbers and other standard types to be used in localized messages
without casting.
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/ME3P282MB3166F9D1F71F787929C0C7E7B6312%40ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM
Diffstat (limited to 'src/interfaces/ecpg')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/typename.c | 9 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/ecpg_config.h.in | 8 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/meson.build | 4 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/pgtypes_interval.h | 12 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/sqltypes.h | 8 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/expected/compat_informix-sqlda.c | 8 |
6 files changed, 25 insertions, 24 deletions
diff --git a/src/interfaces/ecpg/ecpglib/typename.c b/src/interfaces/ecpg/ecpglib/typename.c index 1d482c4fa61..1fb9860371b 100644 --- a/src/interfaces/ecpg/ecpglib/typename.c +++ b/src/interfaces/ecpg/ecpglib/typename.c @@ -131,11 +131,12 @@ sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat) case INTERVALOID: return ECPGt_interval; case INT8OID: -#ifdef HAVE_LONG_LONG_INT_64 - return ECPGt_long_long; -#endif -#ifdef HAVE_LONG_INT_64 +#if SIZEOF_LONG == 8 return ECPGt_long; +#elif SIZEOF_LONG_LONG == 8 + return ECPGt_long_long; +#else +#error "cannot find integer type of the same size as INT8OID" #endif /* Unhandled types always return a string */ default: diff --git a/src/interfaces/ecpg/include/ecpg_config.h.in b/src/interfaces/ecpg/include/ecpg_config.h.in index 75f542f263b..4af45930b61 100644 --- a/src/interfaces/ecpg/include/ecpg_config.h.in +++ b/src/interfaces/ecpg/include/ecpg_config.h.in @@ -1,8 +1,8 @@ /* Define to 1 to build client libraries as thread-safe code. */ #define ENABLE_THREAD_SAFETY 1 -/* Define to 1 if `long int' works and is 64 bits. */ -#undef HAVE_LONG_INT_64 +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG -/* Define to 1 if `long long int' works and is 64 bits. */ -#undef HAVE_LONG_LONG_INT_64 +/* The size of `long long', as computed by sizeof. */ +#undef SIZEOF_LONG_LONG diff --git a/src/interfaces/ecpg/include/meson.build b/src/interfaces/ecpg/include/meson.build index a3beb3cc7be..c1a88e73fb8 100644 --- a/src/interfaces/ecpg/include/meson.build +++ b/src/interfaces/ecpg/include/meson.build @@ -3,8 +3,8 @@ ecpg_inc = include_directories('.') ecpg_conf_keys = [ - 'HAVE_LONG_INT_64', - 'HAVE_LONG_LONG_INT_64', + 'SIZEOF_LONG', + 'SIZEOF_LONG_LONG', ] ecpg_conf_data = configuration_data() diff --git a/src/interfaces/ecpg/include/pgtypes_interval.h b/src/interfaces/ecpg/include/pgtypes_interval.h index 46cfce65517..f0acbb4512a 100644 --- a/src/interfaces/ecpg/include/pgtypes_interval.h +++ b/src/interfaces/ecpg/include/pgtypes_interval.h @@ -3,21 +3,17 @@ #ifndef PGTYPES_INTERVAL #define PGTYPES_INTERVAL +#include <stdint.h> + #include <ecpg_config.h> #include <pgtypes.h> #ifndef C_H -#ifdef HAVE_LONG_INT_64 -typedef long int int64; -#elif defined(HAVE_LONG_LONG_INT_64) -typedef long long int int64; -#else -/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */ -#error must have a working 64-bit integer datatype -#endif +typedef int64_t int64; #define HAVE_INT64_TIMESTAMP + #endif /* C_H */ typedef struct diff --git a/src/interfaces/ecpg/include/sqltypes.h b/src/interfaces/ecpg/include/sqltypes.h index e7cbfa47956..498840458c4 100644 --- a/src/interfaces/ecpg/include/sqltypes.h +++ b/src/interfaces/ecpg/include/sqltypes.h @@ -46,12 +46,14 @@ #define SQLINTERVAL ECPGt_interval #define SQLNCHAR ECPGt_char #define SQLNVCHAR ECPGt_char -#ifdef HAVE_LONG_LONG_INT_64 +#if SIZEOF_LONG == 8 +#define SQLINT8 ECPGt_long +#define SQLSERIAL8 ECPGt_long +#elif SIZEOF_LONG_LONG == 8 #define SQLINT8 ECPGt_long_long #define SQLSERIAL8 ECPGt_long_long #else -#define SQLINT8 ECPGt_long -#define SQLSERIAL8 ECPGt_long +#error "cannot find integer type of the same size as SQLINT8" #endif #endif /* ndef ECPG_SQLTYPES_H */ diff --git a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c index 7e19319d27f..8eebc51664e 100644 --- a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c +++ b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c @@ -97,12 +97,14 @@ typedef struct sqlda_struct sqlda_t; #define SQLINTERVAL ECPGt_interval #define SQLNCHAR ECPGt_char #define SQLNVCHAR ECPGt_char -#ifdef HAVE_LONG_LONG_INT_64 +#if SIZEOF_LONG == 8 +#define SQLINT8 ECPGt_long +#define SQLSERIAL8 ECPGt_long +#elif SIZEOF_LONG_LONG == 8 #define SQLINT8 ECPGt_long_long #define SQLSERIAL8 ECPGt_long_long #else -#define SQLINT8 ECPGt_long -#define SQLSERIAL8 ECPGt_long +#error "cannot find integer type of the same size as SQLINT8" #endif #endif /* ndef ECPG_SQLTYPES_H */ |