- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitf0efa5a
committed
Introduce the concept of read-only StringInfos
There were various places in our codebase which conjured up a StringInfoby manually assigning the StringInfo fields and setting the data fieldto point to some existing buffer. There wasn't much consistency here asto what fields like maxlen got set to and in one location we didn'tcorrectly ensure that the buffer was correctly NUL terminated at lenbytes, as per what was documented as required in stringinfo.hHere we introduce 2 new functions to initialize StringInfos. One allowscallers to initialize a StringInfo passing along a buffer that isalready allocated by palloc. Here the StringInfo code uses this bufferdirectly rather than doing any memcpying into a new allocation. Havingthis as a function allows us to verify the buffer is correctly NULterminated. StringInfos initialized this way can be appended to andreset just like any other normal StringInfo.The other new initialization function also accepts an existing buffer,but the given buffer does not need to be a pointer to a palloc'd chunk.This buffer could be a pointer pointing partway into some palloc'd chunkor may not even be palloc'd at all. StringInfos initialized this wayare deemed as "read-only". This means that it's not possible toappend to them or reset them.For the latter of the two new initialization functions mentioned above,we relax the requirement that the data buffer must be NUL terminated.Relaxing this requirement is convenient in a few places as it can saveus from having to allocate an entire new buffer just to add the NULterminator or save us from having to temporarily add a NUL only to have toput the original char back again later.Incompatibility note:Here we also forego adding the NUL in a few places where it does notseem to be required. These locations are passing the given StringInfointo a type's receive function. It does not seem like any of ourbuilt-in receive functions require this, but perhaps there's some UDTout there in the wild which does require this. It is likely worthy ofa mention in the release notes that a UDT's receive function mustn't relyon the input StringInfo being NUL terminated.Author: David RowleyReviewed-by: Tom LaneDiscussion:https://postgr.es/m/CAApHDvorfO3iBZ%3DxpiZvp3uHtJVLyFaPBSvcAhAq2HPLnaNSwQ%40mail.gmail.com1 parent01575ad commitf0efa5a
File tree
9 files changed
+127
-83
lines changed- src
- backend
- replication/logical
- tcop
- utils/adt
- common
- include/lib
9 files changed
+127
-83
lines changedLines changed: 1 addition & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
774 | 774 |
| |
775 | 775 |
| |
776 | 776 |
| |
777 |
| - | |
778 |
| - | |
779 |
| - | |
780 |
| - | |
| 777 | + | |
781 | 778 |
| |
782 | 779 |
| |
783 | 780 |
| |
|
Lines changed: 9 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
879 | 879 |
| |
880 | 880 |
| |
881 | 881 |
| |
| 882 | + | |
882 | 883 |
| |
883 | 884 |
| |
884 | 885 |
| |
| |||
899 | 900 |
| |
900 | 901 |
| |
901 | 902 |
| |
902 |
| - | |
903 |
| - | |
| 903 | + | |
| 904 | + | |
904 | 905 |
| |
905 | 906 |
| |
906 |
| - | |
907 |
| - | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
908 | 911 |
| |
909 |
| - | |
| 912 | + | |
910 | 913 |
| |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
| 914 | + | |
915 | 915 |
| |
916 | 916 |
| |
917 | 917 |
| |
|
Lines changed: 1 addition & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3582 | 3582 |
| |
3583 | 3583 |
| |
3584 | 3584 |
| |
3585 |
| - | |
3586 |
| - | |
3587 |
| - | |
3588 |
| - | |
| 3585 | + | |
3589 | 3586 |
| |
3590 | 3587 |
| |
3591 | 3588 |
| |
|
Lines changed: 9 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1817 | 1817 |
| |
1818 | 1818 |
| |
1819 | 1819 |
| |
1820 |
| - | |
| 1820 | + | |
1821 | 1821 |
| |
1822 | 1822 |
| |
1823 |
| - | |
| 1823 | + | |
1824 | 1824 |
| |
1825 |
| - | |
1826 |
| - | |
1827 |
| - | |
1828 |
| - | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
1829 | 1828 |
| |
1830 |
| - | |
1831 |
| - | |
1832 |
| - | |
1833 |
| - | |
1834 |
| - | |
1835 |
| - | |
1836 |
| - | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
1837 | 1833 |
| |
1838 | 1834 |
| |
1839 | 1835 |
| |
|
Lines changed: 4 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
784 | 784 |
| |
785 | 785 |
| |
786 | 786 |
| |
787 |
| - | |
788 | 787 |
| |
789 | 788 |
| |
790 | 789 |
| |
| |||
799 | 798 |
| |
800 | 799 |
| |
801 | 800 |
| |
802 |
| - | |
803 |
| - | |
804 |
| - | |
805 |
| - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
806 | 804 |
| |
807 |
| - | |
808 |
| - | |
809 |
| - | |
810 |
| - | |
| 805 | + | |
811 | 806 |
| |
812 | 807 |
| |
813 | 808 |
| |
814 |
| - | |
815 |
| - | |
816 |
| - | |
817 | 809 |
| |
818 | 810 |
| |
819 | 811 |
| |
820 | 812 |
| |
821 | 813 |
| |
822 |
| - | |
823 |
| - | |
824 | 814 |
| |
825 | 815 |
| |
826 | 816 |
| |
|
Lines changed: 3 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1475 | 1475 |
| |
1476 | 1476 |
| |
1477 | 1477 |
| |
1478 |
| - | |
1479 | 1478 |
| |
1480 | 1479 |
| |
1481 | 1480 |
| |
| |||
1494 | 1493 |
| |
1495 | 1494 |
| |
1496 | 1495 |
| |
1497 |
| - | |
1498 |
| - | |
1499 |
| - | |
1500 |
| - | |
| 1496 | + | |
| 1497 | + | |
1501 | 1498 |
| |
1502 |
| - | |
1503 |
| - | |
1504 |
| - | |
1505 |
| - | |
| 1499 | + | |
1506 | 1500 |
| |
1507 | 1501 |
| |
1508 | 1502 |
| |
1509 |
| - | |
1510 |
| - | |
1511 |
| - | |
1512 | 1503 |
| |
1513 | 1504 |
| |
1514 | 1505 |
| |
| |||
1520 | 1511 |
| |
1521 | 1512 |
| |
1522 | 1513 |
| |
1523 |
| - | |
1524 |
| - | |
1525 | 1514 |
| |
1526 | 1515 |
| |
1527 | 1516 |
| |
|
Lines changed: 7 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
569 | 569 |
| |
570 | 570 |
| |
571 | 571 |
| |
572 |
| - | |
573 | 572 |
| |
574 | 573 |
| |
575 | 574 |
| |
| |||
619 | 618 |
| |
620 | 619 |
| |
621 | 620 |
| |
622 |
| - | |
623 | 621 |
| |
624 | 622 |
| |
625 | 623 |
| |
| 624 | + | |
| 625 | + | |
626 | 626 |
| |
627 |
| - | |
628 |
| - | |
629 |
| - | |
630 |
| - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
631 | 630 |
| |
632 |
| - | |
633 |
| - | |
634 |
| - | |
635 |
| - | |
636 |
| - | |
| 631 | + | |
637 | 632 |
| |
638 |
| - | |
639 |
| - | |
640 |
| - | |
| 633 | + | |
641 | 634 |
| |
642 | 635 |
| |
643 | 636 |
| |
| |||
667 | 660 |
| |
668 | 661 |
| |
669 | 662 |
| |
670 |
| - | |
671 |
| - | |
672 | 663 |
| |
673 | 664 |
| |
674 | 665 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
70 | 70 |
| |
71 | 71 |
| |
72 | 72 |
| |
| 73 | + | |
| 74 | + | |
| 75 | + | |
73 | 76 |
| |
74 | 77 |
| |
75 | 78 |
| |
76 | 79 |
| |
| 80 | + | |
| 81 | + | |
| 82 | + | |
77 | 83 |
| |
78 | 84 |
| |
79 | 85 |
| |
| |||
284 | 290 |
| |
285 | 291 |
| |
286 | 292 |
| |
| 293 | + | |
| 294 | + | |
| 295 | + | |
287 | 296 |
| |
288 | 297 |
| |
289 | 298 |
| |
|
Lines changed: 84 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
23 |
| - | |
24 |
| - | |
25 |
| - | |
26 |
| - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
34 | 44 |
| |
35 | 45 |
| |
36 | 46 |
| |
| |||
45 | 55 |
| |
46 | 56 |
| |
47 | 57 |
| |
48 |
| - | |
| 58 | + | |
49 | 59 |
| |
50 | 60 |
| |
51 | 61 |
| |
| |||
56 | 66 |
| |
57 | 67 |
| |
58 | 68 |
| |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
59 | 89 |
| |
60 | 90 |
| |
| 91 | + | |
| 92 | + | |
| 93 | + | |
61 | 94 |
| |
62 | 95 |
| |
63 | 96 |
| |
| |||
79 | 112 |
| |
80 | 113 |
| |
81 | 114 |
| |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
82 | 157 |
| |
83 | 158 |
| |
84 | 159 |
| |
|
0 commit comments
Comments
(0)