PostgreSQL Source Code: src/include/c.h File Reference (original) (raw)

978 { static_assert(condition, errmessage); } while(0)

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993#ifndef __cplusplus

994#if !defined(_MSC_VER) || _MSC_VER >= 1933

995#define StaticAssertExpr(condition, errmessage) \

996 ((void) sizeof(struct {static_assert(condition, errmessage); char a;}))

997#else

998

999

1000

1001

1002#define StaticAssertExpr(condition, errmessage) \

1003 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))

1004#endif

1005#else

1006#define StaticAssertExpr(condition, errmessage) \

1007 ([]{static_assert(condition, errmessage);})

1008#endif

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P

1023#define StaticAssertVariableIsOfType(varname, typename) \

1024 StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \

1025 CppAsString(varname) " does not have type " CppAsString(typename))

1026#define StaticAssertVariableIsOfTypeMacro(varname, typename) \

1027 (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \

1028 CppAsString(varname) " does not have type " CppAsString(typename)))

1029#else

1030#define StaticAssertVariableIsOfType(varname, typename) \

1031 StaticAssertDecl(sizeof(varname) == sizeof(typename), \

1032 CppAsString(varname) " does not have type " CppAsString(typename))

1033#define StaticAssertVariableIsOfTypeMacro(varname, typename) \

1034 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \

1035 CppAsString(varname) " does not have type " CppAsString(typename)))

1036#endif

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047#define Max(x, y) ((x) > (y) ? (x) : (y))

1048

1049

1050

1051

1052

1053#define Min(x, y) ((x) < (y) ? (x) : (y))

1054

1055

1056

1057#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069#define MemSet(start, val, len) \

1070 do \

1071 { \

1072 \

1073 void *_vstart = (void *) (start); \

1074 int _val = (val); \

1075 Size _len = (len); \

1076\

1077 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \

1078 (_len & SIZE_T_ALIGN_MASK) == 0 && \

1079 _val == 0 && \

1080 _len <= MEMSET_LOOP_LIMIT && \

1081

1082

1083

1084 \

1085 MEMSET_LOOP_LIMIT != 0) \

1086 { \

1087 size_t *_start = (size_t *) _vstart; \

1088 size_t *_stop = (size_t *) ((char *) _start + _len); \

1089 while (_start < _stop) \

1090 *_start++ = 0; \

1091 } \

1092 else \

1093 memset(_vstart, _val, _len); \

1094 } while (0)

1095

1096

1097

1098

1099

1100

1101

1102#define MemSetAligned(start, val, len) \

1103 do \

1104 { \

1105 size_t *_start = (size_t *) (start); \

1106 int _val = (val); \

1107 Size _len = (len); \

1108\

1109 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \

1110 _val == 0 && \

1111 _len <= MEMSET_LOOP_LIMIT && \

1112 MEMSET_LOOP_LIMIT != 0) \

1113 { \

1114 size_t *_stop = (size_t *) ((char *) _start + _len); \

1115 while (_start < _stop) \

1116 *_start++ = 0; \

1117 } \

1118 else \

1119 memset(_start, _val, _len); \

1120 } while (0)

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134#define FLOAT4_FITS_IN_INT16(num) \

1135 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))

1136#define FLOAT4_FITS_IN_INT32(num) \

1137 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))

1138#define FLOAT4_FITS_IN_INT64(num) \

1139 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))

1140#define FLOAT8_FITS_IN_INT16(num) \

1141 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))

1142#define FLOAT8_FITS_IN_INT32(num) \

1143 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))

1144#define FLOAT8_FITS_IN_INT64(num) \

1145 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158#define INVERT_COMPARE_RESULT(var) \

1159 ((var) = ((var) < 0) ? 1 : -(var))

1160

1161

1162

1163

1164

1165

1166

