Skip to content

Commit 6bcda4a

Browse files
committed
Fix incorrect uses of Datum conversion macros
Since these macros just cast whatever you give them to the designated output type, and many normal uses also cast the output type further, a number of incorrect uses go undiscovered. The fixes in this patch have been discovered by changing these macros to inline functions, which is the subject of a future patch. Reviewed-by: Aleksander Alekseev <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
1 parent 6dc0738 commit 6bcda4a

File tree

22 files changed

+33
-33
lines changed

22 files changed

+33
-33
lines changed

Diff for: contrib/btree_gist/btree_utils_num.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
153153
datum = CashGetDatum(*(Cash *) entry->key);
154154
break;
155155
default:
156-
datum = PointerGetDatum(entry->key);
156+
datum = entry->key;
157157
}
158158

159159
retval = palloc(sizeof(GISTENTRY));

Diff for: contrib/dblink/dblink.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ dblink_get_connections(PG_FUNCTION_ARGS)
13361336
}
13371337

13381338
if (astate)
1339-
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate,
1339+
PG_RETURN_DATUM(makeArrayResult(astate,
13401340
CurrentMemoryContext));
13411341
else
13421342
PG_RETURN_NULL();

Diff for: contrib/hstore/hstore_op.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ hstore_each(PG_FUNCTION_ARGS)
10641064
tuple = heap_form_tuple(funcctx->tuple_desc, dvalues, nulls);
10651065
res = HeapTupleGetDatum(tuple);
10661066

1067-
SRF_RETURN_NEXT(funcctx, PointerGetDatum(res));
1067+
SRF_RETURN_NEXT(funcctx, res);
10681068
}
10691069

10701070
SRF_RETURN_DONE(funcctx);

Diff for: contrib/pageinspect/heapfuncs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
383383
errmsg("unexpected end of tuple data")));
384384

385385
if (attr->attlen == -1 && do_detoast)
386-
attr_data = DatumGetByteaPCopy(tupdata + off);
386+
attr_data = pg_detoast_datum_copy((struct varlena *) (tupdata + off));
387387
else
388388
{
389389
attr_data = (bytea *) palloc(len + VARHDRSZ);
@@ -492,7 +492,7 @@ tuple_data_split(PG_FUNCTION_ARGS)
492492
if (t_bits)
493493
pfree(t_bits);
494494

495-
PG_RETURN_ARRAYTYPE_P(res);
495+
PG_RETURN_DATUM(res);
496496
}
497497

