Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6ef00b

Browse files
committed
Remove byte-masking macros for Datum conversion macros
As the comment there stated, these were needed for old-styleuser-defined functions, but since we removed support for those, we don'tneed this anymore.Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent6588a43 commita6ef00b

File tree

1 file changed

+34
-56
lines changed

1 file changed

+34
-56
lines changed

‎src/include/postgres.h

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* sectiondescription
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

372366
typedefuintptr_tDatum;
373367

374368
#defineSIZEOF_DATUM SIZEOF_VOID_P
375369

376-
typedefDatum*DatumPtr;
377-
378-
#defineGET_1_BYTE(datum)(((Datum) (datum)) & 0x000000ff)
379-
#defineGET_2_BYTES(datum)(((Datum) (datum)) & 0x0000ffff)
380-
#defineGET_4_BYTES(datum)(((Datum) (datum)) & 0xffffffff)
381-
#ifSIZEOF_DATUM==8
382-
#defineGET_8_BYTES(datum)((Datum) (datum))
383-
#endif
384-
#defineSET_1_BYTE(value)(((Datum) (value)) & 0x000000ff)
385-
#defineSET_2_BYTES(value)(((Datum) (value)) & 0x0000ffff)
386-
#defineSET_4_BYTES(value)(((Datum) (value)) & 0xffffffff)
387-
#ifSIZEOF_DATUM==8
388-
#defineSET_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-
#defineDatumGetBool(X) ((bool) (GET_1_BYTE(X) != 0))
377+
#defineDatumGetBool(X) ((bool) ((X) != 0))
400378

401379
/*
402380
* BoolGetDatum
403381
*Returns datum representation for a boolean.
404382
*
405-
* Note: any nonzero value will be consideredTRUE.
383+
* Note: any nonzero value will be consideredtrue.
406384
*/
407385

408386
#defineBoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
@@ -412,140 +390,140 @@ typedef Datum *DatumPtr;
412390
*Returns character value of a datum.
413391
*/
414392

415-
#defineDatumGetChar(X) ((char)GET_1_BYTE(X))
393+
#defineDatumGetChar(X) ((char) (X))
416394

417395
/*
418396
* CharGetDatum
419397
*Returns datum representation for a character.
420398
*/
421399

422-
#defineCharGetDatum(X) ((Datum)SET_1_BYTE(X))
400+
#defineCharGetDatum(X) ((Datum) (X))
423401

424402
/*
425403
* Int8GetDatum
426404
*Returns datum representation for an 8-bit integer.
427405
*/
428406

429-
#defineInt8GetDatum(X) ((Datum)SET_1_BYTE(X))
407+
#defineInt8GetDatum(X) ((Datum) (X))
430408

431409
/*
432410
* DatumGetUInt8
433411
*Returns 8-bit unsigned integer value of a datum.
434412
*/
435413

436-
#defineDatumGetUInt8(X) ((uint8)GET_1_BYTE(X))
414+
#defineDatumGetUInt8(X) ((uint8) (X))
437415

438416
/*
439417
* UInt8GetDatum
440418
*Returns datum representation for an 8-bit unsigned integer.
441419
*/
442420

443-
#defineUInt8GetDatum(X) ((Datum)SET_1_BYTE(X))
421+
#defineUInt8GetDatum(X) ((Datum) (X))
444422

445423
/*
446424
* DatumGetInt16
447425
*Returns 16-bit integer value of a datum.
448426
*/
449427

450-
#defineDatumGetInt16(X) ((int16)GET_2_BYTES(X))
428+
#defineDatumGetInt16(X) ((int16) (X))
451429

452430
/*
453431
* Int16GetDatum
454432
*Returns datum representation for a 16-bit integer.
455433
*/
456434

457-
#defineInt16GetDatum(X) ((Datum)SET_2_BYTES(X))
435+
#defineInt16GetDatum(X) ((Datum) (X))
458436

459437
/*
460438
* DatumGetUInt16
461439
*Returns 16-bit unsigned integer value of a datum.
462440
*/
463441

464-
#defineDatumGetUInt16(X) ((uint16)GET_2_BYTES(X))
442+
#defineDatumGetUInt16(X) ((uint16) (X))
465443

466444
/*
467445
* UInt16GetDatum
468446
*Returns datum representation for a 16-bit unsigned integer.
469447
*/
470448

471-
#defineUInt16GetDatum(X) ((Datum)SET_2_BYTES(X))
449+
#defineUInt16GetDatum(X) ((Datum) (X))
472450

473451
/*
474452
* DatumGetInt32
475453
*Returns 32-bit integer value of a datum.
476454
*/
477455

478-
#defineDatumGetInt32(X) ((int32)GET_4_BYTES(X))
456+
#defineDatumGetInt32(X) ((int32) (X))
479457

