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