498498
/*

Diff for: src/backend/access/brin/brin_bloom.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ brin_bloom_summary_out(PG_FUNCTION_ARGS)
767767
StringInfoData str;
768768

769769
/* detoast the data to get value with a full 4B header */
770-
filter = (BloomFilter *) PG_DETOAST_DATUM(PG_GETARG_BYTEA_PP(0));
770+
filter = (BloomFilter *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
771771

772772
initStringInfo(&str);
773773
appendStringInfoChar(&str, '{');

Diff for: src/backend/access/brin/brin_minmax_multi.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,12 @@ brin_range_deserialize(int maxvalues, SerializedRanges *serialized)
774774
datalen += MAXALIGN(typlen);
775775
else if (typlen == -1) /* varlena */
776776
{
777-
datalen += MAXALIGN(VARSIZE_ANY(DatumGetPointer(ptr)));
778-
ptr += VARSIZE_ANY(DatumGetPointer(ptr));
777+
datalen += MAXALIGN(VARSIZE_ANY(ptr));
778+
ptr += VARSIZE_ANY(ptr);
779779
}
780780
else if (typlen == -2) /* cstring */
781781
{
782-
Size slen = strlen(DatumGetCString(ptr)) + 1;
782+
Size slen = strlen(ptr) + 1;
783783

784784
datalen += MAXALIGN(slen);
785785
ptr += slen;
@@ -3033,7 +3033,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
30333033
* Detoast to get value with full 4B header (can't be stored in a toast
30343034
* table, but can use 1B header).
30353035
*/
3036-
ranges = (SerializedRanges *) PG_DETOAST_DATUM(PG_GETARG_BYTEA_PP(0));
3036+
ranges = (SerializedRanges *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
30373037

30383038
/* lookup output func for the type */
30393039
getTypeOutputInfo(ranges->typid, &outfunc, &isvarlena);
@@ -3081,7 +3081,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
30813081

30823082
getTypeOutputInfo(ANYARRAYOID, &typoutput, &typIsVarlena);
30833083

3084-
val = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
3084+
val = makeArrayResult(astate_values, CurrentMemoryContext);
30853085

30863086
extval = OidOutputFunctionCall(typoutput, val);
30873087

@@ -3121,7 +3121,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
31213121

31223122
getTypeOutputInfo(ANYARRAYOID, &typoutput, &typIsVarlena);
31233123

3124-
val = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
3124+
val = makeArrayResult(astate_values, CurrentMemoryContext);
31253125

31263126
extval = OidOutputFunctionCall(typoutput, val);
31273127

Diff for: src/backend/access/common/toast_compression.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pglz_compress_datum(const struct varlena *value)
4444
len;
4545
struct varlena *tmp = NULL;
4646

47-
valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
47+
valsize = VARSIZE_ANY_EXHDR(value);
4848

4949
/*
5050
* No point in wasting a palloc cycle if value size is outside the allowed

Diff for: src/backend/access/table/toast_helper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ toast_delete_external(Relation rel, Datum *values, bool *isnull,
330330

331331
if (isnull[i])
332332
continue;
333-
else if (VARATT_IS_EXTERNAL_ONDISK(PointerGetDatum(value)))
333+
else if (VARATT_IS_EXTERNAL_ONDISK(value))
334334
toast_delete_datum(rel, value, is_speculative);
335335
}
336336
}

Diff for: src/backend/access/transam/xlogfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ pg_wal_lsn_diff(PG_FUNCTION_ARGS)
555555
PG_GETARG_DATUM(0),
556556
PG_GETARG_DATUM(1));
557557

558-
PG_RETURN_NUMERIC(result);
558+
PG_RETURN_DATUM(result);
559559
}
560560

561561
/*

Diff for: src/backend/statistics/mcv.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,8 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
14441444
}
14451445

14461446
values[0] = Int32GetDatum(funcctx->call_cntr);
1447-
values[1] = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
1448-
values[2] = PointerGetDatum(makeArrayResult(astate_nulls, CurrentMemoryContext));
1447+
values[1] = makeArrayResult(astate_values, CurrentMemoryContext);
1448+
values[2] = makeArrayResult(astate_nulls, CurrentMemoryContext);
14491449
values[3] = Float8GetDatum(item->frequency);
14501450
values[4] = Float8GetDatum(item->base_frequency);
14511451

Diff for: src/backend/utils/adt/amutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,5 +466,5 @@ pg_indexam_progress_phasename(PG_FUNCTION_ARGS)
466466
if (!name)
467467
PG_RETURN_NULL();
468468

469-
PG_RETURN_TEXT_P(CStringGetTextDatum(name));
469+
PG_RETURN_DATUM(CStringGetTextDatum(name));
470470
}

Diff for: src/backend/utils/adt/multirangetypes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ multirange_intersect_agg_transfn(PG_FUNCTION_ARGS)
14911491
ranges1,
14921492
range_count2,
14931493
ranges2);
1494-
PG_RETURN_RANGE_P(result);
1494+
PG_RETURN_MULTIRANGE_P(result);
14951495
}
14961496

14971497

Diff for: src/backend/utils/adt/pg_lsn.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pg_lsn_pli(PG_FUNCTION_ARGS)
271271

272272
/* Add two numerics */
273273
res = DirectFunctionCall2(numeric_add,
274-
NumericGetDatum(num),
274+
num,
275275
NumericGetDatum(nbytes));
276276

277277
/* Convert to pg_lsn */
@@ -305,7 +305,7 @@ pg_lsn_mii(PG_FUNCTION_ARGS)
305305

306306
/* Subtract two numerics */
307307
res = DirectFunctionCall2(numeric_sub,
308-
NumericGetDatum(num),
308+
num,
309309
NumericGetDatum(nbytes));
310310

311311
/* Convert to pg_lsn */

Diff for: src/backend/utils/adt/pgstatfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
11191119

11201120
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
11211121

1122-
PG_RETURN_INET_P(DirectFunctionCall1(inet_in,
1122+
PG_RETURN_DATUM(DirectFunctionCall1(inet_in,
11231123
CStringGetDatum(remote_host)));
11241124
}
11251125

Diff for: src/backend/utils/adt/rangetypes_spgist.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
416416
/* This node has a centroid. Fetch it. */
417417
centroid = DatumGetRangeTypeP(in->prefixDatum);
418418
typcache = range_get_typcache(fcinfo,
419-
RangeTypeGetOid(DatumGetRangeTypeP(centroid)));
419+
RangeTypeGetOid(centroid));
420420
range_deserialize(typcache, centroid, &centroidLower, &centroidUpper,
421421
&centroidEmpty);
422422

@@ -557,7 +557,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
557557
*/
558558
if (in->traversalValue)
559559
{
560-
prevCentroid = DatumGetRangeTypeP(in->traversalValue);
560+
prevCentroid = in->traversalValue;
561561
range_deserialize(typcache, prevCentroid,
562562
&prevLower, &prevUpper, &prevEmpty);
563563
}

Diff for: src/backend/utils/adt/regexp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ regexp_split_to_array(PG_FUNCTION_ARGS)
17571757
splitctx->next_match++;
17581758
}
17591759

1760-
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext));
1760+
PG_RETURN_DATUM(makeArrayResult(astate, CurrentMemoryContext));
17611761
}
17621762

