944 {
static_assert(condition,
errmessage); }
while(0)
945#ifdef HAVE_STATEMENT_EXPRESSIONS
946#define StaticAssertExpr(condition, errmessage) \
947 ((void) ({ static_assert(condition, errmessage); true; }))
948#else
949#define StaticAssertExpr(condition, errmessage) \
950 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
951#endif
952
953
954
955
956
957
958
959
960
961
962
963
964
965#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
966#define StaticAssertVariableIsOfType(varname, typename) \
967 StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
968 CppAsString(varname) " does not have type " CppAsString(typename))
969#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
970 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
971 CppAsString(varname) " does not have type " CppAsString(typename)))
972#else
973#define StaticAssertVariableIsOfType(varname, typename) \
974 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
975 CppAsString(varname) " does not have type " CppAsString(typename))
976#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
977 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
978 CppAsString(varname) " does not have type " CppAsString(typename)))
979#endif
980
981
982
983
984
985
986
987
988
989
990#define Max(x, y) ((x) > (y) ? (x) : (y))
991
992
993
994
995
996#define Min(x, y) ((x) < (y) ? (x) : (y))
997
998
999
1000#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012#define MemSet(start, val, len) \
1013 do \
1014 { \
1015 \
1016 void *_vstart = (void *) (start); \
1017 int _val = (val); \
1018 Size _len = (len); \
1019\
1020 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1021 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1022 _val == 0 && \
1023 _len <= MEMSET_LOOP_LIMIT && \
1024
1025
1026
1027 \
1028 MEMSET_LOOP_LIMIT != 0) \
1029 { \
1030 size_t *_start = (size_t *) _vstart; \
1031 size_t *_stop = (size_t *) ((char *) _start + _len); \
1032 while (_start < _stop) \
1033 *_start++ = 0; \
1034 } \
1035 else \
1036 memset(_vstart, _val, _len); \
1037 } while (0)
1038
1039
1040
1041
1042
1043
1044
1045#define MemSetAligned(start, val, len) \
1046 do \
1047 { \
1048 size_t *_start = (size_t *) (start); \
1049 int _val = (val); \
1050 Size _len = (len); \
1051\
1052 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1053 _val == 0 && \
1054 _len <= MEMSET_LOOP_LIMIT && \
1055 MEMSET_LOOP_LIMIT != 0) \
1056 { \
1057 size_t *_stop = (size_t *) ((char *) _start + _len); \
1058 while (_start < _stop) \
1059 *_start++ = 0; \
1060 } \
1061 else \
1062 memset(_start, _val, _len); \
1063 } while (0)
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077#define FLOAT4_FITS_IN_INT16(num) \
1078 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1079#define FLOAT4_FITS_IN_INT32(num) \
1080 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1081#define FLOAT4_FITS_IN_INT64(num) \
1082 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1083#define FLOAT8_FITS_IN_INT16(num) \
1084 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1085#define FLOAT8_FITS_IN_INT32(num) \
1086 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1087#define FLOAT8_FITS_IN_INT64(num) \
1088 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101#define INVERT_COMPARE_RESULT(var) \
1102 ((var) = ((var) < 0) ? 1 : -(var))
1103
1104
1105
1106
1107
1108
1109
1111{
1114
1115
1116
1117
1118
1119
1120
1121#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1122
1123
1124
1125
1126
1127
1128
1129
1130
1132{
1135
1136
1138{
1141
1142#else
1143
1144
1147
1148#endif
1149
1150
1151#define HIGHBIT (0x80)
1152#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1153
1154
1155
1156
1157
1158
1159
1160#define SQL_STR_DOUBLE(ch, escape_backslash) \
1161 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1162
1163#define ESCAPE_STRING_SYNTAX 'E'
1164
1165
1166#define STATUS_OK (0)
1167#define STATUS_ERROR (-1)
1168#define STATUS_EOF (-2)
1169
1170
1171
1172
1173
1174#ifndef ENABLE_NLS
1175
1176#define gettext(x) (x)
1177#define dgettext(d,x) (x)
1178#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1179#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1180#endif
1181
1182#define _(x) gettext(x)
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193#define gettext_noop(x) (x)
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208#ifdef SO_MAJOR_VERSION
1209#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1210#else
1211#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1212#endif
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229#if defined(__cplusplus)
1230#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1231#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1232#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1233#define unconstify(underlying_type, expr) \
1234 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1235 "wrong cast"), \
1236 (underlying_type) (expr))
1237#define unvolatize(underlying_type, expr) \
1238 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1239 "wrong cast"), \
1240 (underlying_type) (expr))
1241#else
1242#define unconstify(underlying_type, expr) \
1243 ((underlying_type) (expr))
1244#define unvolatize(underlying_type, expr) \
1245 ((underlying_type) (expr))
1246#endif
1247
1248
1249
1250
1251
1252#if (defined(__x86_64__) || defined(_M_AMD64))
1253#define USE_SSE2
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263#elif defined(__aarch64__) && defined(__ARM_NEON)
1264#define USE_NEON
1265#endif
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283#if defined(WIN32) || defined(__CYGWIN__)
1284#define PG_BINARY O_BINARY
1285#define PG_BINARY_A "ab"
1286#define PG_BINARY_R "rb"
1287#define PG_BINARY_W "wb"
1288#else
1289#define PG_BINARY 0
1290#define PG_BINARY_A "a"
1291#define PG_BINARY_R "r"
1292#define PG_BINARY_W "w"
1293#endif
1294
1295
1296
1297
1298
1299
1300#if !HAVE_DECL_FDATASYNC
1302#endif
1303
1304
1305
1306
1307
1308
1309#if SIZEOF_LONG == 8
1310#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1311#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1312#elif SIZEOF_LONG_LONG == 8
1313#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1314#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1315#else
1316#error "cannot find integer type of the same size as int64_t"
1317#endif
1318
1319
1320
1321
1322#if SIZEOF_LONG == 8
1323#define i64abs(i) ((int64) labs(i))
1324#elif SIZEOF_LONG_LONG == 8
1325#define i64abs(i) ((int64) llabs(i))
1326#else
1327#error "cannot find integer type of the same size as int64_t"
1328#endif
1329
1330
1331
1332
1333
1334
1335#ifndef PGDLLIMPORT
1336#define PGDLLIMPORT
1337#endif
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347#ifndef PGDLLEXPORT
1348#ifdef HAVE_VISIBILITY_ATTRIBUTE
1349#define PGDLLEXPORT __attribute__((visibility("default")))
1350#else
1351#define PGDLLEXPORT
1352#endif
1353#endif
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364#ifndef SIGNAL_ARGS
1365#define SIGNAL_ARGS int postgres_signal_arg
1366#endif
1367
1368
1369
1370
1371
1372
1373
1374#ifdef WIN32
1375#ifdef __MINGW64__
1377#define sigsetjmp(x,y) __builtin_setjmp(x)
1378#define siglongjmp __builtin_longjmp
1379#else
1380#define sigjmp_buf jmp_buf
1381#define sigsetjmp(x,y) setjmp(x)
1382#define siglongjmp longjmp
1383#endif
1384#endif
1385
1386
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403#ifdef HAVE_UCHAR_H
1404#include <uchar.h>
1405#else
1406#ifndef __cplusplus
1409#endif
1410#endif
1411
1412
1413
1414#endif
static int fd(const char *x, int i)