2424 * section description
2525 * ------- ------------------------------------------------
2626 * 1) variable-length datatypes (TOAST support)
27- * 2) datum type + support macros
27+ * 2) Datum type + support macros
2828 * 3) exception handling backend support
2929 *
3030 * NOTES
@@ -349,60 +349,38 @@ typedef struct
349349
350350
351351/* ----------------------------------------------------------------
352- * Section 2: datum type + support macros
352+ * Section 2: Datum type + support macros
353353 * ----------------------------------------------------------------
354354 */
355355
356356/*
357- * Port Notes:
358- * Postgres makes the following assumptions about datatype sizes :
357+ * A Datum contains either a value of a pass-by-value type or a pointer to a
358+ * value of a pass-by-reference type. Therefore, we require :
359359 *
360- * sizeof(Datum) == sizeof(void *) == 4 or 8
361- * sizeof(char) == 1
362- * sizeof(short) == 2
360+ * sizeof(Datum) == sizeof(void *) == 4 or 8
363361 *
364- * When a type narrower than Datum is stored in a Datum, we place it in the
365- * low-order bits and are careful that the DatumGetXXX macro for it discards
366- * the unused high-order bits (as opposed to, say, assuming they are zero).
367- * This is needed to support old-style user-defined functions, since depending
368- * on architecture and compiler, the return value of a function returning char
369- * or short may contain garbage when called as if it returned Datum.
362+ * The macros below and the analogous macros for other types should be used to
363+ * convert between a Datum and the appropriate C type.
370364 */
371365
372366typedef uintptr_t Datum ;
373367
374368#define SIZEOF_DATUM SIZEOF_VOID_P
375369
376- typedef Datum * DatumPtr ;
377-
378- #define GET_1_BYTE (datum ) (((Datum) (datum)) & 0x000000ff)
379- #define GET_2_BYTES (datum ) (((Datum) (datum)) & 0x0000ffff)
380- #define GET_4_BYTES (datum ) (((Datum) (datum)) & 0xffffffff)
381- #if SIZEOF_DATUM == 8
382- #define GET_8_BYTES (datum ) ((Datum) (datum))
383- #endif
384- #define SET_1_BYTE (value ) (((Datum) (value)) & 0x000000ff)
385- #define SET_2_BYTES (value ) (((Datum) (value)) & 0x0000ffff)
386- #define SET_4_BYTES (value ) (((Datum) (value)) & 0xffffffff)
387- #if SIZEOF_DATUM == 8
388- #define SET_8_BYTES (value ) ((Datum) (value))
389- #endif
390-
391370/*
392371 * DatumGetBool
393372 * Returns boolean value of a datum.
394373 *
395- * Note: any nonzero value will be considered TRUE, but we ignore bits to
396- * the left of the width of bool, per comment above.
374+ * Note: any nonzero value will be considered true.
397375 */
398376
399- #define DatumGetBool (X ) ((bool) (GET_1_BYTE (X) != 0))
377+ #define DatumGetBool (X ) ((bool) ((X) != 0))
400378
401379/*
402380 * BoolGetDatum
403381 * Returns datum representation for a boolean.
404382 *
405- * Note: any nonzero value will be considered TRUE .
383+ * Note: any nonzero value will be considered true .
406384 */
407385
408386#define BoolGetDatum (X ) ((Datum) ((X) ? 1 : 0))
@@ -412,140 +390,140 @@ typedef Datum *DatumPtr;
412390 * Returns character value of a datum.
413391 */
414392
415- #define DatumGetChar (X ) ((char) GET_1_BYTE (X))
393+ #define DatumGetChar (X ) ((char) (X))
416394
417395/*
418396 * CharGetDatum
419397 * Returns datum representation for a character.
420398 */
421399
422- #define CharGetDatum (X ) ((Datum) SET_1_BYTE (X))
400+ #define CharGetDatum (X ) ((Datum) (X))
423401
424402/*
425403 * Int8GetDatum
426404 * Returns datum representation for an 8-bit integer.
427405 */
428406
429- #define Int8GetDatum (X ) ((Datum) SET_1_BYTE (X))
407+ #define Int8GetDatum (X ) ((Datum) (X))
430408
431409/*
432410 * DatumGetUInt8
433411 * Returns 8-bit unsigned integer value of a datum.
434412 */
435413
436- #define DatumGetUInt8 (X ) ((uint8) GET_1_BYTE (X))
414+ #define DatumGetUInt8 (X ) ((uint8) (X))
437415
438416/*
439417 * UInt8GetDatum
440418 * Returns datum representation for an 8-bit unsigned integer.
441419 */
442420
443- #define UInt8GetDatum (X ) ((Datum) SET_1_BYTE (X))
421+ #define UInt8GetDatum (X ) ((Datum) (X))
444422
445423/*
446424 * DatumGetInt16
447425 * Returns 16-bit integer value of a datum.
448426 */
449427
450- #define DatumGetInt16 (X ) ((int16) GET_2_BYTES (X))
428+ #define DatumGetInt16 (X ) ((int16) (X))
451429
452430/*
453431 * Int16GetDatum
454432 * Returns datum representation for a 16-bit integer.
455433 */
456434
457- #define Int16GetDatum (X ) ((Datum) SET_2_BYTES (X))
435+ #define Int16GetDatum (X ) ((Datum) (X))
458436
459437/*
460438 * DatumGetUInt16
461439 * Returns 16-bit unsigned integer value of a datum.
462440 */
463441
464- #define DatumGetUInt16 (X ) ((uint16) GET_2_BYTES (X))
442+ #define DatumGetUInt16 (X ) ((uint16) (X))
465443
466444/*
467445 * UInt16GetDatum
468446 * Returns datum representation for a 16-bit unsigned integer.
469447 */
470448
471- #define UInt16GetDatum (X ) ((Datum) SET_2_BYTES (X))
449+ #define UInt16GetDatum (X ) ((Datum) (X))
472450
473451/*
474452 * DatumGetInt32
475453 * Returns 32-bit integer value of a datum.
476454 */
477455
478- #define DatumGetInt32 (X ) ((int32) GET_4_BYTES (X))
456+ #define DatumGetInt32 (X ) ((int32) (X))
479457
480458/*
481459 * Int32GetDatum
482460 * Returns datum representation for a 32-bit integer.
483461 */
484462
485- #define Int32GetDatum (X ) ((Datum) SET_4_BYTES (X))
463+ #define Int32GetDatum (X ) ((Datum) (X))
486464
487465/*
488466 * DatumGetUInt32
489467 * Returns 32-bit unsigned integer value of a datum.
490468 */
491469
492- #define DatumGetUInt32 (X ) ((uint32) GET_4_BYTES (X))
470+ #define DatumGetUInt32 (X ) ((uint32) (X))
493471
494472/*
495473 * UInt32GetDatum
496474 * Returns datum representation for a 32-bit unsigned integer.
497475 */
498476
499- #define UInt32GetDatum (X ) ((Datum) SET_4_BYTES (X))
477+ #define UInt32GetDatum (X ) ((Datum) (X))
500478
501479/*
502480 * DatumGetObjectId
503481 * Returns object identifier value of a datum.
504482 */
505483
506- #define DatumGetObjectId (X ) ((Oid) GET_4_BYTES (X))
484+ #define DatumGetObjectId (X ) ((Oid) (X))
507485
508486/*
509487 * ObjectIdGetDatum
510488 * Returns datum representation for an object identifier.
511489 */
512490
513- #define ObjectIdGetDatum (X ) ((Datum) SET_4_BYTES (X))
491+ #define ObjectIdGetDatum (X ) ((Datum) (X))
514492
515493/*
516494 * DatumGetTransactionId
517495 * Returns transaction identifier value of a datum.
518496 */
519497
520- #define DatumGetTransactionId (X ) ((TransactionId) GET_4_BYTES (X))
498+ #define DatumGetTransactionId (X ) ((TransactionId) (X))
521499
522500/*
523501 * TransactionIdGetDatum
524502 * Returns datum representation for a transaction identifier.
525503 */
526504
527- #define TransactionIdGetDatum (X ) ((Datum) SET_4_BYTES((X) ))
505+ #define TransactionIdGetDatum (X ) ((Datum) (X ))
528506
529507/*
530508 * MultiXactIdGetDatum
531509 * Returns datum representation for a multixact identifier.
532510 */
533511
534- #define MultiXactIdGetDatum (X ) ((Datum) SET_4_BYTES((X) ))
512+ #define MultiXactIdGetDatum (X ) ((Datum) (X ))
535513
536514/*
537515 * DatumGetCommandId
538516 * Returns command identifier value of a datum.
539517 */
540518
541- #define DatumGetCommandId (X ) ((CommandId) GET_4_BYTES (X))
519+ #define DatumGetCommandId (X ) ((CommandId) (X))
542520
543521/*
544522 * CommandIdGetDatum
545523 * Returns datum representation for a command identifier.
546524 */
547525
548- #define CommandIdGetDatum (X ) ((Datum) SET_4_BYTES (X))
526+ #define CommandIdGetDatum (X ) ((Datum) (X))
549527
550528/*
551529 * DatumGetPointer
@@ -608,7 +586,7 @@ typedef Datum *DatumPtr;
608586 */
609587
610588#ifdef USE_FLOAT8_BYVAL
611- #define DatumGetInt64 (X ) ((int64) GET_8_BYTES (X))
589+ #define DatumGetInt64 (X ) ((int64) (X))
612590#else
613591#define DatumGetInt64 (X ) (* ((int64 *) DatumGetPointer(X)))
614592#endif
@@ -622,7 +600,7 @@ typedef Datum *DatumPtr;
622600 */
623601
624602#ifdef USE_FLOAT8_BYVAL
625- #define Int64GetDatum (X ) ((Datum) SET_8_BYTES (X))
603+ #define Int64GetDatum (X ) ((Datum) (X))
626604#else
627605extern Datum Int64GetDatum (int64 X );
628606#endif
@@ -635,7 +613,7 @@ extern Datum Int64GetDatum(int64 X);
635613 */
636614
637615#ifdef USE_FLOAT8_BYVAL
638- #define DatumGetUInt64 (X ) ((uint64) GET_8_BYTES (X))
616+ #define DatumGetUInt64 (X ) ((uint64) (X))
639617#else
640618#define DatumGetUInt64 (X ) (* ((uint64 *) DatumGetPointer(X)))
641619#endif
@@ -649,7 +627,7 @@ extern Datum Int64GetDatum(int64 X);
649627 */
650628
651629#ifdef USE_FLOAT8_BYVAL
652- #define UInt64GetDatum (X ) ((Datum) SET_8_BYTES (X))
630+ #define UInt64GetDatum (X ) ((Datum) (X))
653631#else
654632#define UInt64GetDatum (X ) Int64GetDatum((int64) (X))
655633#endif
0 commit comments