]> granicus.if.org Git - postgresql/blob - src/include/postgres.h
Rename DLLIMPORT macro to PGDLLIMPORT to avoid conflict with
[postgresql] / src / include / postgres.h
1 /*-------------------------------------------------------------------------
2  *
3  * postgres.h
4  *        Primary include file for PostgreSQL server .c files
5  *
6  * This should be the first file included by PostgreSQL backend modules.
7  * Client-side code should include postgres_fe.h instead.
8  *
9  *
10  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
11  * Portions Copyright (c) 1995, Regents of the University of California
12  *
13  * $PostgreSQL: pgsql/src/include/postgres.h,v 1.82 2007/07/25 12:22:53 mha Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17 /*
18  *----------------------------------------------------------------
19  *       TABLE OF CONTENTS
20  *
21  *              When adding stuff to this file, please try to put stuff
22  *              into the relevant section, or add new sections as appropriate.
23  *
24  *        section       description
25  *        -------       ------------------------------------------------
26  *              1)              variable-length datatypes (TOAST support)
27  *              2)              datum type + support macros
28  *              3)              exception handling definitions
29  *              4)              genbki macros used by catalog/pg_xxx.h files
30  *
31  *       NOTES
32  *
33  *      In general, this file should contain declarations that are widely needed
34  *      in the backend environment, but are of no interest outside the backend.
35  *
36  *      Simple type definitions live in c.h, where they are shared with
37  *      postgres_fe.h.  We do that since those type definitions are needed by
38  *      frontend modules that want to deal with binary data transmission to or
39  *      from the backend.  Type definitions in this file should be for
40  *      representations that never escape the backend, such as Datum or
41  *      TOASTed varlena objects.
42  *
43  *----------------------------------------------------------------
44  */
45 #ifndef POSTGRES_H
46 #define POSTGRES_H
47
48 #include "c.h"
49 #include "utils/elog.h"
50 #include "utils/palloc.h"
51
52 /* ----------------------------------------------------------------
53  *                              Section 1:      variable-length datatypes (TOAST support)
54  * ----------------------------------------------------------------
55  */
56
57 /*
58  * struct varatt_external is a "TOAST pointer", that is, the information
59  * needed to fetch a stored-out-of-line Datum.  The data is compressed
60  * if and only if va_extsize < va_rawsize - VARHDRSZ.  This struct must not
61  * contain any padding, because we sometimes compare pointers using memcmp.
62  *
63  * Note that this information is stored unaligned within actual tuples, so
64  * you need to memcpy from the tuple into a local struct variable before
65  * you can look at these fields!  (The reason we use memcmp is to avoid
66  * having to do that just to detect equality of two TOAST pointers...)
67  */
68 struct varatt_external
69 {
70         int32           va_rawsize;                     /* Original data size (includes header) */
71         int32           va_extsize;                     /* External saved size (doesn't) */
72         Oid                     va_valueid;                     /* Unique ID of value within TOAST table */
73         Oid                     va_toastrelid;          /* RelID of TOAST table containing it */
74 };
75
76 /*
77  * These structs describe the header of a varlena object that may have been
78  * TOASTed.  Generally, don't reference these structs directly, but use the
79  * macros below.
80  *
81  * We use separate structs for the aligned and unaligned cases because the
82  * compiler might otherwise think it could generate code that assumes
83  * alignment while touching fields of a 1-byte-header varlena.
84  */
85 typedef union
86 {
87         struct                                                  /* Normal varlena (4-byte length) */
88         {
89                 uint32  va_header;
90                 char    va_data[1];
91         } va_4byte;
92         struct                                                  /* Compressed-in-line format */
93         {
94                 uint32  va_header;
95                 uint32  va_rawsize;                     /* Original data size (excludes header) */
96                 char    va_data[1];                     /* Compressed data */
97         } va_compressed;
98 } varattrib_4b;
99
100 typedef struct
101 {
102         uint8           va_header;
103         char            va_data[1];                     /* Data or TOAST pointer */
104 } varattrib_1b;
105
106 typedef struct
107 {
108         uint8           va_header;
109         char            va_data[sizeof(struct varatt_external)];
110 } varattrib_pointer;
111
112 /*
113  * Bit layouts for varlena headers on big-endian machines:
114  *
115  * 00xxxxxx     4-byte length word, aligned, uncompressed data (up to 1G)
116  * 01xxxxxx     4-byte length word, aligned, *compressed* data (up to 1G)
117  * 10000000     1-byte length word, unaligned, TOAST pointer
118  * 1xxxxxxx     1-byte length word, unaligned, uncompressed data (up to 126b)
119  *
120  * Bit layouts for varlena headers on little-endian machines:
121  *
122  * xxxxxx00     4-byte length word, aligned, uncompressed data (up to 1G)
123  * xxxxxx10     4-byte length word, aligned, *compressed* data (up to 1G)
124  * 00000001     1-byte length word, unaligned, TOAST pointer
125  * xxxxxxx1     1-byte length word, unaligned, uncompressed data (up to 126b)
126  *
127  * The "xxx" bits are the length field (which includes itself in all cases).
128  * In the big-endian case we mask to extract the length, in the little-endian
129  * case we shift.  Note that in both cases the flag bits are in the physically
130  * first byte.  Also, it is not possible for a 1-byte length word to be zero;
131  * this lets us disambiguate alignment padding bytes from the start of an
132  * unaligned datum.  (We now *require* pad bytes to be filled with zero!)
133  */
134
135 /*
136  * Endian-dependent macros.  These are considered internal --- use the
137  * external macros below instead of using these directly.
138  *
139  * Note: IS_1B is true for external toast records but VARSIZE_1B will return 0
140  * for such records. Hence you should usually check for IS_EXTERNAL before
141  * checking for IS_1B.
142  */
143
144 #ifdef WORDS_BIGENDIAN
145
146 #define VARATT_IS_4B(PTR) \
147         ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
148 #define VARATT_IS_4B_U(PTR) \
149         ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
150 #define VARATT_IS_4B_C(PTR) \
151         ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
152 #define VARATT_IS_1B(PTR) \
153         ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
154 #define VARATT_IS_1B_E(PTR) \
155         ((((varattrib_1b *) (PTR))->va_header) == 0x80)
156 #define VARATT_NOT_PAD_BYTE(PTR) \
157         (*((uint8 *) (PTR)) != 0)
158
159 /* VARSIZE_4B() should only be used on known-aligned data */
160 #define VARSIZE_4B(PTR) \
161         (((varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
162 #define VARSIZE_1B(PTR) \
163         (((varattrib_1b *) (PTR))->va_header & 0x7F)
164 /* Currently there is only one size of toast pointer, but someday maybe not */
165 #define VARSIZE_1B_E(PTR) \
166         (sizeof(varattrib_pointer))
167
168 #define SET_VARSIZE_4B(PTR,len) \
169         (((varattrib_4b *) (PTR))->va_4byte.va_header = (len) & 0x3FFFFFFF)
170 #define SET_VARSIZE_4B_C(PTR,len) \
171         (((varattrib_4b *) (PTR))->va_4byte.va_header = ((len) & 0x3FFFFFFF) | 0x40000000)
172 #define SET_VARSIZE_1B(PTR,len) \
173         (((varattrib_1b *) (PTR))->va_header = (len) | 0x80)
174 #define SET_VARSIZE_1B_E(PTR) \
175         (((varattrib_1b *) (PTR))->va_header = 0x80)
176
177 #else  /* !WORDS_BIGENDIAN */
178
179 #define VARATT_IS_4B(PTR) \
180         ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
181 #define VARATT_IS_4B_U(PTR) \
182         ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
183 #define VARATT_IS_4B_C(PTR) \
184         ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
185 #define VARATT_IS_1B(PTR) \
186         ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
187 #define VARATT_IS_1B_E(PTR) \
188         ((((varattrib_1b *) (PTR))->va_header) == 0x01)
189 #define VARATT_NOT_PAD_BYTE(PTR) \
190         (*((uint8 *) (PTR)) != 0)
191
192 /* VARSIZE_4B() should only be used on known-aligned data */
193 #define VARSIZE_4B(PTR) \
194         ((((varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
195 #define VARSIZE_1B(PTR) \
196         ((((varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
197 /* Currently there is only one size of toast pointer, but someday maybe not */
198 #define VARSIZE_1B_E(PTR) \
199         (sizeof(varattrib_pointer))
200
201 #define SET_VARSIZE_4B(PTR,len) \
202         (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2))
203 #define SET_VARSIZE_4B_C(PTR,len) \
204         (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2) | 0x02)
205 #define SET_VARSIZE_1B(PTR,len) \
206         (((varattrib_1b *) (PTR))->va_header = (((uint8) (len)) << 1) | 0x01)
207 #define SET_VARSIZE_1B_E(PTR) \
208         (((varattrib_1b *) (PTR))->va_header = 0x01)
209
210 #endif /* WORDS_BIGENDIAN */
211
212 #define VARHDRSZ_SHORT                  1
213 #define VARATT_SHORT_MAX                0x7F
214 #define VARATT_CAN_MAKE_SHORT(PTR) \
215         (VARATT_IS_4B_U(PTR) && \
216          (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX)
217 #define VARATT_CONVERTED_SHORT_SIZE(PTR) \
218         (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT)
219
220 #define VARDATA_4B(PTR)         (((varattrib_4b *) (PTR))->va_4byte.va_data)
221 #define VARDATA_4B_C(PTR)       (((varattrib_4b *) (PTR))->va_compressed.va_data)
222 #define VARDATA_1B(PTR)         (((varattrib_1b *) (PTR))->va_data)
223
224 #define VARRAWSIZE_4B_C(PTR) \
225         (((varattrib_4b *) (PTR))->va_compressed.va_rawsize)
226
227 /* Externally visible macros */
228
229 /*
230  * VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code
231  * for varlena datatypes.  Note that they only work on untoasted,
232  * 4-byte-header Datums!
233  *
234  * Code that wants to use 1-byte-header values without detoasting should
235  * use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY.  The other macros here
236  * should usually be used only by tuple assembly/disassembly code and
237  * code that specifically wants to work with still-toasted Datums.
238  *
239  * WARNING: It is only safe to use VARDATA_ANY() -- typically with
240  * PG_DETOAST_DATUM_UNPACKED() -- if you really don't care about the alignment.
241  * Either because you're working with something like text where the alignment
242  * doesn't matter or because you're not going to access its constituent parts
243  * and just use things like memcpy on it anyways.
244  */
245 #define VARDATA(PTR)                                            VARDATA_4B(PTR)
246 #define VARSIZE(PTR)                                            VARSIZE_4B(PTR)
247
248 #define VARSIZE_SHORT(PTR)                                      VARSIZE_1B(PTR)
249 #define VARDATA_SHORT(PTR)                                      VARDATA_1B(PTR)
250
251 #define VARSIZE_EXTERNAL(PTR)                           VARSIZE_1B_E(PTR)
252
253 #define VARATT_IS_COMPRESSED(PTR)                       VARATT_IS_4B_C(PTR)
254 #define VARATT_IS_EXTERNAL(PTR)                         VARATT_IS_1B_E(PTR)
255 #define VARATT_IS_SHORT(PTR)                            VARATT_IS_1B(PTR)
256 #define VARATT_IS_EXTENDED(PTR)                         (!VARATT_IS_4B_U(PTR))
257
258 #define SET_VARSIZE(PTR, len)                           SET_VARSIZE_4B(PTR, len)
259 #define SET_VARSIZE_SHORT(PTR, len)                     SET_VARSIZE_1B(PTR, len)
260 #define SET_VARSIZE_COMPRESSED(PTR, len)        SET_VARSIZE_4B_C(PTR, len)
261 #define SET_VARSIZE_EXTERNAL(PTR)                       SET_VARSIZE_1B_E(PTR)
262
263 #define VARSIZE_ANY(PTR) \
264         (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR) : \
265          (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : \
266           VARSIZE_4B(PTR)))
267
268 #define VARSIZE_ANY_EXHDR(PTR) \
269         (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-1 : \
270          (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-1 : \
271           VARSIZE_4B(PTR)-4))
272
273 /* caution: this will not work on an external or compressed-in-line Datum */
274 /* caution: this will return a possibly unaligned pointer */
275 #define VARDATA_ANY(PTR) \
276          (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
277
278
279 /* ----------------------------------------------------------------
280  *                              Section 2:      datum type + support macros
281  * ----------------------------------------------------------------
282  */
283
284 /*
285  * Port Notes:
286  *      Postgres makes the following assumption about machines:
287  *
288  *      sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
289  *
290  *      Postgres also assumes that
291  *
292  *      sizeof(char) == 1
293  *
294  *      and that
295  *
296  *      sizeof(short) == 2
297  *
298  * When a type narrower than Datum is stored in a Datum, we place it in the
299  * low-order bits and are careful that the DatumGetXXX macro for it discards
300  * the unused high-order bits (as opposed to, say, assuming they are zero).
301  * This is needed to support old-style user-defined functions, since depending
302  * on architecture and compiler, the return value of a function returning char
303  * or short may contain garbage when called as if it returned Datum.
304  */
305
306 typedef unsigned long Datum;    /* XXX sizeof(long) >= sizeof(void *) */
307
308 #define SIZEOF_DATUM SIZEOF_UNSIGNED_LONG
309
310 typedef Datum *DatumPtr;
311
312 #define GET_1_BYTE(datum)       (((Datum) (datum)) & 0x000000ff)
313 #define GET_2_BYTES(datum)      (((Datum) (datum)) & 0x0000ffff)
314 #define GET_4_BYTES(datum)      (((Datum) (datum)) & 0xffffffff)
315 #define SET_1_BYTE(value)       (((Datum) (value)) & 0x000000ff)
316 #define SET_2_BYTES(value)      (((Datum) (value)) & 0x0000ffff)
317 #define SET_4_BYTES(value)      (((Datum) (value)) & 0xffffffff)
318
319 /*
320  * DatumGetBool
321  *              Returns boolean value of a datum.
322  *
323  * Note: any nonzero value will be considered TRUE, but we ignore bits to
324  * the left of the width of bool, per comment above.
325  */
326
327 #define DatumGetBool(X) ((bool) (((bool) (X)) != 0))
328
329 /*
330  * BoolGetDatum
331  *              Returns datum representation for a boolean.
332  *
333  * Note: any nonzero value will be considered TRUE.
334  */
335
336 #define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
337
338 /*
339  * DatumGetChar
340  *              Returns character value of a datum.
341  */
342
343 #define DatumGetChar(X) ((char) GET_1_BYTE(X))
344
345 /*
346  * CharGetDatum
347  *              Returns datum representation for a character.
348  */
349
350 #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
351
352 /*
353  * Int8GetDatum
354  *              Returns datum representation for an 8-bit integer.
355  */
356
357 #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
358
359 /*
360  * DatumGetUInt8
361  *              Returns 8-bit unsigned integer value of a datum.
362  */
363
364 #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
365
366 /*
367  * UInt8GetDatum
368  *              Returns datum representation for an 8-bit unsigned integer.
369  */
370
371 #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
372
373 /*
374  * DatumGetInt16
375  *              Returns 16-bit integer value of a datum.
376  */
377
378 #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
379
380 /*
381  * Int16GetDatum
382  *              Returns datum representation for a 16-bit integer.
383  */
384
385 #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
386
387 /*
388  * DatumGetUInt16
389  *              Returns 16-bit unsigned integer value of a datum.
390  */
391
392 #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
393
394 /*
395  * UInt16GetDatum
396  *              Returns datum representation for a 16-bit unsigned integer.
397  */
398
399 #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
400
401 /*
402  * DatumGetInt32
403  *              Returns 32-bit integer value of a datum.
404  */
405
406 #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
407
408 /*
409  * Int32GetDatum
410  *              Returns datum representation for a 32-bit integer.
411  */
412
413 #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
414
415 /*
416  * DatumGetUInt32
417  *              Returns 32-bit unsigned integer value of a datum.
418  */
419
420 #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
421
422 /*
423  * UInt32GetDatum
424  *              Returns datum representation for a 32-bit unsigned integer.
425  */
426
427 #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
428
429 /*
430  * DatumGetObjectId
431  *              Returns object identifier value of a datum.
432  */
433
434 #define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
435
436 /*
437  * ObjectIdGetDatum
438  *              Returns datum representation for an object identifier.
439  */
440
441 #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
442
443 /*
444  * DatumGetTransactionId
445  *              Returns transaction identifier value of a datum.
446  */
447
448 #define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X))
449
450 /*
451  * TransactionIdGetDatum
452  *              Returns datum representation for a transaction identifier.
453  */
454
455 #define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
456
457 /*
458  * DatumGetCommandId
459  *              Returns command identifier value of a datum.
460  */
461
462 #define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X))
463
464 /*
465  * CommandIdGetDatum
466  *              Returns datum representation for a command identifier.
467  */
468
469 #define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X))
470
471 /*
472  * DatumGetPointer
473  *              Returns pointer value of a datum.
474  */
475
476 #define DatumGetPointer(X) ((Pointer) (X))
477
478 /*
479  * PointerGetDatum
480  *              Returns datum representation for a pointer.
481  */
482
483 #define PointerGetDatum(X) ((Datum) (X))
484
485 /*
486  * DatumGetCString
487  *              Returns C string (null-terminated string) value of a datum.
488  *
489  * Note: C string is not a full-fledged Postgres type at present,
490  * but type input functions use this conversion for their inputs.
491  */
492
493 #define DatumGetCString(X) ((char *) DatumGetPointer(X))
494
495 /*
496  * CStringGetDatum
497  *              Returns datum representation for a C string (null-terminated string).
498  *
499  * Note: C string is not a full-fledged Postgres type at present,
500  * but type output functions use this conversion for their outputs.
501  * Note: CString is pass-by-reference; caller must ensure the pointed-to
502  * value has adequate lifetime.
503  */
504
505 #define CStringGetDatum(X) PointerGetDatum(X)
506
507 /*
508  * DatumGetName
509  *              Returns name value of a datum.
510  */
511
512 #define DatumGetName(X) ((Name) DatumGetPointer(X))
513
514 /*
515  * NameGetDatum
516  *              Returns datum representation for a name.
517  *
518  * Note: Name is pass-by-reference; caller must ensure the pointed-to
519  * value has adequate lifetime.
520  */
521
522 #define NameGetDatum(X) PointerGetDatum(X)
523
524 /*
525  * DatumGetInt64
526  *              Returns 64-bit integer value of a datum.
527  *
528  * Note: this macro hides the fact that int64 is currently a
529  * pass-by-reference type.      Someday it may be pass-by-value,
530  * at least on some platforms.
531  */
532
533 #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
534
535 /*
536  * Int64GetDatum
537  *              Returns datum representation for a 64-bit integer.
538  *
539  * Note: this routine returns a reference to palloc'd space.
540  */
541
542 extern Datum Int64GetDatum(int64 X);
543
544 /*
545  * DatumGetFloat4
546  *              Returns 4-byte floating point value of a datum.
547  *
548  * Note: this macro hides the fact that float4 is currently a
549  * pass-by-reference type.      Someday it may be pass-by-value.
550  */
551
552 #define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
553
554 /*
555  * Float4GetDatum
556  *              Returns datum representation for a 4-byte floating point number.
557  *
558  * Note: this routine returns a reference to palloc'd space.
559  */
560
561 extern Datum Float4GetDatum(float4 X);
562
563 /*
564  * DatumGetFloat8
565  *              Returns 8-byte floating point value of a datum.
566  *
567  * Note: this macro hides the fact that float8 is currently a
568  * pass-by-reference type.      Someday it may be pass-by-value,
569  * at least on some platforms.
570  */
571
572 #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
573
574 /*
575  * Float8GetDatum
576  *              Returns datum representation for an 8-byte floating point number.
577  *
578  * Note: this routine returns a reference to palloc'd space.
579  */
580
581 extern Datum Float8GetDatum(float8 X);
582
583
584 /*
585  * DatumGetFloat32
586  *              Returns 32-bit floating point value of a datum.
587  *              This is really a pointer, of course.
588  *
589  * XXX: this macro is now deprecated in favor of DatumGetFloat4.
590  * It will eventually go away.
591  */
592
593 #define DatumGetFloat32(X) ((float32) DatumGetPointer(X))
594
595 /*
596  * Float32GetDatum
597  *              Returns datum representation for a 32-bit floating point number.
598  *              This is really a pointer, of course.
599  *
600  * XXX: this macro is now deprecated in favor of Float4GetDatum.
601  * It will eventually go away.
602  */
603
604 #define Float32GetDatum(X) PointerGetDatum(X)
605
606 /*
607  * DatumGetFloat64
608  *              Returns 64-bit floating point value of a datum.
609  *              This is really a pointer, of course.
610  *
611  * XXX: this macro is now deprecated in favor of DatumGetFloat8.
612  * It will eventually go away.
613  */
614
615 #define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
616
617 /*
618  * Float64GetDatum
619  *              Returns datum representation for a 64-bit floating point number.
620  *              This is really a pointer, of course.
621  *
622  * XXX: this macro is now deprecated in favor of Float8GetDatum.
623  * It will eventually go away.
624  */
625
626 #define Float64GetDatum(X) PointerGetDatum(X)
627
628 /*
629  * Int64GetDatumFast
630  * Float4GetDatumFast
631  * Float8GetDatumFast
632  *
633  * These macros are intended to allow writing code that does not depend on
634  * whether int64, float4, float8 are pass-by-reference types, while not
635  * sacrificing performance when they are.  The argument must be a variable
636  * that will exist and have the same value for as long as the Datum is needed.
637  * In the pass-by-ref case, the address of the variable is taken to use as
638  * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
639  * macros.
640  */
641
642 #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
643 #define Float4GetDatumFast(X) PointerGetDatum(&(X))
644 #define Float8GetDatumFast(X) PointerGetDatum(&(X))
645
646
647 /* ----------------------------------------------------------------
648  *                              Section 3:      exception handling definitions
649  *                                                      Assert, Trap, etc macros
650  * ----------------------------------------------------------------
651  */
652
653 extern PGDLLIMPORT bool assert_enabled;
654
655 /*
656  * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
657  * - plai  9/5/90
658  *
659  * It should _NOT_ be defined in releases or in benchmark copies
660  */
661
662 /*
663  * Trap
664  *              Generates an exception if the given condition is true.
665  */
666 #define Trap(condition, errorType) \
667         do { \
668                 if ((assert_enabled) && (condition)) \
669                         ExceptionalCondition(CppAsString(condition), (errorType), \
670                                                                  __FILE__, __LINE__); \
671         } while (0)
672
673 /*
674  *      TrapMacro is the same as Trap but it's intended for use in macros:
675  *
676  *              #define foo(x) (AssertMacro(x != 0) && bar(x))
677  *
678  *      Isn't CPP fun?
679  */
680 #define TrapMacro(condition, errorType) \
681         ((bool) ((! assert_enabled) || ! (condition) || \
682                          (ExceptionalCondition(CppAsString(condition), (errorType), \
683                                                                    __FILE__, __LINE__))))
684
685 #ifndef USE_ASSERT_CHECKING
686 #define Assert(condition)
687 #define AssertMacro(condition)  ((void)true)
688 #define AssertArg(condition)
689 #define AssertState(condition)
690 #else
691 #define Assert(condition) \
692                 Trap(!(condition), "FailedAssertion")
693
694 #define AssertMacro(condition) \
695                 ((void) TrapMacro(!(condition), "FailedAssertion"))
696
697 #define AssertArg(condition) \
698                 Trap(!(condition), "BadArgument")
699
700 #define AssertState(condition) \
701                 Trap(!(condition), "BadState")
702 #endif   /* USE_ASSERT_CHECKING */
703
704 extern int ExceptionalCondition(const char *conditionName,
705                                                                 const char *errorType,
706                                                                 const char *fileName, int lineNumber);
707
708 /* ----------------------------------------------------------------
709  *                              Section 4: genbki macros used by catalog/pg_xxx.h files
710  * ----------------------------------------------------------------
711  */
712 #define CATALOG(name,oid)       typedef struct CppConcat(FormData_,name)
713
714 #define BKI_BOOTSTRAP
715 #define BKI_SHARED_RELATION
716 #define BKI_WITHOUT_OIDS
717
718 /* these need to expand into some harmless, repeatable declaration */
719 #define DATA(x)   extern int no_such_variable
720 #define DESCR(x)  extern int no_such_variable
721 #define SHDESCR(x) extern int no_such_variable
722
723 typedef int4 aclitem;                   /* PHONY definition for catalog use only */
724
725 #endif   /* POSTGRES_H */