Header And Logo

PostgreSQL
| The world's most advanced open source database.

postgres.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * postgres.h
00004  *    Primary include file for PostgreSQL server .c files
00005  *
00006  * This should be the first file included by PostgreSQL backend modules.
00007  * Client-side code should include postgres_fe.h instead.
00008  *
00009  *
00010  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
00011  * Portions Copyright (c) 1995, Regents of the University of California
00012  *
00013  * $PostgreSQL: pgsql/src/include/postgres.h,v 1.91 2008/04/21 00:26:46 tgl Exp $
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 /*
00018  *----------------------------------------------------------------
00019  *   TABLE OF CONTENTS
00020  *
00021  *      When adding stuff to this file, please try to put stuff
00022  *      into the relevant section, or add new sections as appropriate.
00023  *
00024  *    section   description
00025  *    -------   ------------------------------------------------
00026  *      1)      variable-length datatypes (TOAST support)
00027  *      2)      datum type + support macros
00028  *      3)      exception handling definitions
00029  *
00030  *   NOTES
00031  *
00032  *  In general, this file should contain declarations that are widely needed
00033  *  in the backend environment, but are of no interest outside the backend.
00034  *
00035  *  Simple type definitions live in c.h, where they are shared with
00036  *  postgres_fe.h.  We do that since those type definitions are needed by
00037  *  frontend modules that want to deal with binary data transmission to or
00038  *  from the backend.  Type definitions in this file should be for
00039  *  representations that never escape the backend, such as Datum or
00040  *  TOASTed varlena objects.
00041  *
00042  *----------------------------------------------------------------
00043  */
00044 #ifndef POSTGRES_H
00045 #define POSTGRES_H
00046 
00047 #include "c.h"
00048 #include "utils/elog.h"
00049 #include "utils/palloc.h"
00050 
00051 /* ----------------------------------------------------------------
00052  *              Section 1:  variable-length datatypes (TOAST support)
00053  * ----------------------------------------------------------------
00054  */
00055 
00056 /*
00057  * struct varatt_external is a "TOAST pointer", that is, the information
00058  * needed to fetch a stored-out-of-line Datum.  The data is compressed
00059  * if and only if va_extsize < va_rawsize - VARHDRSZ.  This struct must not
00060  * contain any padding, because we sometimes compare pointers using memcmp.
00061  *
00062  * Note that this information is stored unaligned within actual tuples, so
00063  * you need to memcpy from the tuple into a local struct variable before
00064  * you can look at these fields!  (The reason we use memcmp is to avoid
00065  * having to do that just to detect equality of two TOAST pointers...)
00066  */
00067 struct varatt_external
00068 {
00069     int32       va_rawsize;     /* Original data size (includes header) */
00070     int32       va_extsize;     /* External saved size (doesn't) */
00071     Oid         va_valueid;     /* Unique ID of value within TOAST table */
00072     Oid         va_toastrelid;  /* RelID of TOAST table containing it */
00073 };
00074 
00075 /*
00076  * These structs describe the header of a varlena object that may have been
00077  * TOASTed.  Generally, don't reference these structs directly, but use the
00078  * macros below.
00079  *
00080  * We use separate structs for the aligned and unaligned cases because the
00081  * compiler might otherwise think it could generate code that assumes
00082  * alignment while touching fields of a 1-byte-header varlena.
00083  */
00084 typedef union
00085 {
00086     struct                      /* Normal varlena (4-byte length) */
00087     {
00088         uint32      va_header;
00089         char        va_data[1];
00090     }           va_4byte;
00091     struct                      /* Compressed-in-line format */
00092     {
00093         uint32      va_header;
00094         uint32      va_rawsize; /* Original data size (excludes header) */
00095         char        va_data[1]; /* Compressed data */
00096     }           va_compressed;
00097 } varattrib_4b;
00098 
00099 typedef struct
00100 {
00101     uint8       va_header;
00102     char        va_data[1];     /* Data begins here */
00103 } varattrib_1b;
00104 
00105 typedef struct
00106 {
00107     uint8       va_header;      /* Always 0x80 or 0x01 */
00108     uint8       va_len_1be;     /* Physical length of datum */
00109     char        va_data[1];     /* Data (for now always a TOAST pointer) */
00110 } varattrib_1b_e;
00111 
00112 /*
00113  * Bit layouts for varlena headers on big-endian machines:
00114  *
00115  * 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G)
00116  * 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G)
00117  * 10000000 1-byte length word, unaligned, TOAST pointer
00118  * 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b)
00119  *
00120  * Bit layouts for varlena headers on little-endian machines:
00121  *
00122  * xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G)
00123  * xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G)
00124  * 00000001 1-byte length word, unaligned, TOAST pointer
00125  * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b)
00126  *
00127  * The "xxx" bits are the length field (which includes itself in all cases).
00128  * In the big-endian case we mask to extract the length, in the little-endian
00129  * case we shift.  Note that in both cases the flag bits are in the physically
00130  * first byte.  Also, it is not possible for a 1-byte length word to be zero;
00131  * this lets us disambiguate alignment padding bytes from the start of an
00132  * unaligned datum.  (We now *require* pad bytes to be filled with zero!)
00133  */
00134 
00135 /*
00136  * Endian-dependent macros.  These are considered internal --- use the
00137  * external macros below instead of using these directly.
00138  *
00139  * Note: IS_1B is true for external toast records but VARSIZE_1B will return 0
00140  * for such records. Hence you should usually check for IS_EXTERNAL before
00141  * checking for IS_1B.
00142  */
00143 
00144 #ifdef WORDS_BIGENDIAN
00145 
00146 #define VARATT_IS_4B(PTR) \
00147     ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
00148 #define VARATT_IS_4B_U(PTR) \
00149     ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
00150 #define VARATT_IS_4B_C(PTR) \
00151     ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
00152 #define VARATT_IS_1B(PTR) \
00153     ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
00154 #define VARATT_IS_1B_E(PTR) \
00155     ((((varattrib_1b *) (PTR))->va_header) == 0x80)
00156 #define VARATT_NOT_PAD_BYTE(PTR) \
00157     (*((uint8 *) (PTR)) != 0)
00158 
00159 /* VARSIZE_4B() should only be used on known-aligned data */
00160 #define VARSIZE_4B(PTR) \
00161     (((varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
00162 #define VARSIZE_1B(PTR) \
00163     (((varattrib_1b *) (PTR))->va_header & 0x7F)
00164 #define VARSIZE_1B_E(PTR) \
00165     (((varattrib_1b_e *) (PTR))->va_len_1be)
00166 
00167 #define SET_VARSIZE_4B(PTR,len) \
00168     (((varattrib_4b *) (PTR))->va_4byte.va_header = (len) & 0x3FFFFFFF)
00169 #define SET_VARSIZE_4B_C(PTR,len) \
00170     (((varattrib_4b *) (PTR))->va_4byte.va_header = ((len) & 0x3FFFFFFF) | 0x40000000)
00171 #define SET_VARSIZE_1B(PTR,len) \
00172     (((varattrib_1b *) (PTR))->va_header = (len) | 0x80)
00173 #define SET_VARSIZE_1B_E(PTR,len) \
00174     (((varattrib_1b_e *) (PTR))->va_header = 0x80, \
00175      ((varattrib_1b_e *) (PTR))->va_len_1be = (len))
00176 #else                           /* !WORDS_BIGENDIAN */
00177 
00178 #define VARATT_IS_4B(PTR) \
00179     ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
00180 #define VARATT_IS_4B_U(PTR) \
00181     ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
00182 #define VARATT_IS_4B_C(PTR) \
00183     ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
00184 #define VARATT_IS_1B(PTR) \
00185     ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
00186 #define VARATT_IS_1B_E(PTR) \
00187     ((((varattrib_1b *) (PTR))->va_header) == 0x01)
00188 #define VARATT_NOT_PAD_BYTE(PTR) \
00189     (*((uint8 *) (PTR)) != 0)
00190 
00191 /* VARSIZE_4B() should only be used on known-aligned data */
00192 #define VARSIZE_4B(PTR) \
00193     ((((varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
00194 #define VARSIZE_1B(PTR) \
00195     ((((varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
00196 #define VARSIZE_1B_E(PTR) \
00197     (((varattrib_1b_e *) (PTR))->va_len_1be)
00198 
00199 #define SET_VARSIZE_4B(PTR,len) \
00200     (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2))
00201 #define SET_VARSIZE_4B_C(PTR,len) \
00202     (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2) | 0x02)
00203 #define SET_VARSIZE_1B(PTR,len) \
00204     (((varattrib_1b *) (PTR))->va_header = (((uint8) (len)) << 1) | 0x01)
00205 #define SET_VARSIZE_1B_E(PTR,len) \
00206     (((varattrib_1b_e *) (PTR))->va_header = 0x01, \
00207      ((varattrib_1b_e *) (PTR))->va_len_1be = (len))
00208 #endif   /* WORDS_BIGENDIAN */
00209 
00210 #define VARHDRSZ_SHORT          1
00211 #define VARATT_SHORT_MAX        0x7F
00212 #define VARATT_CAN_MAKE_SHORT(PTR) \
00213     (VARATT_IS_4B_U(PTR) && \
00214      (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX)
00215 #define VARATT_CONVERTED_SHORT_SIZE(PTR) \
00216     (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT)
00217 
00218 #define VARHDRSZ_EXTERNAL       2
00219 
00220 #define VARDATA_4B(PTR)     (((varattrib_4b *) (PTR))->va_4byte.va_data)
00221 #define VARDATA_4B_C(PTR)   (((varattrib_4b *) (PTR))->va_compressed.va_data)
00222 #define VARDATA_1B(PTR)     (((varattrib_1b *) (PTR))->va_data)
00223 #define VARDATA_1B_E(PTR)   (((varattrib_1b_e *) (PTR))->va_data)
00224 
00225 #define VARRAWSIZE_4B_C(PTR) \
00226     (((varattrib_4b *) (PTR))->va_compressed.va_rawsize)
00227 
00228 /* Externally visible macros */
00229 
00230 /*
00231  * VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code
00232  * for varlena datatypes.  Note that they only work on untoasted,
00233  * 4-byte-header Datums!
00234  *
00235  * Code that wants to use 1-byte-header values without detoasting should
00236  * use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY.  The other macros here
00237  * should usually be used only by tuple assembly/disassembly code and
00238  * code that specifically wants to work with still-toasted Datums.
00239  *
00240  * WARNING: It is only safe to use VARDATA_ANY() -- typically with
00241  * PG_DETOAST_DATUM_PACKED() -- if you really don't care about the alignment.
00242  * Either because you're working with something like text where the alignment
00243  * doesn't matter or because you're not going to access its constituent parts
00244  * and just use things like memcpy on it anyways.
00245  */
00246 #define VARDATA(PTR)                        VARDATA_4B(PTR)
00247 #define VARSIZE(PTR)                        VARSIZE_4B(PTR)
00248 
00249 #define VARSIZE_SHORT(PTR)                  VARSIZE_1B(PTR)
00250 #define VARDATA_SHORT(PTR)                  VARDATA_1B(PTR)
00251 
00252 #define VARSIZE_EXTERNAL(PTR)               VARSIZE_1B_E(PTR)
00253 #define VARDATA_EXTERNAL(PTR)               VARDATA_1B_E(PTR)
00254 
00255 #define VARATT_IS_COMPRESSED(PTR)           VARATT_IS_4B_C(PTR)
00256 #define VARATT_IS_EXTERNAL(PTR)             VARATT_IS_1B_E(PTR)
00257 #define VARATT_IS_SHORT(PTR)                VARATT_IS_1B(PTR)
00258 #define VARATT_IS_EXTENDED(PTR)             (!VARATT_IS_4B_U(PTR))
00259 
00260 #define SET_VARSIZE(PTR, len)               SET_VARSIZE_4B(PTR, len)
00261 #define SET_VARSIZE_SHORT(PTR, len)         SET_VARSIZE_1B(PTR, len)
00262 #define SET_VARSIZE_COMPRESSED(PTR, len)    SET_VARSIZE_4B_C(PTR, len)
00263 #define SET_VARSIZE_EXTERNAL(PTR, len)      SET_VARSIZE_1B_E(PTR, len)
00264 
00265 #define VARSIZE_ANY(PTR) \
00266     (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR) : \
00267      (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : \
00268       VARSIZE_4B(PTR)))
00269 
00270 #define VARSIZE_ANY_EXHDR(PTR) \
00271     (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-VARHDRSZ_EXTERNAL : \
00272      (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-VARHDRSZ_SHORT : \
00273       VARSIZE_4B(PTR)-VARHDRSZ))
00274 
00275 /* caution: this will not work on an external or compressed-in-line Datum */
00276 /* caution: this will return a possibly unaligned pointer */
00277 #define VARDATA_ANY(PTR) \
00278      (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
00279 
00280 
00281 /* ----------------------------------------------------------------
00282  *              Section 2:  datum type + support macros
00283  * ----------------------------------------------------------------
00284  */
00285 
00286 /*
00287  * Port Notes:
00288  *  Postgres makes the following assumption about machines:
00289  *
00290  *  sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
00291  *
00292  *  Postgres also assumes that
00293  *
00294  *  sizeof(char) == 1
00295  *
00296  *  and that
00297  *
00298  *  sizeof(short) == 2
00299  *
00300  * When a type narrower than Datum is stored in a Datum, we place it in the
00301  * low-order bits and are careful that the DatumGetXXX macro for it discards
00302  * the unused high-order bits (as opposed to, say, assuming they are zero).
00303  * This is needed to support old-style user-defined functions, since depending
00304  * on architecture and compiler, the return value of a function returning char
00305  * or short may contain garbage when called as if it returned Datum.
00306  */
00307 
00308 typedef unsigned long Datum;    /* XXX sizeof(long) >= sizeof(void *) */
00309 
00310 #define SIZEOF_DATUM SIZEOF_UNSIGNED_LONG
00311 
00312 typedef Datum *DatumPtr;
00313 
00314 #define GET_1_BYTE(datum)   (((Datum) (datum)) & 0x000000ff)
00315 #define GET_2_BYTES(datum)  (((Datum) (datum)) & 0x0000ffff)
00316 #define GET_4_BYTES(datum)  (((Datum) (datum)) & 0xffffffff)
00317 #if SIZEOF_DATUM == 8
00318 #define GET_8_BYTES(datum)  ((Datum) (datum))
00319 #endif
00320 #define SET_1_BYTE(value)   (((Datum) (value)) & 0x000000ff)
00321 #define SET_2_BYTES(value)  (((Datum) (value)) & 0x0000ffff)
00322 #define SET_4_BYTES(value)  (((Datum) (value)) & 0xffffffff)
00323 #if SIZEOF_DATUM == 8
00324 #define SET_8_BYTES(value)  ((Datum) (value))
00325 #endif
00326 
00327 /*
00328  * DatumGetBool
00329  *      Returns boolean value of a datum.
00330  *
00331  * Note: any nonzero value will be considered TRUE, but we ignore bits to
00332  * the left of the width of bool, per comment above.
00333  */
00334 
00335 #define DatumGetBool(X) ((bool) (((bool) (X)) != 0))
00336 
00337 /*
00338  * BoolGetDatum
00339  *      Returns datum representation for a boolean.
00340  *
00341  * Note: any nonzero value will be considered TRUE.
00342  */
00343 
00344 #define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
00345 
00346 /*
00347  * DatumGetChar
00348  *      Returns character value of a datum.
00349  */
00350 
00351 #define DatumGetChar(X) ((char) GET_1_BYTE(X))
00352 
00353 /*
00354  * CharGetDatum
00355  *      Returns datum representation for a character.
00356  */
00357 
00358 #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
00359 
00360 /*
00361  * Int8GetDatum
00362  *      Returns datum representation for an 8-bit integer.
00363  */
00364 
00365 #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
00366 
00367 /*
00368  * DatumGetUInt8
00369  *      Returns 8-bit unsigned integer value of a datum.
00370  */
00371 
00372 #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
00373 
00374 /*
00375  * UInt8GetDatum
00376  *      Returns datum representation for an 8-bit unsigned integer.
00377  */
00378 
00379 #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
00380 
00381 /*
00382  * DatumGetInt16
00383  *      Returns 16-bit integer value of a datum.
00384  */
00385 
00386 #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
00387 
00388 /*
00389  * Int16GetDatum
00390  *      Returns datum representation for a 16-bit integer.
00391  */
00392 
00393 #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
00394 
00395 /*
00396  * DatumGetUInt16
00397  *      Returns 16-bit unsigned integer value of a datum.
00398  */
00399 
00400 #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
00401 
00402 /*
00403  * UInt16GetDatum
00404  *      Returns datum representation for a 16-bit unsigned integer.
00405  */
00406 
00407 #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
00408 
00409 /*
00410  * DatumGetInt32
00411  *      Returns 32-bit integer value of a datum.
00412  */
00413 
00414 #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
00415 
00416 /*
00417  * Int32GetDatum
00418  *      Returns datum representation for a 32-bit integer.
00419  */
00420 
00421 #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
00422 
00423 /*
00424  * DatumGetUInt32
00425  *      Returns 32-bit unsigned integer value of a datum.
00426  */
00427 
00428 #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
00429 
00430 /*
00431  * UInt32GetDatum
00432  *      Returns datum representation for a 32-bit unsigned integer.
00433  */
00434 
00435 #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
00436 
00437 /*
00438  * DatumGetObjectId
00439  *      Returns object identifier value of a datum.
00440  */
00441 
00442 #define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
00443 
00444 /*
00445  * ObjectIdGetDatum
00446  *      Returns datum representation for an object identifier.
00447  */
00448 
00449 #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00450 
00451 /*
00452  * DatumGetTransactionId
00453  *      Returns transaction identifier value of a datum.
00454  */
00455 
00456 #define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X))
00457 
00458 /*
00459  * TransactionIdGetDatum
00460  *      Returns datum representation for a transaction identifier.
00461  */
00462 
00463 #define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
00464 
00465 /*
00466  * DatumGetCommandId
00467  *      Returns command identifier value of a datum.
00468  */
00469 
00470 #define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X))
00471 
00472 /*
00473  * CommandIdGetDatum
00474  *      Returns datum representation for a command identifier.
00475  */
00476 
00477 #define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00478 
00479 /*
00480  * DatumGetPointer
00481  *      Returns pointer value of a datum.
00482  */
00483 
00484 #define DatumGetPointer(X) ((Pointer) (X))
00485 
00486 /*
00487  * PointerGetDatum
00488  *      Returns datum representation for a pointer.
00489  */
00490 
00491 #define PointerGetDatum(X) ((Datum) (X))
00492 
00493 /*
00494  * DatumGetCString
00495  *      Returns C string (null-terminated string) value of a datum.
00496  *
00497  * Note: C string is not a full-fledged Postgres type at present,
00498  * but type input functions use this conversion for their inputs.
00499  */
00500 
00501 #define DatumGetCString(X) ((char *) DatumGetPointer(X))
00502 
00503 /*
00504  * CStringGetDatum
00505  *      Returns datum representation for a C string (null-terminated string).
00506  *
00507  * Note: C string is not a full-fledged Postgres type at present,
00508  * but type output functions use this conversion for their outputs.
00509  * Note: CString is pass-by-reference; caller must ensure the pointed-to
00510  * value has adequate lifetime.
00511  */
00512 
00513 #define CStringGetDatum(X) PointerGetDatum(X)
00514 
00515 /*
00516  * DatumGetName
00517  *      Returns name value of a datum.
00518  */
00519 
00520 #define DatumGetName(X) ((Name) DatumGetPointer(X))
00521 
00522 /*
00523  * NameGetDatum
00524  *      Returns datum representation for a name.
00525  *
00526  * Note: Name is pass-by-reference; caller must ensure the pointed-to
00527  * value has adequate lifetime.
00528  */
00529 
00530 #define NameGetDatum(X) PointerGetDatum(X)
00531 
00532 /*
00533  * DatumGetInt64
00534  *      Returns 64-bit integer value of a datum.
00535  *
00536  * Note: this macro hides whether int64 is pass by value or by reference.
00537  */
00538 
00539 #ifdef USE_FLOAT8_BYVAL
00540 #define DatumGetInt64(X) ((int64) GET_8_BYTES(X))
00541 #else
00542 #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
00543 #endif
00544 
00545 /*
00546  * Int64GetDatum
00547  *      Returns datum representation for a 64-bit integer.
00548  *
00549  * Note: if int64 is pass by reference, this function returns a reference
00550  * to palloc'd space.
00551  */
00552 
00553 #ifdef USE_FLOAT8_BYVAL
00554 #define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
00555 #else
00556 extern Datum Int64GetDatum(int64 X);
00557 #endif
00558 
00559 /*
00560  * DatumGetFloat4
00561  *      Returns 4-byte floating point value of a datum.
00562  *
00563  * Note: this macro hides whether float4 is pass by value or by reference.
00564  */
00565 
00566 #ifdef USE_FLOAT4_BYVAL
00567 extern float4 DatumGetFloat4(Datum X);
00568 #else
00569 #define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
00570 #endif
00571 
00572 /*
00573  * Float4GetDatum
00574  *      Returns datum representation for a 4-byte floating point number.
00575  *
00576  * Note: if float4 is pass by reference, this function returns a reference
00577  * to palloc'd space.
00578  */
00579 
00580 extern Datum Float4GetDatum(float4 X);
00581 
00582 /*
00583  * DatumGetFloat8
00584  *      Returns 8-byte floating point value of a datum.
00585  *
00586  * Note: this macro hides whether float8 is pass by value or by reference.
00587  */
00588 
00589 #ifdef USE_FLOAT8_BYVAL
00590 extern float8 DatumGetFloat8(Datum X);
00591 #else
00592 #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
00593 #endif
00594 
00595 /*
00596  * Float8GetDatum
00597  *      Returns datum representation for an 8-byte floating point number.
00598  *
00599  * Note: if float8 is pass by reference, this function returns a reference
00600  * to palloc'd space.
00601  */
00602 
00603 extern Datum Float8GetDatum(float8 X);
00604 
00605 
00606 /*
00607  * Int64GetDatumFast
00608  * Float8GetDatumFast
00609  * Float4GetDatumFast
00610  *
00611  * These macros are intended to allow writing code that does not depend on
00612  * whether int64, float8, float4 are pass-by-reference types, while not
00613  * sacrificing performance when they are.  The argument must be a variable
00614  * that will exist and have the same value for as long as the Datum is needed.
00615  * In the pass-by-ref case, the address of the variable is taken to use as
00616  * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
00617  * macros.
00618  */
00619 
00620 #ifdef USE_FLOAT8_BYVAL
00621 #define Int64GetDatumFast(X)  Int64GetDatum(X)
00622 #define Float8GetDatumFast(X) Float8GetDatum(X)
00623 #else
00624 #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
00625 #define Float8GetDatumFast(X) PointerGetDatum(&(X))
00626 #endif
00627 
00628 #ifdef USE_FLOAT4_BYVAL
00629 #define Float4GetDatumFast(X) Float4GetDatum(X)
00630 #else
00631 #define Float4GetDatumFast(X) PointerGetDatum(&(X))
00632 #endif
00633 
00634 
00635 /* ----------------------------------------------------------------
00636  *              Section 3:  exception handling definitions
00637  *                          Assert, Trap, etc macros
00638  * ----------------------------------------------------------------
00639  */
00640 
00641 extern PGDLLIMPORT bool assert_enabled;
00642 
00643 /*
00644  * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
00645  * - plai  9/5/90
00646  *
00647  * It should _NOT_ be defined in releases or in benchmark copies
00648  */
00649 
00650 /*
00651  * Trap
00652  *      Generates an exception if the given condition is true.
00653  */
00654 #define Trap(condition, errorType) \
00655     do { \
00656         if ((assert_enabled) && (condition)) \
00657             ExceptionalCondition(CppAsString(condition), (errorType), \
00658                                  __FILE__, __LINE__); \
00659     } while (0)
00660 
00661 /*
00662  *  TrapMacro is the same as Trap but it's intended for use in macros:
00663  *
00664  *      #define foo(x) (AssertMacro(x != 0) && bar(x))
00665  *
00666  *  Isn't CPP fun?
00667  */
00668 #define TrapMacro(condition, errorType) \
00669     ((bool) ((! assert_enabled) || ! (condition) || \
00670              (ExceptionalCondition(CppAsString(condition), (errorType), \
00671                                    __FILE__, __LINE__))))
00672 
00673 #ifndef USE_ASSERT_CHECKING
00674 #define Assert(condition)
00675 #define AssertMacro(condition)  ((void)true)
00676 #define AssertArg(condition)
00677 #define AssertState(condition)
00678 #else
00679 #define Assert(condition) \
00680         Trap(!(condition), "FailedAssertion")
00681 
00682 #define AssertMacro(condition) \
00683         ((void) TrapMacro(!(condition), "FailedAssertion"))
00684 
00685 #define AssertArg(condition) \
00686         Trap(!(condition), "BadArgument")
00687 
00688 #define AssertState(condition) \
00689         Trap(!(condition), "BadState")
00690 #endif   /* USE_ASSERT_CHECKING */
00691 
00692 extern int ExceptionalCondition(const char *conditionName,
00693                      const char *errorType,
00694                      const char *fileName, int lineNumber);
00695 
00696 #endif   /* POSTGRES_H */

Generated on Thu Nov 20 03:02:32 2008 for PostgreSQL Source Code by  doxygen 1.5.5