480458
/*
481459
* Int32GetDatum
482460
*Returns datum representation for a 32-bit integer.
483461
*/
484462

485-
#defineInt32GetDatum(X) ((Datum)SET_4_BYTES(X))
463+
#defineInt32GetDatum(X) ((Datum) (X))
486464

487465
/*
488466
* DatumGetUInt32
489467
*Returns 32-bit unsigned integer value of a datum.
490468
*/
491469

492-
#defineDatumGetUInt32(X) ((uint32)GET_4_BYTES(X))
470+
#defineDatumGetUInt32(X) ((uint32) (X))
493471

494472
/*
495473
* UInt32GetDatum
496474
*Returns datum representation for a 32-bit unsigned integer.
497475
*/
498476

499-
#defineUInt32GetDatum(X) ((Datum)SET_4_BYTES(X))
477+
#defineUInt32GetDatum(X) ((Datum) (X))
500478

501479
/*
502480
* DatumGetObjectId
503481
*Returns object identifier value of a datum.
504482
*/
505483

506-
#defineDatumGetObjectId(X) ((Oid)GET_4_BYTES(X))
484+
#defineDatumGetObjectId(X) ((Oid) (X))
507485

508486
/*
509487
* ObjectIdGetDatum
510488
*Returns datum representation for an object identifier.
511489
*/
512490

513-
#defineObjectIdGetDatum(X) ((Datum)SET_4_BYTES(X))
491+
#defineObjectIdGetDatum(X) ((Datum) (X))
514492

515493
/*
516494
* DatumGetTransactionId
517495
*Returns transaction identifier value of a datum.
518496
*/
519497

520-
#defineDatumGetTransactionId(X) ((TransactionId)GET_4_BYTES(X))
498+
#defineDatumGetTransactionId(X) ((TransactionId) (X))
521499

522500
/*
523501
* TransactionIdGetDatum
524502
*Returns datum representation for a transaction identifier.
525503
*/
526504

527-
#defineTransactionIdGetDatum(X) ((Datum)SET_4_BYTES((X)))
505+
#defineTransactionIdGetDatum(X) ((Datum)(X))
528506

529507
/*
530508
* MultiXactIdGetDatum
531509
*Returns datum representation for a multixact identifier.
532510
*/
533511

534-
#defineMultiXactIdGetDatum(X) ((Datum)SET_4_BYTES((X)))
512+
#defineMultiXactIdGetDatum(X) ((Datum)(X))
535513

536514
/*
537515
* DatumGetCommandId
538516
*Returns command identifier value of a datum.
539517
*/
540518

541-
#defineDatumGetCommandId(X) ((CommandId)GET_4_BYTES(X))
519+
#defineDatumGetCommandId(X) ((CommandId) (X))
542520

543521
/*
544522
* CommandIdGetDatum
545523
*Returns datum representation for a command identifier.
546524
*/
547525

548-
#defineCommandIdGetDatum(X) ((Datum)SET_4_BYTES(X))
526+
#defineCommandIdGetDatum(X) ((Datum) (X))
549527

550528
/*
551529
* DatumGetPointer
@@ -608,7 +586,7 @@ typedef Datum *DatumPtr;
608586
*/
609587

610588
#ifdefUSE_FLOAT8_BYVAL
611-
#defineDatumGetInt64(X) ((int64)GET_8_BYTES(X))
589+
#defineDatumGetInt64(X) ((int64) (X))
612590
#else
613591
#defineDatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
614592
#endif
@@ -622,7 +600,7 @@ typedef Datum *DatumPtr;
622600
*/
623601

624602
#ifdefUSE_FLOAT8_BYVAL
625-
#defineInt64GetDatum(X) ((Datum)SET_8_BYTES(X))
603+
#defineInt64GetDatum(X) ((Datum) (X))
626604
#else
627605
externDatumInt64GetDatum(int64X);
628606
#endif
@@ -635,7 +613,7 @@ extern Datum Int64GetDatum(int64 X);
635613
*/
636614

637615
#ifdefUSE_FLOAT8_BYVAL
638-
#defineDatumGetUInt64(X) ((uint64)GET_8_BYTES(X))
616+
#defineDatumGetUInt64(X) ((uint64) (X))
639617
#else
640618
#defineDatumGetUInt64(X) (* ((uint64 *) DatumGetPointer(X)))
641619
#endif
@@ -649,7 +627,7 @@ extern Datum Int64GetDatum(int64 X);
649627
*/
650628

651629
#ifdefUSE_FLOAT8_BYVAL
652-
#defineUInt64GetDatum(X) ((Datum)SET_8_BYTES(X))
630+
#defineUInt64GetDatum(X) ((Datum) (X))
653631
#else
654632
#defineUInt64GetDatum(X) Int64GetDatum((int64) (X))
655633
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp