1015 {
static_assert(condition,
errmessage); }
while(0)
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030#ifndef __cplusplus
1031#if !defined(_MSC_VER) || _MSC_VER >= 1933
1032#define StaticAssertExpr(condition, errmessage) \
1033 ((void) sizeof(struct {static_assert(condition, errmessage); char a;}))
1034#else
1035
1036
1037
1038
1039#define StaticAssertExpr(condition, errmessage) \
1040 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
1041#endif
1042#else
1043#define StaticAssertExpr(condition, errmessage) \
1044 ([]{static_assert(condition, errmessage);})
1045#endif
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
1060#define StaticAssertVariableIsOfType(varname, typename) \
1061 StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \
1062 CppAsString(varname) " does not have type " CppAsString(typename))
1063#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1064 (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \
1065 CppAsString(varname) " does not have type " CppAsString(typename)))
1066#else
1067#define StaticAssertVariableIsOfType(varname, typename) \
1068 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
1069 CppAsString(varname) " does not have type " CppAsString(typename))
1070#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1071 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
1072 CppAsString(varname) " does not have type " CppAsString(typename)))
1073#endif
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084#define Max(x, y) ((x) > (y) ? (x) : (y))
1085
1086
1087
1088
1089
1090#define Min(x, y) ((x) < (y) ? (x) : (y))
1091
1092
1093
1094#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106#define MemSet(start, val, len) \
1107 do \
1108 { \
1109 \
1110 void *_vstart = (void *) (start); \
1111 int _val = (val); \
1112 Size _len = (len); \
1113\
1114 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1115 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1116 _val == 0 && \
1117 _len <= MEMSET_LOOP_LIMIT && \
1118
1119
1120
1121 \
1122 MEMSET_LOOP_LIMIT != 0) \
1123 { \
1124 size_t *_start = (size_t *) _vstart; \
1125 size_t *_stop = (size_t *) ((char *) _start + _len); \
1126 while (_start < _stop) \
1127 *_start++ = 0; \
1128 } \
1129 else \
1130 memset(_vstart, _val, _len); \
1131 } while (0)
1132
1133
1134
1135
1136
1137
1138
1139#define MemSetAligned(start, val, len) \
1140 do \
1141 { \
1142 size_t *_start = (size_t *) (start); \
1143 int _val = (val); \
1144 Size _len = (len); \
1145\
1146 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1147 _val == 0 && \
1148 _len <= MEMSET_LOOP_LIMIT && \
1149 MEMSET_LOOP_LIMIT != 0) \
1150 { \
1151 size_t *_stop = (size_t *) ((char *) _start + _len); \
1152 while (_start < _stop) \
1153 *_start++ = 0; \
1154 } \
1155 else \
1156 memset(_start, _val, _len); \
1157 } while (0)
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171#define FLOAT4_FITS_IN_INT16(num) \
1172 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1173#define FLOAT4_FITS_IN_INT32(num) \
1174 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1175#define FLOAT4_FITS_IN_INT64(num) \
1176 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1177#define FLOAT8_FITS_IN_INT16(num) \
1178 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1179#define FLOAT8_FITS_IN_INT32(num) \
1180 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1181#define FLOAT8_FITS_IN_INT64(num) \
1182 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195#define INVERT_COMPARE_RESULT(var) \
1196 ((var) = ((var) < 0) ? 1 : -(var))
1197
1198
1199
1200
1201
1202
1203
1205{
1208
1209
1210
1211
1212
1213
1214
1215#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1216
1217
1218
1219
1220
1221
1222
1223
1224
1226{
1229
1230
1232{
1235
1236#else
1237
1238
1241
1242#endif
1243
1244
1245#define HIGHBIT (0x80)
1246#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1247
1248
1249
1250
1251
1252
1253
1254#define SQL_STR_DOUBLE(ch, escape_backslash) \
1255 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1256
1257#define ESCAPE_STRING_SYNTAX 'E'
1258
1259
1260#define STATUS_OK (0)
1261#define STATUS_ERROR (-1)
1262#define STATUS_EOF (-2)
1263
1264
1265
1266
1267
1268#ifndef ENABLE_NLS
1269
1270#define gettext(x) (x)
1271#define dgettext(d,x) (x)
1272#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1273#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1274#endif
1275
1276#define _(x) gettext(x)
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287#define gettext_noop(x) (x)
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302#ifdef SO_MAJOR_VERSION
1303#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1304#else
1305#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1306#endif
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323#if defined(__cplusplus)
1324#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1325#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1326#else
1327#define unconstify(underlying_type, expr) \
1328 (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
1329 (underlying_type) (expr))
1330#define unvolatize(underlying_type, expr) \
1331 (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
1332 (underlying_type) (expr))
1333#endif
1334
1335
1336
1337
1338
1339#if (defined(__x86_64__) || defined(_M_AMD64))
1340#define USE_SSE2
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350#elif defined(__aarch64__) && defined(__ARM_NEON)
1351#define USE_NEON
1352#endif
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370#if defined(WIN32) || defined(__CYGWIN__)
1371#define PG_BINARY O_BINARY
1372#define PG_BINARY_A "ab"
1373#define PG_BINARY_R "rb"
1374#define PG_BINARY_W "wb"
1375#else
1376#define PG_BINARY 0
1377#define PG_BINARY_A "a"
1378#define PG_BINARY_R "r"
1379#define PG_BINARY_W "w"
1380#endif
1381
1382
1383
1384
1385
1386
1387#if !HAVE_DECL_FDATASYNC
1389#endif
1390
1391
1392
1393
1394
1395
1396#if SIZEOF_LONG == 8
1397#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1398#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1399#elif SIZEOF_LONG_LONG == 8
1400#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1401#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1402#else
1403#error "cannot find integer type of the same size as int64_t"
1404#endif
1405
1406
1407
1408
1409#if SIZEOF_LONG == 8
1410#define i64abs(i) ((int64) labs(i))
1411#elif SIZEOF_LONG_LONG == 8
1412#define i64abs(i) ((int64) llabs(i))
1413#else
1414#error "cannot find integer type of the same size as int64_t"
1415#endif
1416
1417
1418
1419
1420
1421
1422#ifndef PGDLLIMPORT
1423#define PGDLLIMPORT
1424#endif
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434#ifndef PGDLLEXPORT
1435#ifdef HAVE_VISIBILITY_ATTRIBUTE
1436#define PGDLLEXPORT __attribute__((visibility("default")))
1437#else
1438#define PGDLLEXPORT
1439#endif
1440#endif
1441
1442
1443
1444
1445
1446
1447
1448
1450{
1453
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464#define SIGNAL_ARGS int postgres_signal_arg, const pg_signal_info *pg_siginfo
1465
1466
1467
1468
1469
1470
1471
1472#ifdef WIN32
1473#ifdef __MINGW64__
1475#define sigsetjmp(x,y) __builtin_setjmp(x)
1476#define siglongjmp __builtin_longjmp
1477#else
1478#define sigjmp_buf jmp_buf
1479#define sigsetjmp(x,y) setjmp(x)
1480#define siglongjmp longjmp
1481#endif
1482#endif
1483
1484
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501#ifdef HAVE_UCHAR_H
1502#include <uchar.h>
1503#else
1504#ifndef __cplusplus
1507#endif
1508#endif
1509
1510
1511
1512#endif
static int fd(const char *x, int i)