17631763
/* This is separate to keep the opr_sanity regression test from complaining */

Diff for: src/backend/utils/adt/tsgistidx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int outbuf_maxlen = 0;
102102
Datum
103103
gtsvectorout(PG_FUNCTION_ARGS)
104104
{
105-
SignTSVector *key = (SignTSVector *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
105+
SignTSVector *key = (SignTSVector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
106106
char *outbuf;
107107

108108
if (outbuf_maxlen == 0)

Diff for: src/backend/utils/adt/tsquery_op.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
148148
Datum
149149
tsquery_phrase(PG_FUNCTION_ARGS)
150150
{
151-
PG_RETURN_POINTER(DirectFunctionCall3(tsquery_phrase_distance,
151+
PG_RETURN_DATUM(DirectFunctionCall3(tsquery_phrase_distance,
152152
PG_GETARG_DATUM(0),
153153
PG_GETARG_DATUM(1),
154154
Int32GetDatum(1)));

Diff for: src/backend/utils/adt/varlena.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4779,7 +4779,7 @@ text_to_array(PG_FUNCTION_ARGS)
47794779
if (tstate.astate == NULL)
47804780
PG_RETURN_ARRAYTYPE_P(construct_empty_array(TEXTOID));
47814781

4782-
PG_RETURN_ARRAYTYPE_P(makeArrayResult(tstate.astate,
4782+
PG_RETURN_DATUM(makeArrayResult(tstate.astate,
47834783
CurrentMemoryContext));
47844784
}
47854785

Diff for: src/backend/utils/adt/xml.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4174,7 +4174,7 @@ xpath(PG_FUNCTION_ARGS)
41744174
astate = initArrayResult(XMLOID, CurrentMemoryContext, true);
41754175
xpath_internal(xpath_expr_text, data, namespaces,
41764176
NULL, astate);
4177-
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext));
4177+
PG_RETURN_DATUM(makeArrayResult(astate, CurrentMemoryContext));
41784178
#else
41794179
NO_XML_SUPPORT();
41804180
return 0;

Diff for: src/backend/utils/resowner/resowner.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
557557
/* Ditto for JIT contexts */
558558
while (ResourceArrayGetAny(&(owner->jitarr), &foundres))
559559
{
560-
JitContext *context = (JitContext *) PointerGetDatum(foundres);
560+
JitContext *context = (JitContext *) DatumGetPointer(foundres);
561561

562562
jit_release_context(context);
563563
}
@@ -566,7 +566,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
566566
while (ResourceArrayGetAny(&(owner->cryptohasharr), &foundres))
567567
{
568568
pg_cryptohash_ctx *context =
569-
(pg_cryptohash_ctx *) PointerGetDatum(foundres);
569+
(pg_cryptohash_ctx *) DatumGetPointer(foundres);
570570

571571
if (isCommit)
572572
PrintCryptoHashLeakWarning(foundres);
@@ -576,7 +576,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
576576
/* Ditto for HMAC contexts */
577577
while (ResourceArrayGetAny(&(owner->hmacarr), &foundres))
578578
{
579-
pg_hmac_ctx *context = (pg_hmac_ctx *) PointerGetDatum(foundres);
579+
pg_hmac_ctx *context = (pg_hmac_ctx *) DatumGetPointer(foundres);
580580

581581
if (isCommit)
582582
PrintHMACLeakWarning(foundres);

Diff for: src/pl/plperl/plperl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
18481848
{
18491849
current_call_data = &this_call_data;
18501850
if (CALLED_AS_TRIGGER(fcinfo))
1851-
retval = PointerGetDatum(plperl_trigger_handler(fcinfo));
1851+
retval = plperl_trigger_handler(fcinfo);
18521852
else if (CALLED_AS_EVENT_TRIGGER(fcinfo))
18531853
{
18541854
plperl_event_trigger_handler(fcinfo);

0 commit comments

Comments
 (0)