1168{

1171

1172

1173

1174

1175

1176

1177

1178#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)

1179

1180

1181

1182

1183

1184

1185

1186

1187

1189{

1192

1193

1195{

1198

1199#else

1200

1201

1204

1205#endif

1206

1207

1208#define HIGHBIT (0x80)

1209#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)

1210

1211

1212

1213

1214

1215

1216

1217#define SQL_STR_DOUBLE(ch, escape_backslash) \

1218 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))

1219

1220#define ESCAPE_STRING_SYNTAX 'E'

1221

1222

1223#define STATUS_OK (0)

1224#define STATUS_ERROR (-1)

1225#define STATUS_EOF (-2)

1226

1227

1228

1229

1230

1231#ifndef ENABLE_NLS

1232

1233#define gettext(x) (x)

1234#define dgettext(d,x) (x)

1235#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))

1236#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))

1237#endif

1238

1239#define _(x) gettext(x)

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250#define gettext_noop(x) (x)

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265#ifdef SO_MAJOR_VERSION

1266#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)

1267#else

1268#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)

1269#endif

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286#if defined(__cplusplus)

1287#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)

1288#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)

1289#else

1290#define unconstify(underlying_type, expr) \

1291 (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \

1292 (underlying_type) (expr))

1293#define unvolatize(underlying_type, expr) \

1294 (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \

1295 (underlying_type) (expr))

1296#endif

1297

1298

1299

1300

1301

1302#if (defined(__x86_64__) || defined(_M_AMD64))

1303#define USE_SSE2

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313#elif defined(__aarch64__) && defined(__ARM_NEON)

1314#define USE_NEON

1315#endif

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333#if defined(WIN32) || defined(__CYGWIN__)

1334#define PG_BINARY O_BINARY

1335#define PG_BINARY_A "ab"

1336#define PG_BINARY_R "rb"

1337#define PG_BINARY_W "wb"

1338#else

1339#define PG_BINARY 0

1340#define PG_BINARY_A "a"

1341#define PG_BINARY_R "r"

1342#define PG_BINARY_W "w"

1343#endif

1344

1345

1346

1347

1348

1349

1350#if !HAVE_DECL_FDATASYNC

1352#endif

1353

1354

1355

1356

1357

1358

1359#if SIZEOF_LONG == 8

1360#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))

1361#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))

1362#elif SIZEOF_LONG_LONG == 8

1363#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))

1364#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))

1365#else

1366#error "cannot find integer type of the same size as int64_t"

1367#endif

1368

1369

1370

1371

1372#if SIZEOF_LONG == 8

1373#define i64abs(i) ((int64) labs(i))

1374#elif SIZEOF_LONG_LONG == 8

1375#define i64abs(i) ((int64) llabs(i))

1376#else

1377#error "cannot find integer type of the same size as int64_t"

1378#endif

1379

1380

1381

1382

1383

1384

1385#ifndef PGDLLIMPORT

1386#define PGDLLIMPORT

1387#endif

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397#ifndef PGDLLEXPORT

1398#ifdef HAVE_VISIBILITY_ATTRIBUTE

1399#define PGDLLEXPORT __attribute__((visibility("default")))

1400#else

1401#define PGDLLEXPORT

1402#endif

1403#endif

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414#ifndef SIGNAL_ARGS

1415#define SIGNAL_ARGS int postgres_signal_arg

1416#endif

1417

1418

1419

1420

1421

1422

1423

1424#ifdef WIN32

1425#ifdef __MINGW64__

1427#define sigsetjmp(x,y) __builtin_setjmp(x)

1428#define siglongjmp __builtin_longjmp

1429#else

1430#define sigjmp_buf jmp_buf

1431#define sigsetjmp(x,y) setjmp(x)

1432#define siglongjmp longjmp

1433#endif

1434#endif

1435

1436

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453#ifdef HAVE_UCHAR_H

1454#include <uchar.h>

1455#else

1456#ifndef __cplusplus

1459#endif

1460#endif

1461

1462

1463

1464#endif

static int fd(const char *x, int i)