mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Add missing Datum conversions
Add various missing conversions from and to Datum. The previous code mostly relied on implicit conversions or its own explicit casts instead of using the correct DatumGet*() or *GetDatum() functions. We think these omissions are harmless. Some actual bugs that were discovered during this process have been committed separately (80c758a2e1,fd2ab03fea). Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/8246d7ff-f4b7-4363-913e-827dadfeb145%40eisentraut.org
This commit is contained in:
@@ -299,9 +299,9 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
|
||||
len1 - VARHDRSZ) == 0);
|
||||
|
||||
/* Only free memory if it's a copy made here. */
|
||||
if ((Pointer) arg1val != (Pointer) value1)
|
||||
if ((Pointer) arg1val != DatumGetPointer(value1))
|
||||
pfree(arg1val);
|
||||
if ((Pointer) arg2val != (Pointer) value2)
|
||||
if ((Pointer) arg2val != DatumGetPointer(value2))
|
||||
pfree(arg2val);
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ datum_image_hash(Datum value, bool typByVal, int typLen)
|
||||
result = hash_bytes((unsigned char *) VARDATA_ANY(val), len - VARHDRSZ);
|
||||
|
||||
/* Only free memory if it's a copy made here. */
|
||||
if ((Pointer) val != (Pointer) value)
|
||||
if ((Pointer) val != DatumGetPointer(value))
|
||||
pfree(val);
|
||||
}
|
||||
else if (typLen == -2)
|
||||
|
||||
@@ -1517,7 +1517,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
||||
/* Convert numstr to Numeric with typmod */
|
||||
Assert(numstr != NULL);
|
||||
noerr = DirectInputFunctionCallSafe(numeric_in, numstr,
|
||||
InvalidOid, dtypmod,
|
||||
InvalidOid, DatumGetInt32(dtypmod),
|
||||
(Node *) &escontext,
|
||||
&numdatum);
|
||||
|
||||
|
||||
@@ -398,15 +398,15 @@ pg_lock_status(PG_FUNCTION_ARGS)
|
||||
values[0] = CStringGetTextDatum(PredicateLockTagTypeNames[lockType]);
|
||||
|
||||
/* lock target */
|
||||
values[1] = GET_PREDICATELOCKTARGETTAG_DB(*predTag);
|
||||
values[2] = GET_PREDICATELOCKTARGETTAG_RELATION(*predTag);
|
||||
values[1] = ObjectIdGetDatum(GET_PREDICATELOCKTARGETTAG_DB(*predTag));
|
||||
values[2] = ObjectIdGetDatum(GET_PREDICATELOCKTARGETTAG_RELATION(*predTag));
|
||||
if (lockType == PREDLOCKTAG_TUPLE)
|
||||
values[4] = GET_PREDICATELOCKTARGETTAG_OFFSET(*predTag);
|
||||
values[4] = UInt16GetDatum(GET_PREDICATELOCKTARGETTAG_OFFSET(*predTag));
|
||||
else
|
||||
nulls[4] = true;
|
||||
if ((lockType == PREDLOCKTAG_TUPLE) ||
|
||||
(lockType == PREDLOCKTAG_PAGE))
|
||||
values[3] = GET_PREDICATELOCKTARGETTAG_PAGE(*predTag);
|
||||
values[3] = UInt32GetDatum(GET_PREDICATELOCKTARGETTAG_PAGE(*predTag));
|
||||
else
|
||||
nulls[3] = true;
|
||||
|
||||
|
||||
@@ -2523,7 +2523,7 @@ multirange_adjacent_range(PG_FUNCTION_ARGS)
|
||||
TypeCacheEntry *typcache;
|
||||
|
||||
if (RangeIsEmpty(r) || MultirangeIsEmpty(mr))
|
||||
return false;
|
||||
PG_RETURN_BOOL(false);
|
||||
|
||||
typcache = multirange_get_typcache(fcinfo, MultirangeTypeGetOid(mr));
|
||||
|
||||
@@ -2544,7 +2544,7 @@ multirange_adjacent_multirange(PG_FUNCTION_ARGS)
|
||||
upper2;
|
||||
|
||||
if (MultirangeIsEmpty(mr1) || MultirangeIsEmpty(mr2))
|
||||
return false;
|
||||
PG_RETURN_BOOL(false);
|
||||
|
||||
typcache = multirange_get_typcache(fcinfo, MultirangeTypeGetOid(mr1));
|
||||
|
||||
@@ -2639,7 +2639,7 @@ multirange_cmp(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
multirange_lt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = multirange_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(multirange_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp < 0);
|
||||
}
|
||||
@@ -2647,7 +2647,7 @@ multirange_lt(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
multirange_le(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = multirange_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(multirange_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp <= 0);
|
||||
}
|
||||
@@ -2655,7 +2655,7 @@ multirange_le(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
multirange_ge(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = multirange_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(multirange_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp >= 0);
|
||||
}
|
||||
@@ -2663,7 +2663,7 @@ multirange_ge(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
multirange_gt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = multirange_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(multirange_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp > 0);
|
||||
}
|
||||
|
||||
@@ -1356,7 +1356,7 @@ range_fast_cmp(Datum a, Datum b, SortSupport ssup)
|
||||
Datum
|
||||
range_lt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = range_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(range_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp < 0);
|
||||
}
|
||||
@@ -1364,7 +1364,7 @@ range_lt(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
range_le(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = range_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(range_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp <= 0);
|
||||
}
|
||||
@@ -1372,7 +1372,7 @@ range_le(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
range_ge(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = range_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(range_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp >= 0);
|
||||
}
|
||||
@@ -1380,7 +1380,7 @@ range_ge(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
range_gt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cmp = range_cmp(fcinfo);
|
||||
int cmp = DatumGetInt32(range_cmp(fcinfo));
|
||||
|
||||
PG_RETURN_BOOL(cmp > 0);
|
||||
}
|
||||
|
||||
@@ -757,7 +757,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
* because it's range
|
||||
*/
|
||||
previousCentroid = datumCopy(in->prefixDatum, false, -1);
|
||||
out->traversalValues[out->nNodes] = (void *) previousCentroid;
|
||||
out->traversalValues[out->nNodes] = DatumGetPointer(previousCentroid);
|
||||
}
|
||||
out->nodeNumbers[out->nNodes] = i - 1;
|
||||
out->nNodes++;
|
||||
|
||||
@@ -1529,9 +1529,9 @@ record_image_cmp(FunctionCallInfo fcinfo)
|
||||
if ((cmpresult == 0) && (len1 != len2))
|
||||
cmpresult = (len1 < len2) ? -1 : 1;
|
||||
|
||||
if ((Pointer) arg1val != (Pointer) values1[i1])
|
||||
if ((Pointer) arg1val != DatumGetPointer(values1[i1]))
|
||||
pfree(arg1val);
|
||||
if ((Pointer) arg2val != (Pointer) values2[i2])
|
||||
if ((Pointer) arg2val != DatumGetPointer(values2[i2]))
|
||||
pfree(arg2val);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -73,7 +73,7 @@ pg_isolation_test_session_is_blocked(PG_FUNCTION_ARGS)
|
||||
* acquire heavyweight locks.
|
||||
*/
|
||||
blocking_pids_a =
|
||||
DatumGetArrayTypeP(DirectFunctionCall1(pg_blocking_pids, blocked_pid));
|
||||
DatumGetArrayTypeP(DirectFunctionCall1(pg_blocking_pids, Int32GetDatum(blocked_pid)));
|
||||
|
||||
Assert(ARR_ELEMTYPE(blocking_pids_a) == INT4OID);
|
||||
Assert(!array_contains_nulls(blocking_pids_a));
|
||||
|
||||
Reference in New Issue
Block a user