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