MobilityDB 1.1
c.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * c.h
4 * Fundamental C definitions. This is included by every .c file in
5 * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
6 *
7 * Note that the definitions here are not intended to be exposed to clients
8 * of the frontend interface libraries --- so we don't worry much about
9 * polluting the namespace with lots of stuff...
10 *
11 *
12 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
14 *
15 * src/include/c.h
16 *
17 *-------------------------------------------------------------------------
18 */
19/*
20 *----------------------------------------------------------------
21 * TABLE OF CONTENTS
22 *
23 * When adding stuff to this file, please try to put stuff
24 * into the relevant section, or add new sections as appropriate.
25 *
26 * section description
27 * ------- ------------------------------------------------
28 * 0) pg_config.h and standard system headers
29 * 1) compiler characteristics
30 * 2) bool, true, false
31 * 3) standard system types
32 * 4) IsValid macros for system types
33 * 5) offsetof, lengthof, alignment
34 * 6) assertions
35 * 7) widely useful macros
36 * 8) random stuff
37 * 9) system-specific hacks
38 *
39 * NOTE: since this file is included by both frontend and backend modules,
40 * it's usually wrong to put an "extern" declaration here, unless it's
41 * ifdef'd so that it's seen in only one case or the other.
42 * typedefs and macros are the kind of thing that might go here.
43 *
44 *----------------------------------------------------------------
45 */
46#ifndef PG_C_H
47#define PG_C_H
48
49#include "postgres_ext.h"
50
51/* Must undef pg_config_ext.h symbols before including pg_config.h */
52#undef PG_INT64_TYPE
53
54#include "pg_config.h"
55// MEOS
56#include "pg_config_manual.h" /* must be after pg_config.h */
57// #include "pg_config_os.h" /* must be before any system header files */
58
59/* System header files that should be available everywhere in Postgres */
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <stddef.h>
64#include <stdarg.h>
65#ifdef HAVE_STRINGS_H
66#include <strings.h>
67#endif
68#include <stdint.h>
69#include <sys/types.h>
70#include <errno.h>
71#if defined(WIN32) || defined(__CYGWIN__)
72#include <fcntl.h> /* ensure O_BINARY is available */
73#endif
74#include <locale.h>
75#ifdef ENABLE_NLS
76#include <libintl.h>
77#endif
78
79
80/* ----------------------------------------------------------------
81 * Section 1: compiler characteristics
82 *
83 * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
84 * ----------------------------------------------------------------
85 */
86
87/*
88 * Disable "inline" if PG_FORCE_DISABLE_INLINE is defined.
89 * This is used to work around compiler bugs and might also be useful for
90 * investigatory purposes.
91 */
92#ifdef PG_FORCE_DISABLE_INLINE
93#undef inline
94#define inline
95#endif
96
97/*
98 * Attribute macros
99 *
100 * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
101 * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
102 * Clang: https://clang.llvm.org/docs/AttributeReference.html
103 * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
104 * XLC: https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.2/com.ibm.xlc131.aix.doc/language_ref/function_attributes.html
105 * XLC: https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.2/com.ibm.xlc131.aix.doc/language_ref/type_attrib.html
106 */
107
108/*
109 * For compilers which don't support __has_attribute, we just define
110 * __has_attribute(x) to 0 so that we can define macros for various
111 * __attribute__s more easily below.
112 */
113#ifndef __has_attribute
114#define __has_attribute(attribute) 0
115#endif
116
117/* only GCC supports the unused attribute */
118#ifdef __GNUC__
119#define pg_attribute_unused() __attribute__((unused))
120#else
121#define pg_attribute_unused()
122#endif
123
124/*
125 * pg_nodiscard means the compiler should warn if the result of a function
126 * call is ignored. The name "nodiscard" is chosen in alignment with
127 * (possibly future) C and C++ standards. For maximum compatibility, use it
128 * as a function declaration specifier, so it goes before the return type.
129 */
130#ifdef __GNUC__
131#define pg_nodiscard __attribute__((warn_unused_result))
132#else
133#define pg_nodiscard
134#endif
135
136/*
137 * Place this macro before functions that should be allowed to make misaligned
138 * accesses. Think twice before using it on non-x86-specific code!
139 * Testing can be done with "-fsanitize=alignment -fsanitize-trap=alignment"
140 * on clang, or "-fsanitize=alignment -fno-sanitize-recover=alignment" on gcc.
141 */
142#if __clang_major__ >= 7 || __GNUC__ >= 8
143#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
144#else
145#define pg_attribute_no_sanitize_alignment()
146#endif
147
148/*
149 * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
150 * used in assert-enabled builds, to avoid compiler warnings about unused
151 * variables in assert-disabled builds.
152 */
153#ifdef USE_ASSERT_CHECKING
154#define PG_USED_FOR_ASSERTS_ONLY
155#else
156#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
157#endif
158
159/* GCC and XLC support format attributes */
160#if defined(__GNUC__) || defined(__IBMC__)
161#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
162#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
163#else
164#define pg_attribute_format_arg(a)
165#define pg_attribute_printf(f,a)
166#endif
167
168/* GCC, Sunpro and XLC support aligned, packed and noreturn */
169#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
170#define pg_attribute_aligned(a) __attribute__((aligned(a)))
171#define pg_attribute_noreturn() __attribute__((noreturn))
172#define pg_attribute_packed() __attribute__((packed))
173#define HAVE_PG_ATTRIBUTE_NORETURN 1
174#else
175/*
176 * NB: aligned and packed are not given default definitions because they
177 * affect code functionality; they *must* be implemented by the compiler
178 * if they are to be used.
179 */
180#define pg_attribute_noreturn()
181#endif
182
183/*
184 * Use "pg_attribute_always_inline" in place of "inline" for functions that
185 * we wish to force inlining of, even when the compiler's heuristics would
186 * choose not to. But, if possible, don't force inlining in unoptimized
187 * debug builds.
188 */
189#if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__)
190/* GCC > 3, Sunpro and XLC support always_inline via __attribute__ */
191#define pg_attribute_always_inline __attribute__((always_inline)) inline
192#elif defined(_MSC_VER)
193/* MSVC has a special keyword for this */
194#define pg_attribute_always_inline __forceinline
195#else
196/* Otherwise, the best we can do is to say "inline" */
197#define pg_attribute_always_inline inline
198#endif
199
200/*
201 * Forcing a function not to be inlined can be useful if it's the slow path of
202 * a performance-critical function, or should be visible in profiles to allow
203 * for proper cost attribution. Note that unlike the pg_attribute_XXX macros
204 * above, this should be placed before the function's return type and name.
205 */
206/* GCC, Sunpro and XLC support noinline via __attribute__ */
207#if (defined(__GNUC__) && __GNUC__ > 2) || defined(__SUNPRO_C) || defined(__IBMC__)
208#define pg_noinline __attribute__((noinline))
209/* msvc via declspec */
210#elif defined(_MSC_VER)
211#define pg_noinline __declspec(noinline)
212#else
213#define pg_noinline
214#endif
215
216/*
217 * For now, just define pg_attribute_cold and pg_attribute_hot to be empty
218 * macros on minGW 8.1. There appears to be a compiler bug that results in
219 * compilation failure. At this time, we still have at least one buildfarm
220 * animal running that compiler, so this should make that green again. It's
221 * likely this compiler is not popular enough to warrant keeping this code
222 * around forever, so let's just remove it once the last buildfarm animal
223 * upgrades.
224 */
225#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
226
227#define pg_attribute_cold
228#define pg_attribute_hot
229
230#else
231/*
232 * Marking certain functions as "hot" or "cold" can be useful to assist the
233 * compiler in arranging the assembly code in a more efficient way.
234 */
235#if __has_attribute (cold)
236#define pg_attribute_cold __attribute__((cold))
237#else
238#define pg_attribute_cold
239#endif
240
241#if __has_attribute (hot)
242#define pg_attribute_hot __attribute__((hot))
243#else
244#define pg_attribute_hot
245#endif
246
247#endif /* defined(__MINGW64__) && __GNUC__ == 8 &&
248 * __GNUC_MINOR__ == 1 */
249/*
250 * Mark a point as unreachable in a portable fashion. This should preferably
251 * be something that the compiler understands, to aid code generation.
252 * In assert-enabled builds, we prefer abort() for debugging reasons.
253 */
254#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
255#define pg_unreachable() __builtin_unreachable()
256#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
257#define pg_unreachable() __assume(0)
258#else
259#define pg_unreachable() abort()
260#endif
261
262/*
263 * Hints to the compiler about the likelihood of a branch. Both likely() and
264 * unlikely() return the boolean value of the contained expression.
265 *
266 * These should only be used sparingly, in very hot code paths. It's very easy
267 * to mis-estimate likelihoods.
268 */
269#if __GNUC__ >= 3
270#define likely(x) __builtin_expect((x) != 0, 1)
271#define unlikely(x) __builtin_expect((x) != 0, 0)
272#else
273#define likely(x) ((x) != 0)
274#define unlikely(x) ((x) != 0)
275#endif
276
277/*
278 * CppAsString
279 * Convert the argument to a string, using the C preprocessor.
280 * CppAsString2
281 * Convert the argument to a string, after one round of macro expansion.
282 * CppConcat
283 * Concatenate two arguments together, using the C preprocessor.
284 *
285 * Note: There used to be support here for pre-ANSI C compilers that didn't
286 * support # and ##. Nowadays, these macros are just for clarity and/or
287 * backward compatibility with existing PostgreSQL code.
288 */
289#define CppAsString(identifier) #identifier
290#define CppAsString2(x) CppAsString(x)
291#define CppConcat(x, y) x##y
292
293/*
294 * VA_ARGS_NARGS
295 * Returns the number of macro arguments it is passed.
296 *
297 * An empty argument still counts as an argument, so effectively, this is
298 * "one more than the number of commas in the argument list".
299 *
300 * This works for up to 63 arguments. Internally, VA_ARGS_NARGS_() is passed
301 * 64+N arguments, and the C99 standard only requires macros to allow up to
302 * 127 arguments, so we can't portably go higher. The implementation is
303 * pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up
304 * the call so that that is the appropriate one of the list of constants.
305 * This idea is due to Laurent Deniau.
306 */
307#define VA_ARGS_NARGS(...) \
308 VA_ARGS_NARGS_(__VA_ARGS__, \
309 63,62,61,60, \
310 59,58,57,56,55,54,53,52,51,50, \
311 49,48,47,46,45,44,43,42,41,40, \
312 39,38,37,36,35,34,33,32,31,30, \
313 29,28,27,26,25,24,23,22,21,20, \
314 19,18,17,16,15,14,13,12,11,10, \
315 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
316#define VA_ARGS_NARGS_( \
317 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
318 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
319 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
320 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
321 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
322 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
323 _61,_62,_63, N, ...) \
324 (N)
325
326/*
327 * dummyret is used to set return values in macros that use ?: to make
328 * assignments. gcc wants these to be void, other compilers like char
329 */
330#ifdef __GNUC__ /* GNU cc */
331#define dummyret void
332#else
333#define dummyret char
334#endif
335
336/*
337 * Generic function pointer. This can be used in the rare cases where it's
338 * necessary to cast a function pointer to a seemingly incompatible function
339 * pointer type while avoiding gcc's -Wcast-function-type warnings.
340 */
341typedef void (*pg_funcptr_t) (void);
342
343/*
344 * We require C99, hence the compiler should understand flexible array
345 * members. However, for documentation purposes we still consider it to be
346 * project style to write "field[FLEXIBLE_ARRAY_MEMBER]" not just "field[]".
347 * When computing the size of such an object, use "offsetof(struct s, f)"
348 * for portability. Don't use "offsetof(struct s, f[0])", as this doesn't
349 * work with MSVC and with C++ compilers.
350 */
351#define FLEXIBLE_ARRAY_MEMBER /* empty */
352
353/* Which __func__ symbol do we have, if any? */
354#ifdef HAVE_FUNCNAME__FUNC
355#define PG_FUNCNAME_MACRO __func__
356#else
357#ifdef HAVE_FUNCNAME__FUNCTION
358#define PG_FUNCNAME_MACRO __FUNCTION__
359#else
360#define PG_FUNCNAME_MACRO NULL
361#endif
362#endif
363
364
365/* ----------------------------------------------------------------
366 * Section 2: bool, true, false
367 * ----------------------------------------------------------------
368 */
369
370/*
371 * bool
372 * Boolean value, either true or false.
373 *
374 * We use stdbool.h if available and its bool has size 1. That's useful for
375 * better compiler and debugger output and for compatibility with third-party
376 * libraries. But PostgreSQL currently cannot deal with bool of other sizes;
377 * there are static assertions around the code to prevent that.
378 *
379 * For C++ compilers, we assume the compiler has a compatible built-in
380 * definition of bool.
381 *
382 * See also the version of this code in src/interfaces/ecpg/include/ecpglib.h.
383 */
384
385// #ifndef __MEOS_H__
386
387#ifndef __cplusplus
388
389#ifdef PG_USE_STDBOOL
390#include <stdbool.h>
391#else
392
393#ifndef bool
394typedef unsigned char bool;
395#endif
396
397#ifndef true
398#define true ((bool) 1)
399#endif
400
401#ifndef false
402#define false ((bool) 0)
403#endif
404
405#endif /* not PG_USE_STDBOOL */
406#endif /* not C++ */
407
408// #endif /*__MEOS_H__ */
409
410
411/* ----------------------------------------------------------------
412 * Section 3: standard system types
413 * ----------------------------------------------------------------
414 */
415
416/*
417 * Pointer
418 * Variable holding address of any memory resident object.
419 *
420 * XXX Pointer arithmetic is done with this, so it can't be void *
421 * under "true" ANSI compilers.
422 */
423typedef char *Pointer;
424
425/*
426 * intN
427 * Signed integer, EXACTLY N BITS IN SIZE,
428 * used for numerical computations and the
429 * frontend/backend protocol.
430 */
431#ifndef HAVE_INT8
432typedef signed char int8; /* == 8 bits */
433typedef signed short int16; /* == 16 bits */
434typedef signed int int32; /* == 32 bits */
435#endif /* not HAVE_INT8 */
436
437/*
438 * uintN
439 * Unsigned integer, EXACTLY N BITS IN SIZE,
440 * used for numerical computations and the
441 * frontend/backend protocol.
442 */
443#ifndef HAVE_UINT8
444typedef unsigned char uint8; /* == 8 bits */
445typedef unsigned short uint16; /* == 16 bits */
446typedef unsigned int uint32; /* == 32 bits */
447#endif /* not HAVE_UINT8 */
448
449/*
450 * bitsN
451 * Unit of bitwise operation, AT LEAST N BITS IN SIZE.
452 */
453typedef uint8 bits8; /* >= 8 bits */
454typedef uint16 bits16; /* >= 16 bits */
455typedef uint32 bits32; /* >= 32 bits */
456
457/*
458 * 64-bit integers
459 */
460#ifdef HAVE_LONG_INT_64
461/* Plain "long int" fits, use it */
462
463#ifndef HAVE_INT64
464typedef long int int64;
465#endif
466#ifndef HAVE_UINT64
467typedef unsigned long int uint64;
468#endif
469#define INT64CONST(x) (x##L)
470#define UINT64CONST(x) (x##UL)
471#elif defined(HAVE_LONG_LONG_INT_64)
472/* We have working support for "long long int", use that */
473
474#ifndef HAVE_INT64
475typedef long long int int64;
476#endif
477#ifndef HAVE_UINT64
478typedef unsigned long long int uint64;
479#endif
480#define INT64CONST(x) (x##LL)
481#define UINT64CONST(x) (x##ULL)
482#else
483/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
484#error must have a working 64-bit integer datatype
485#endif
486
487/* snprintf format strings to use for 64-bit integers */
488#define INT64_FORMAT "%" INT64_MODIFIER "d"
489#define UINT64_FORMAT "%" INT64_MODIFIER "u"
490
491/*
492 * 128-bit signed and unsigned integers
493 * There currently is only limited support for such types.
494 * E.g. 128bit literals and snprintf are not supported; but math is.
495 * Also, because we exclude such types when choosing MAXIMUM_ALIGNOF,
496 * it must be possible to coerce the compiler to allocate them on no
497 * more than MAXALIGN boundaries.
498 */
499#if defined(PG_INT128_TYPE)
500#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
501#define HAVE_INT128 1
502
503typedef PG_INT128_TYPE int128
504#if defined(pg_attribute_aligned)
505 pg_attribute_aligned(MAXIMUM_ALIGNOF)
506#endif
507 ;
508
509typedef unsigned PG_INT128_TYPE uint128
510#if defined(pg_attribute_aligned)
511 pg_attribute_aligned(MAXIMUM_ALIGNOF)
512#endif
513 ;
514
515#endif
516#endif
517
518/*
519 * stdint.h limits aren't guaranteed to have compatible types with our fixed
520 * width types. So just define our own.
521 */
522#define PG_INT8_MIN (-0x7F-1)
523#define PG_INT8_MAX (0x7F)
524#define PG_UINT8_MAX (0xFF)
525#define PG_INT16_MIN (-0x7FFF-1)
526#define PG_INT16_MAX (0x7FFF)
527#define PG_UINT16_MAX (0xFFFF)
528#define PG_INT32_MIN (-0x7FFFFFFF-1)
529#define PG_INT32_MAX (0x7FFFFFFF)
530#define PG_UINT32_MAX (0xFFFFFFFFU)
531#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
532#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
533#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
534
535/*
536 * We now always use int64 timestamps, but keep this symbol defined for the
537 * benefit of external code that might test it.
538 */
539#define HAVE_INT64_TIMESTAMP
540
541/*
542 * Size
543 * Size of any memory resident object, as returned by sizeof.
544 */
545typedef size_t Size;
546
547/*
548 * Index
549 * Index into any memory resident array.
550 *
551 * Note:
552 * Indices are non negative.
553 */
554typedef unsigned int Index;
555
556/*
557 * Offset
558 * Offset into any memory resident array.
559 *
560 * Note:
561 * This differs from an Index in that an Index is always
562 * non negative, whereas Offset may be negative.
563 */
564typedef signed int Offset;
565
566/*
567 * Common Postgres datatype names (as used in the catalogs)
568 */
569typedef float float4;
570typedef double float8;
571
572#ifdef USE_FLOAT8_BYVAL
573#define FLOAT8PASSBYVAL true
574#else
575#define FLOAT8PASSBYVAL false
576#endif
577
578/*
579 * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
580 * CommandId
581 */
582
583/* typedef Oid is in postgres_ext.h */
584
585/*
586 * regproc is the type name used in the include/catalog headers, but
587 * RegProcedure is the preferred name in C code.
588 */
589typedef Oid regproc;
591
593
595
597
598#define InvalidSubTransactionId ((SubTransactionId) 0)
599#define TopSubTransactionId ((SubTransactionId) 1)
600
601/* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
603
605
607
608#define FirstCommandId ((CommandId) 0)
609#define InvalidCommandId (~(CommandId)0)
610
611
612/* ----------------
613 * Variable-length datatypes all share the 'struct varlena' header.
614 *
615 * NOTE: for TOASTable types, this is an oversimplification, since the value
616 * may be compressed or moved out-of-line. However datatype-specific routines
617 * are mostly content to deal with de-TOASTed values only, and of course
618 * client-side routines should never see a TOASTed value. But even in a
619 * de-TOASTed value, beware of touching vl_len_ directly, as its
620 * representation is no longer convenient. It's recommended that code always
621 * use macros VARDATA_ANY, VARSIZE_ANY, VARSIZE_ANY_EXHDR, VARDATA, VARSIZE,
622 * and SET_VARSIZE instead of relying on direct mentions of the struct fields.
623 * See postgres.h for details of the TOASTed form.
624 * ----------------
625 */
626struct varlena
627{
628 char vl_len_[4]; /* Do not touch this field directly! */
629 char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */
630};
631
632#define VARHDRSZ ((int32) sizeof(int32))
633
634/*
635 * These widely-used datatypes are just a varlena header and the data bytes.
636 * There is no terminating null or anything like that --- the data length is
637 * always VARSIZE_ANY_EXHDR(ptr).
638 */
639typedef struct varlena bytea;
640typedef struct varlena text;
641typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */
642typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
643
644// MEOS
645// /*
646 // * Specialized array types. These are physically laid out just the same
647 // * as regular arrays (so that the regular array subscripting code works
648 // * with them). They exist as distinct types mostly for historical reasons:
649 // * they have nonstandard I/O behavior which we don't want to change for fear
650 // * of breaking applications that look at the system catalogs. There is also
651 // * an implementation issue for oidvector: it's part of the primary key for
652 // * pg_proc, and we can't use the normal btree array support routines for that
653 // * without circularity.
654 // */
655// typedef struct
656// {
657 // int32 vl_len_; /* these fields must match ArrayType! */
658 // int ndim; /* always 1 for int2vector */
659 // int32 dataoffset; /* always 0 for int2vector */
660 // Oid elemtype;
661 // int dim1;
662 // int lbound1;
663 // int16 values[FLEXIBLE_ARRAY_MEMBER];
664// } int2vector;
665
666// typedef struct
667// {
668 // int32 vl_len_; /* these fields must match ArrayType! */
669 // int ndim; /* always 1 for oidvector */
670 // int32 dataoffset; /* always 0 for oidvector */
671 // Oid elemtype;
672 // int dim1;
673 // int lbound1;
674 // Oid values[FLEXIBLE_ARRAY_MEMBER];
675// } oidvector;
676
677// MEOS
678// /*
679 // * Representation of a Name: effectively just a C string, but null-padded to
680 // * exactly NAMEDATALEN bytes. The use of a struct is historical.
681 // */
682// typedef struct nameData
683// {
684 // char data[NAMEDATALEN];
685// } NameData;
686// typedef NameData *Name;
687
688// #define NameStr(name) ((name).data)
689
690
691/* ----------------------------------------------------------------
692 * Section 4: IsValid macros for system types
693 * ----------------------------------------------------------------
694 */
695/*
696 * BoolIsValid
697 * True iff bool is valid.
698 */
699#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
700
701/*
702 * PointerIsValid
703 * True iff pointer is valid.
704 */
705#define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
706
707/*
708 * PointerIsAligned
709 * True iff pointer is properly aligned to point to the given type.
710 */
711#define PointerIsAligned(pointer, type) \
712 (((uintptr_t)(pointer) % (sizeof (type))) == 0)
713
714#define OffsetToPointer(base, offset) \
715 ((void *)((char *) base + offset))
716
717#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
718
719#define RegProcedureIsValid(p) OidIsValid(p)
720
721
722/* ----------------------------------------------------------------
723 * Section 5: offsetof, lengthof, alignment
724 * ----------------------------------------------------------------
725 */
726/*
727 * offsetof
728 * Offset of a structure/union field within that structure/union.
729 *
730 * XXX This is supposed to be part of stddef.h, but isn't on
731 * some systems (like SunOS 4).
732 */
733#ifndef offsetof
734#define offsetof(type, field) ((long) &((type *)0)->field)
735#endif /* offsetof */
736
737/*
738 * lengthof
739 * Number of elements in an array.
740 */
741#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
742
743/* ----------------
744 * Alignment macros: align a length or address appropriately for a given type.
745 * The fooALIGN() macros round up to a multiple of the required alignment,
746 * while the fooALIGN_DOWN() macros round down. The latter are more useful
747 * for problems like "how many X-sized structures will fit in a page?".
748 *
749 * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
750 * That case seems extremely unlikely to be needed in practice, however.
751 *
752 * NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
753 * larger-than-8-byte types the compiler might have.
754 * ----------------
755 */
756
757#define TYPEALIGN(ALIGNVAL,LEN) \
758 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
759
760#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
761#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
762#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
763#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
764#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
765/* MAXALIGN covers only built-in types, not buffers */
766#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
767#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
768
769#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
770 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
771
772#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
773#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
774#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
775#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
776#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
777#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
778
779/*
780 * The above macros will not work with types wider than uintptr_t, like with
781 * uint64 on 32-bit platforms. That's not problem for the usual use where a
782 * pointer or a length is aligned, but for the odd case that you need to
783 * align something (potentially) wider, use TYPEALIGN64.
784 */
785#define TYPEALIGN64(ALIGNVAL,LEN) \
786 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
787
788/* we don't currently need wider versions of the other ALIGN macros */
789#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
790
791
792/* ----------------------------------------------------------------
793 * Section 6: assertions
794 * ----------------------------------------------------------------
795 */
796
797/*
798 * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
799 * - plai 9/5/90
800 *
801 * It should _NOT_ be defined in releases or in benchmark copies
802 */
803
804/*
805 * Assert() can be used in both frontend and backend code. In frontend code it
806 * just calls the standard assert, if it's available. If use of assertions is
807 * not configured, it does nothing.
808 */
809#ifndef USE_ASSERT_CHECKING
810
811#define Assert(condition) ((void)true)
812#define AssertMacro(condition) ((void)true)
813#define AssertArg(condition) ((void)true)
814#define AssertState(condition) ((void)true)
815#define AssertPointerAlignment(ptr, bndr) ((void)true)
816#define Trap(condition, errorType) ((void)true)
817#define TrapMacro(condition, errorType) (true)
818
819#elif defined(FRONTEND)
820
821#include <assert.h>
822#define Assert(p) assert(p)
823#define AssertMacro(p) ((void) assert(p))
824#define AssertArg(condition) assert(condition)
825#define AssertState(condition) assert(condition)
826#define AssertPointerAlignment(ptr, bndr) ((void)true)
827
828#else /* USE_ASSERT_CHECKING && !FRONTEND */
829
830/*
831 * Trap
832 * Generates an exception if the given condition is true.
833 */
834#define Trap(condition, errorType) \
835 do { \
836 if (condition) \
837 ExceptionalCondition(#condition, (errorType), \
838 __FILE__, __LINE__); \
839 } while (0)
840
841/*
842 * TrapMacro is the same as Trap but it's intended for use in macros:
843 *
844 * #define foo(x) (AssertMacro(x != 0), bar(x))
845 *
846 * Isn't CPP fun?
847 */
848#define TrapMacro(condition, errorType) \
849 ((bool) (! (condition) || \
850 (ExceptionalCondition(#condition, (errorType), \
851 __FILE__, __LINE__), 0)))
852
853#define Assert(condition) \
854 do { \
855 if (!(condition)) \
856 ExceptionalCondition(#condition, "FailedAssertion", \
857 __FILE__, __LINE__); \
858 } while (0)
859
860#define AssertMacro(condition) \
861 ((void) ((condition) || \
862 (ExceptionalCondition(#condition, "FailedAssertion", \
863 __FILE__, __LINE__), 0)))
864
865#define AssertArg(condition) \
866 do { \
867 if (!(condition)) \
868 ExceptionalCondition(#condition, "BadArgument", \
869 __FILE__, __LINE__); \
870 } while (0)
871
872#define AssertState(condition) \
873 do { \
874 if (!(condition)) \
875 ExceptionalCondition(#condition, "BadState", \
876 __FILE__, __LINE__); \
877 } while (0)
878
879/*
880 * Check that `ptr' is `bndr' aligned.
881 */
882#define AssertPointerAlignment(ptr, bndr) \
883 Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \
884 "UnalignedPointer")
885
886#endif /* USE_ASSERT_CHECKING && !FRONTEND */
887
888/*
889 * ExceptionalCondition is compiled into the backend whether or not
890 * USE_ASSERT_CHECKING is defined, so as to support use of extensions
891 * that are built with that #define with a backend that isn't. Hence,
892 * we should declare it as long as !FRONTEND.
893 */
894#ifndef FRONTEND
895extern void ExceptionalCondition(const char *conditionName,
896 const char *errorType,
897 const char *fileName, int lineNumber) pg_attribute_noreturn();
898#endif
899
900/*
901 * Macros to support compile-time assertion checks.
902 *
903 * If the "condition" (a compile-time-constant expression) evaluates to false,
904 * throw a compile error using the "errmessage" (a string literal).
905 *
906 * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic
907 * placement restrictions. Macros StaticAssertStmt() and StaticAssertExpr()
908 * make it safe to use as a statement or in an expression, respectively.
909 * The macro StaticAssertDecl() is suitable for use at file scope (outside of
910 * any function).
911 *
912 * Otherwise we fall back on a kluge that assumes the compiler will complain
913 * about a negative width for a struct bit-field. This will not include a
914 * helpful error message, but it beats not getting an error at all.
915 */
916#ifndef __cplusplus
917#ifdef HAVE__STATIC_ASSERT
918#define StaticAssertStmt(condition, errmessage) \
919 do { _Static_assert(condition, errmessage); } while(0)
920#define StaticAssertExpr(condition, errmessage) \
921 ((void) ({ StaticAssertStmt(condition, errmessage); true; }))
922#define StaticAssertDecl(condition, errmessage) \
923 _Static_assert(condition, errmessage)
924#else /* !HAVE__STATIC_ASSERT */
925#define StaticAssertStmt(condition, errmessage) \
926 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
927#define StaticAssertExpr(condition, errmessage) \
928 StaticAssertStmt(condition, errmessage)
929#define StaticAssertDecl(condition, errmessage) \
930 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
931#endif /* HAVE__STATIC_ASSERT */
932#else /* C++ */
933#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410
934#define StaticAssertStmt(condition, errmessage) \
935 static_assert(condition, errmessage)
936#define StaticAssertExpr(condition, errmessage) \
937 ({ static_assert(condition, errmessage); })
938#define StaticAssertDecl(condition, errmessage) \
939 static_assert(condition, errmessage)
940#else /* !__cpp_static_assert */
941#define StaticAssertStmt(condition, errmessage) \
942 do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
943#define StaticAssertExpr(condition, errmessage) \
944 ((void) ({ StaticAssertStmt(condition, errmessage); }))
945#define StaticAssertDecl(condition, errmessage) \
946 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
947#endif /* __cpp_static_assert */
948#endif /* C++ */
949
950
951/*
952 * Compile-time checks that a variable (or expression) has the specified type.
953 *
954 * AssertVariableIsOfType() can be used as a statement.
955 * AssertVariableIsOfTypeMacro() is intended for use in macros, eg
956 * #define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x))
957 *
958 * If we don't have __builtin_types_compatible_p, we can still assert that
959 * the types have the same size. This is far from ideal (especially on 32-bit
960 * platforms) but it provides at least some coverage.
961 */
962#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
963#define AssertVariableIsOfType(varname, typename) \
964 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
965 CppAsString(varname) " does not have type " CppAsString(typename))
966#define AssertVariableIsOfTypeMacro(varname, typename) \
967 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
968 CppAsString(varname) " does not have type " CppAsString(typename)))
969#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
970#define AssertVariableIsOfType(varname, typename) \
971 StaticAssertStmt(sizeof(varname) == sizeof(typename), \
972 CppAsString(varname) " does not have type " CppAsString(typename))
973#define AssertVariableIsOfTypeMacro(varname, typename) \
974 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
975 CppAsString(varname) " does not have type " CppAsString(typename)))
976#endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
977
978
979/* ----------------------------------------------------------------
980 * Section 7: widely useful macros
981 * ----------------------------------------------------------------
982 */
983/*
984 * Max
985 * Return the maximum of two numbers.
986 */
987#define Max(x, y) ((x) > (y) ? (x) : (y))
988
989/*
990 * Min
991 * Return the minimum of two numbers.
992 */
993#define Min(x, y) ((x) < (y) ? (x) : (y))
994
995/*
996 * Abs
997 * Return the absolute value of the argument.
998 */
999#define Abs(x) ((x) >= 0 ? (x) : -(x))
1000
1001
1002/* Get a bit mask of the bits set in non-long aligned addresses */
1003#define LONG_ALIGN_MASK (sizeof(long) - 1)
1004
1005/*
1006 * MemSet
1007 * Exactly the same as standard library function memset(), but considerably
1008 * faster for zeroing small word-aligned structures (such as parsetree nodes).
1009 * This has to be a macro because the main point is to avoid function-call
1010 * overhead. However, we have also found that the loop is faster than
1011 * native libc memset() on some platforms, even those with assembler
1012 * memset() functions. More research needs to be done, perhaps with
1013 * MEMSET_LOOP_LIMIT tests in configure.
1014 */
1015#define MemSet(start, val, len) \
1016 do \
1017 { \
1018 /* must be void* because we don't know if it is integer aligned yet */ \
1019 void *_vstart = (void *) (start); \
1020 int _val = (val); \
1021 Size _len = (len); \
1022\
1023 if ((((uintptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
1024 (_len & LONG_ALIGN_MASK) == 0 && \
1025 _val == 0 && \
1026 _len <= MEMSET_LOOP_LIMIT && \
1027 /* \
1028 * If MEMSET_LOOP_LIMIT == 0, optimizer should find \
1029 * the whole "if" false at compile time. \
1030 */ \
1031 MEMSET_LOOP_LIMIT != 0) \
1032 { \
1033 long *_start = (long *) _vstart; \
1034 long *_stop = (long *) ((char *) _start + _len); \
1035 while (_start < _stop) \
1036 *_start++ = 0; \
1037 } \
1038 else \
1039 memset(_vstart, _val, _len); \
1040 } while (0)
1041
1042/*
1043 * MemSetAligned is the same as MemSet except it omits the test to see if
1044 * "start" is word-aligned. This is okay to use if the caller knows a-priori
1045 * that the pointer is suitably aligned (typically, because he just got it
1046 * from palloc(), which always delivers a max-aligned pointer).
1047 */
1048#define MemSetAligned(start, val, len) \
1049 do \
1050 { \
1051 long *_start = (long *) (start); \
1052 int _val = (val); \
1053 Size _len = (len); \
1054\
1055 if ((_len & LONG_ALIGN_MASK) == 0 && \
1056 _val == 0 && \
1057 _len <= MEMSET_LOOP_LIMIT && \
1058 MEMSET_LOOP_LIMIT != 0) \
1059 { \
1060 long *_stop = (long *) ((char *) _start + _len); \
1061 while (_start < _stop) \
1062 *_start++ = 0; \
1063 } \
1064 else \
1065 memset(_start, _val, _len); \
1066 } while (0)
1067
1068
1069/*
1070 * MemSetTest/MemSetLoop are a variant version that allow all the tests in
1071 * MemSet to be done at compile time in cases where "val" and "len" are
1072 * constants *and* we know the "start" pointer must be word-aligned.
1073 * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
1074 * MemSetAligned. Beware of multiple evaluations of the arguments when using
1075 * this approach.
1076 */
1077#define MemSetTest(val, len) \
1078 ( ((len) & LONG_ALIGN_MASK) == 0 && \
1079 (len) <= MEMSET_LOOP_LIMIT && \
1080 MEMSET_LOOP_LIMIT != 0 && \
1081 (val) == 0 )
1082
1083#define MemSetLoop(start, val, len) \
1084 do \
1085 { \
1086 long * _start = (long *) (start); \
1087 long * _stop = (long *) ((char *) _start + (Size) (len)); \
1088 \
1089 while (_start < _stop) \
1090 *_start++ = 0; \
1091 } while (0)
1092
1093/*
1094 * Macros for range-checking float values before converting to integer.
1095 * We must be careful here that the boundary values are expressed exactly
1096 * in the float domain. PG_INTnn_MIN is an exact power of 2, so it will
1097 * be represented exactly; but PG_INTnn_MAX isn't, and might get rounded
1098 * off, so avoid using that.
1099 * The input must be rounded to an integer beforehand, typically with rint(),
1100 * else we might draw the wrong conclusion about close-to-the-limit values.
1101 * These macros will do the right thing for Inf, but not necessarily for NaN,
1102 * so check isnan(num) first if that's a possibility.
1104#define FLOAT4_FITS_IN_INT16(num) \
1105 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1106#define FLOAT4_FITS_IN_INT32(num) \
1107 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1108#define FLOAT4_FITS_IN_INT64(num) \
1109 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1110#define FLOAT8_FITS_IN_INT16(num) \
1111 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1112#define FLOAT8_FITS_IN_INT32(num) \
1113 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1114#define FLOAT8_FITS_IN_INT64(num) \
1115 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1116
1117
1118/* ----------------------------------------------------------------
1119 * Section 8: random stuff
1120 * ----------------------------------------------------------------
1122
1123#ifdef HAVE_STRUCT_SOCKADDR_UN
1124#define HAVE_UNIX_SOCKETS 1
1125#endif
1126
1127/*
1128 * Invert the sign of a qsort-style comparison result, ie, exchange negative
1129 * and positive integer values, being careful not to get the wrong answer
1130 * for INT_MIN. The argument should be an integral variable.
1131 */
1132#define INVERT_COMPARE_RESULT(var) \
1133 ((var) = ((var) < 0) ? 1 : -(var))
1134
1135/*
1136 * Use this, not "char buf[BLCKSZ]", to declare a field or local variable
1137 * holding a page buffer, if that page might be accessed as a page and not
1138 * just a string of bytes. Otherwise the variable might be under-aligned,
1139 * causing problems on alignment-picky hardware. (In some places, we use
1140 * this to declare buffers even though we only pass them to read() and
1141 * write(), because copying to/from aligned buffers is usually faster than
1142 * using unaligned buffers.) We include both "double" and "int64" in the
1143 * union to ensure that the compiler knows the value must be MAXALIGN'ed
1144 * (cf. configure's computation of MAXIMUM_ALIGNOF).
1146typedef union PGAlignedBlock
1149 double force_align_d;
1152
1153/* Same, but for an XLOG_BLCKSZ-sized buffer */
1157 double force_align_d;
1161/* msb for char */
1162#define HIGHBIT (0x80)
1163#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1164
1165/*
1166 * Support macros for escaping strings. escape_backslash should be true
1167 * if generating a non-standard-conforming string. Prefixing a string
1168 * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
1169 * Beware of multiple evaluation of the "ch" argument!
1170 */
1171#define SQL_STR_DOUBLE(ch, escape_backslash) \
1172 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1173
1174#define ESCAPE_STRING_SYNTAX 'E'
1177#define STATUS_OK (0)
1178#define STATUS_ERROR (-1)
1179#define STATUS_EOF (-2)
1180
1181/*
1182 * gettext support
1183 */
1185#ifndef ENABLE_NLS
1186/* stuff we'd otherwise get from <libintl.h> */
1187#define gettext(x) (x)
1188#define dgettext(d,x) (x)
1189#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1190#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1191#endif
1192
1193#define _(x) gettext(x)
1194
1195/*
1196 * Use this to mark string constants as needing translation at some later
1197 * time, rather than immediately. This is useful for cases where you need
1198 * access to the original string and translated string, and for cases where
1199 * immediate translation is not possible, like when initializing global
1200 * variables.
1202 * https://www.gnu.org/software/gettext/manual/html_node/Special-cases.html
1203 */
1204#define gettext_noop(x) (x)
1205
1206/*
1207 * To better support parallel installations of major PostgreSQL
1208 * versions as well as parallel installations of major library soname
1209 * versions, we mangle the gettext domain name by appending those
1210 * version numbers. The coding rule ought to be that wherever the
1211 * domain name is mentioned as a literal, it must be wrapped into
1212 * PG_TEXTDOMAIN(). The macros below do not work on non-literals; but
1213 * that is somewhat intentional because it avoids having to worry
1214 * about multiple states of premangling and postmangling as the values
1215 * are being passed around.
1216 *
1217 * Make sure this matches the installation rules in nls-global.mk.
1218 */
1219#ifdef SO_MAJOR_VERSION
1220#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1221#else
1222#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1223#endif
1224
1225/*
1226 * Macro that allows to cast constness and volatile away from an expression, but doesn't
1227 * allow changing the underlying type. Enforcement of the latter
1228 * currently only works for gcc like compilers.
1229 *
1230 * Please note IT IS NOT SAFE to cast constness away if the result will ever
1231 * be modified (it would be undefined behaviour). Doing so anyway can cause
1232 * compiler misoptimizations or runtime crashes (modifying readonly memory).
1233 * It is only safe to use when the result will not be modified, but API
1234 * design or language restrictions prevent you from declaring that
1235 * (e.g. because a function returns both const and non-const variables).
1236 *
1237 * Note that this only works in function scope, not for global variables (it'd
1238 * be nice, but not trivial, to improve that).
1239 */
1240#if defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1241#define unconstify(underlying_type, expr) \
1242 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1243 "wrong cast"), \
1244 (underlying_type) (expr))
1245#define unvolatize(underlying_type, expr) \
1246 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1247 "wrong cast"), \
1248 (underlying_type) (expr))
1249#else
1250#define unconstify(underlying_type, expr) \
1251 ((underlying_type) (expr))
1252#define unvolatize(underlying_type, expr) \
1253 ((underlying_type) (expr))
1254#endif
1255
1256/* ----------------------------------------------------------------
1257 * Section 9: system-specific hacks
1258 *
1259 * This should be limited to things that absolutely have to be
1260 * included in every source file. The port-specific header file
1261 * is usually a better place for this sort of thing.
1262 * ----------------------------------------------------------------
1263 */
1264
1265/*
1266 * NOTE: this is also used for opening text files.
1267 * WIN32 treats Control-Z as EOF in files opened in text mode.
1268 * Therefore, we open files in binary mode on Win32 so we can read
1269 * literal control-Z. The other affect is that we see CRLF, but
1270 * that is OK because we can already handle those cleanly.
1271 */
1272#if defined(WIN32) || defined(__CYGWIN__)
1273#define PG_BINARY O_BINARY
1274#define PG_BINARY_A "ab"
1275#define PG_BINARY_R "rb"
1276#define PG_BINARY_W "wb"
1277#else
1278#define PG_BINARY 0
1279#define PG_BINARY_A "a"
1280#define PG_BINARY_R "r"
1281#define PG_BINARY_W "w"
1282#endif
1283
1284/*
1285 * Provide prototypes for routines not present in a particular machine's
1286 * standard C library.
1287 */
1288
1289#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
1290extern int fdatasync(int fildes);
1291#endif
1292
1293/* Older platforms may provide strto[u]ll functionality under other names */
1294#if !defined(HAVE_STRTOLL) && defined(HAVE___STRTOLL)
1295#define strtoll __strtoll
1296#define HAVE_STRTOLL 1
1297#endif
1298
1299#if !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
1300#define strtoll strtoq
1301#define HAVE_STRTOLL 1
1302#endif
1303
1304#if !defined(HAVE_STRTOULL) && defined(HAVE___STRTOULL)
1305#define strtoull __strtoull
1306#define HAVE_STRTOULL 1
1307#endif
1308
1309#if !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
1310#define strtoull strtouq
1311#define HAVE_STRTOULL 1
1312#endif
1313
1314#if defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
1315extern long long strtoll(const char *str, char **endptr, int base);
1316#endif
1317
1318#if defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
1319extern unsigned long long strtoull(const char *str, char **endptr, int base);
1320#endif
1322/* no special DLL markers on most ports */
1323#ifndef PGDLLIMPORT
1324#define PGDLLIMPORT
1325#endif
1326#ifndef PGDLLEXPORT
1327#define PGDLLEXPORT
1328#endif
1329
1330/*
1331 * The following is used as the arg list for signal handlers. Any ports
1332 * that take something other than an int argument should override this in
1333 * their pg_config_os.h file. Note that variable names are required
1334 * because it is used in both the prototypes as well as the definitions.
1335 * Note also the long name. We expect that this won't collide with
1336 * other names causing compiler warnings.
1338
1339#ifndef SIGNAL_ARGS
1340#define SIGNAL_ARGS int postgres_signal_arg
1341#endif
1342
1343/*
1344 * When there is no sigsetjmp, its functionality is provided by plain
1345 * setjmp. We now support the case only on Windows. However, it seems
1346 * that MinGW-64 has some longstanding issues in its setjmp support,
1347 * so on that toolchain we cheat and use gcc's builtins.
1348 */
1349#ifdef WIN32
1350#ifdef __MINGW64__
1351typedef intptr_t sigjmp_buf[5];
1352#define sigsetjmp(x,y) __builtin_setjmp(x)
1353#define siglongjmp __builtin_longjmp
1354#else /* !__MINGW64__ */
1355#define sigjmp_buf jmp_buf
1356#define sigsetjmp(x,y) setjmp(x)
1357#define siglongjmp longjmp
1358#endif /* __MINGW64__ */
1359#endif /* WIN32 */
1360
1361/* EXEC_BACKEND defines */
1362#ifdef EXEC_BACKEND
1363#define NON_EXEC_STATIC
1364#else
1365#define NON_EXEC_STATIC static
1366#endif
1367
1368/* /port compatibility functions */
1369
1370#include "port.h"
1371
1372#endif /* PG_C_H */
unsigned short uint16
Definition: c.h:445
#define pg_attribute_noreturn()
Definition: c.h:180
unsigned int uint32
Definition: c.h:446
uint16 bits16
Definition: c.h:454
signed char int8
Definition: c.h:432
union PGAlignedBlock PGAlignedBlock
signed short int16
Definition: c.h:433
union PGAlignedXLogBlock PGAlignedXLogBlock
void ExceptionalCondition(const char *conditionName, const char *errorType, const char *fileName, int lineNumber) pg_attribute_noreturn()
uint32 SubTransactionId
Definition: c.h:596
signed int int32
Definition: c.h:434
char * Pointer
Definition: c.h:423
Oid regproc
Definition: c.h:589
uint32 MultiXactOffset
Definition: c.h:604
double float8
Definition: c.h:570
TransactionId MultiXactId
Definition: c.h:602
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:351
regproc RegProcedure
Definition: c.h:590
uint8 bits8
Definition: c.h:453
uint32 bits32
Definition: c.h:455
unsigned int Index
Definition: c.h:554
float float4
Definition: c.h:569
uint32 LocalTransactionId
Definition: c.h:594
unsigned char uint8
Definition: c.h:444
uint32 CommandId
Definition: c.h:606
uint32 TransactionId
Definition: c.h:592
signed int Offset
Definition: c.h:564
unsigned long int uint64
Definition: c.h:467
void(* pg_funcptr_t)(void)
Definition: c.h:341
size_t Size
Definition: c.h:545
long int int64
Definition: c.h:464
#define BLCKSZ
Definition: pg_config.h:44
#define XLOG_BLCKSZ
Definition: pg_config.h:976
#define MAXIMUM_ALIGNOF
Definition: pg_config.h:783
#define PG_INT128_TYPE
Definition: pg_config.h:811
unsigned short uint16
Definition: pg_ext_defs.in.h:12
unsigned int uint32
Definition: pg_ext_defs.in.h:13
unsigned char uint8
Definition: pg_ext_defs.in.h:11
long int int64
Definition: pg_ext_defs.in.h:9
unsigned int Oid
Definition: postgres_ext.h:31
char vl_len_[4]
Definition: pg_ext_defs.in.h:32
char vl_dat[]
Definition: pg_ext_defs.in.h:33
Definition: pg_ext_defs.in.h:31
double force_align_d
Definition: c.h:1146
int64 force_align_i64
Definition: c.h:1147
char data[BLCKSZ]
Definition: c.h:1145
Definition: c.h:1144
char data[XLOG_BLCKSZ]
Definition: c.h:1153
double force_align_d
Definition: c.h:1154
int64 force_align_i64
Definition: c.h:1155
Definition: c.h:1152