Skip to content

Commit 8a27d41

Browse files
committed
Mark function arguments of type "Datum *" as "const Datum *" where possible
Several functions in the codebase accept "Datum *" parameters but do not modify the pointed-to data. These have been updated to take "const Datum *" instead, improving type safety and making the interfaces clearer about their intent. This change helps the compiler catch accidental modifications and better documents immutability of arguments. Most of "Datum *" parameters have a pairing "bool *isnull" parameter, they are constified as well. No functional behavior is changed by this patch. Author: Chao Li <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2msfT0knvzUa72ZBwu9LR_RLY4on85w2a9YpE-o2By5HQ@mail.gmail.com
1 parent aa45353 commit 8a27d41

File tree

34 files changed

+145
-145
lines changed

34 files changed

+145
-145
lines changed

doc/src/sgml/spi.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ int SPI_execute_extended(const char *<parameter>command</parameter>,
846846
<synopsis>
847847
int SPI_execute_with_args(const char *<parameter>command</parameter>,
848848
int <parameter>nargs</parameter>, Oid *<parameter>argtypes</parameter>,
849-
Datum *<parameter>values</parameter>, const char *<parameter>nulls</parameter>,
849+
const Datum *<parameter>values</parameter>, const char *<parameter>nulls</parameter>,
850850
bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
851851
</synopsis>
852852
</refsynopsisdiv>
@@ -1671,7 +1671,7 @@ bool SPI_is_cursor_plan(SPIPlanPtr <parameter>plan</parameter>)
16711671

16721672
<refsynopsisdiv>
16731673
<synopsis>
1674-
int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>,
1674+
int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, const Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>,
16751675
bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
16761676
</synopsis>
16771677
</refsynopsisdiv>
@@ -2317,7 +2317,7 @@ Portal SPI_cursor_open(const char * <parameter>name</parameter>, SPIPlanPtr <par
23172317
Portal SPI_cursor_open_with_args(const char *<parameter>name</parameter>,
23182318
const char *<parameter>command</parameter>,
23192319
int <parameter>nargs</parameter>, Oid *<parameter>argtypes</parameter>,
2320-
Datum *<parameter>values</parameter>, const char *<parameter>nulls</parameter>,
2320+
const Datum *<parameter>values</parameter>, const char *<parameter>nulls</parameter>,
23212321
bool <parameter>read_only</parameter>, int <parameter>cursorOptions</parameter>)
23222322
</synopsis>
23232323
</refsynopsisdiv>

src/backend/access/brin/brin_minmax_multi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int compare_values(const void *a, const void *b, void *arg);
276276
* function (which should be BTLessStrategyNumber).
277277
*/
278278
static void
279-
AssertArrayOrder(FmgrInfo *cmp, Oid colloid, Datum *values, int nvalues)
279+
AssertArrayOrder(FmgrInfo *cmp, Oid colloid, const Datum *values, int nvalues)
280280
{
281281
int i;
282282
Datum lt;

src/backend/access/hash/hashutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ _hash_get_indextuple_hashkey(IndexTuple itup)
316316
*/
317317
bool
318318
_hash_convert_tuple(Relation index,
319-
Datum *user_values, bool *user_isnull,
319+
const Datum *user_values, const bool *user_isnull,
320320
Datum *index_values, bool *index_isnull)
321321
{
322322
uint32 hashkey;

src/backend/access/heap/heaptoast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ toast_flatten_tuple_to_datum(HeapTupleHeader tup,
561561
*/
562562
HeapTuple
563563
toast_build_flattened_tuple(TupleDesc tupleDesc,
564-
Datum *values,
565-
bool *isnull)
564+
const Datum *values,
565+
const bool *isnull)
566566
{
567567
HeapTuple new_tuple;
568568
int numAttrs = tupleDesc->natts;

src/backend/access/nbtree/nbtpreprocesskeys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int _bt_num_array_keys(IndexScanDesc scan, Oid *skip_eq_ops_out,
6767
int *numSkipArrayKeys_out);
6868
static Datum _bt_find_extreme_element(IndexScanDesc scan, ScanKey skey,
6969
Oid elemtype, StrategyNumber strat,
70-
Datum *elems, int nelems);
70+
const Datum *elems, int nelems);
7171
static void _bt_setup_array_cmp(IndexScanDesc scan, ScanKey skey, Oid elemtype,
7272
FmgrInfo *orderproc, FmgrInfo **sortprocp);
7373
static int _bt_sort_array_elements(ScanKey skey, FmgrInfo *sortproc,
@@ -2569,7 +2569,7 @@ _bt_num_array_keys(IndexScanDesc scan, Oid *skip_eq_ops_out,
25692569
static Datum
25702570
_bt_find_extreme_element(IndexScanDesc scan, ScanKey skey, Oid elemtype,
25712571
StrategyNumber strat,
2572-
Datum *elems, int nelems)
2572+
const Datum *elems, int nelems)
25732573
{
25742574
Relation rel = scan->indexRelation;
25752575
Oid cmp_op;

src/backend/access/nbtree/nbtsort.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static double _bt_spools_heapscan(Relation heap, Relation index,
258258
BTBuildState *buildstate, IndexInfo *indexInfo);
259259
static void _bt_spooldestroy(BTSpool *btspool);
260260
static void _bt_spool(BTSpool *btspool, const ItemPointerData *self,
261-
Datum *values, bool *isnull);
261+
const Datum *values, const bool *isnull);
262262
static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2);
263263
static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values,
264264
bool *isnull, bool tupleIsAlive, void *state);
@@ -525,7 +525,7 @@ _bt_spooldestroy(BTSpool *btspool)
525525
* spool an index entry into the sort file.
526526
*/
527527
static void
528-
_bt_spool(BTSpool *btspool, const ItemPointerData *self, Datum *values, bool *isnull)
528+
_bt_spool(BTSpool *btspool, const ItemPointerData *self, const Datum *values, const bool *isnull)
529529
{
530530
tuplesort_putindextuplevalues(btspool->sortstate, btspool->index,
531531
self, values, isnull);

src/backend/access/spgist/spgdoinsert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ spgSplitNodeAction(Relation index, SpGistState *state,
19081908
*/
19091909
bool
19101910
spgdoinsert(Relation index, SpGistState *state,
1911-
const ItemPointerData *heapPtr, Datum *datums, bool *isnulls)
1911+
const ItemPointerData *heapPtr, const Datum *datums, const bool *isnulls)
19121912
{
19131913
bool result = true;
19141914
TupleDesc leafDescriptor = state->leafTupDesc;

src/backend/access/spgist/spgtextproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ commonPrefix(const char *a, const char *b, int lena, int lenb)
155155
* On success, *i gets the match location; on failure, it gets where to insert
156156
*/
157157
static bool
158-
searchChar(Datum *nodeLabels, int nNodes, int16 c, int *i)
158+
searchChar(const Datum *nodeLabels, int nNodes, int16 c, int *i)
159159
{
160160
int StopLow = 0,
161161
StopHigh = nNodes;

src/backend/executor/execPartition.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ static void FormPartitionKeyDatum(PartitionDispatch pd,
173173
EState *estate,
174174
Datum *values,
175175
bool *isnull);
176-
static int get_partition_for_tuple(PartitionDispatch pd, Datum *values,
177-
bool *isnull);
176+
static int get_partition_for_tuple(PartitionDispatch pd, const Datum *values,
177+
const bool *isnull);
178178
static char *ExecBuildSlotPartitionKeyDescription(Relation rel,
179-
Datum *values,
180-
bool *isnull,
179+
const Datum *values,
180+
const bool *isnull,
181181
int maxfieldlen);
182182
static List *adjust_partition_colnos(List *colnos, ResultRelInfo *leaf_part_rri);
183183
static List *adjust_partition_colnos_using_map(List *colnos, AttrMap *attrMap);
@@ -1396,7 +1396,7 @@ FormPartitionKeyDatum(PartitionDispatch pd,
13961396
* found or -1 if none found.
13971397
*/
13981398
static int
1399-
get_partition_for_tuple(PartitionDispatch pd, Datum *values, bool *isnull)
1399+
get_partition_for_tuple(PartitionDispatch pd, const Datum *values, const bool *isnull)
14001400
{
14011401
int bound_offset = -1;
14021402
int part_index = -1;
@@ -1617,8 +1617,8 @@ get_partition_for_tuple(PartitionDispatch pd, Datum *values, bool *isnull)
16171617
*/
16181618
static char *
16191619
ExecBuildSlotPartitionKeyDescription(Relation rel,
1620-
Datum *values,
1621-
bool *isnull,
1620+
const Datum *values,
1621+
const bool *isnull,
16221622
int maxfieldlen)
16231623
{
16241624
StringInfoData buf;

src/backend/executor/nodeIndexscan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int cmp_orderbyvals(const Datum *adist, const bool *anulls,
6565
static int reorderqueue_cmp(const pairingheap_node *a,
6666
const pairingheap_node *b, void *arg);
6767
static void reorderqueue_push(IndexScanState *node, TupleTableSlot *slot,
68-
Datum *orderbyvals, bool *orderbynulls);
68+
const Datum *orderbyvals, const bool *orderbynulls);
6969
static HeapTuple reorderqueue_pop(IndexScanState *node);
7070

7171

@@ -458,7 +458,7 @@ reorderqueue_cmp(const pairingheap_node *a, const pairingheap_node *b,
458458
*/
459459
static void
460460
reorderqueue_push(IndexScanState *node, TupleTableSlot *slot,
461-
Datum *orderbyvals, bool *orderbynulls)
461+
const Datum *orderbyvals, const bool *orderbynulls)
462462
{
463463
IndexScanDesc scandesc = node->iss_ScanDesc;
464464
EState *estate = node->ss.ps.state;

0 commit comments

Comments
 (0)