mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +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));
|
||||
|
||||
2
src/backend/utils/cache/attoptcache.c
vendored
2
src/backend/utils/cache/attoptcache.c
vendored
@@ -86,7 +86,7 @@ relatt_cache_syshash(const void *key, Size keysize)
|
||||
const AttoptCacheKey *ckey = key;
|
||||
|
||||
Assert(keysize == sizeof(*ckey));
|
||||
return GetSysCacheHashValue2(ATTNUM, ckey->attrelid, ckey->attnum);
|
||||
return GetSysCacheHashValue2(ATTNUM, ObjectIdGetDatum(ckey->attrelid), Int32GetDatum(ckey->attnum));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
2
src/backend/utils/cache/lsyscache.c
vendored
2
src/backend/utils/cache/lsyscache.c
vendored
@@ -3817,7 +3817,7 @@ get_subscription_oid(const char *subname, bool missing_ok)
|
||||
Oid oid;
|
||||
|
||||
oid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
|
||||
MyDatabaseId, CStringGetDatum(subname));
|
||||
ObjectIdGetDatum(MyDatabaseId), CStringGetDatum(subname));
|
||||
if (!OidIsValid(oid) && !missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
|
||||
2
src/backend/utils/cache/relcache.c
vendored
2
src/backend/utils/cache/relcache.c
vendored
@@ -6991,5 +6991,5 @@ ResOwnerReleaseRelation(Datum res)
|
||||
Assert(rel->rd_refcnt > 0);
|
||||
rel->rd_refcnt -= 1;
|
||||
|
||||
RelationCloseCleanup((Relation) res);
|
||||
RelationCloseCleanup((Relation) DatumGetPointer(res));
|
||||
}
|
||||
|
||||
6
src/backend/utils/cache/syscache.c
vendored
6
src/backend/utils/cache/syscache.c
vendored
@@ -459,9 +459,9 @@ GetSysCacheOid(int cacheId,
|
||||
tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return InvalidOid;
|
||||
result = heap_getattr(tuple, oidcol,
|
||||
SysCache[cacheId]->cc_tupdesc,
|
||||
&isNull);
|
||||
result = DatumGetObjectId(heap_getattr(tuple, oidcol,
|
||||
SysCache[cacheId]->cc_tupdesc,
|
||||
&isNull));
|
||||
Assert(!isNull); /* columns used as oids should never be NULL */
|
||||
ReleaseSysCache(tuple);
|
||||
return result;
|
||||
|
||||
@@ -57,7 +57,7 @@ comparison_shim(Datum x, Datum y, SortSupport ssup)
|
||||
if (extra->fcinfo.isnull)
|
||||
elog(ERROR, "function %u returned NULL", extra->flinfo.fn_oid);
|
||||
|
||||
return result;
|
||||
return DatumGetInt32(result);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -865,7 +865,7 @@ tuplesort_putbrintuple(Tuplesortstate *state, BrinTuple *tuple, Size size)
|
||||
memcpy(&bstup->tuple, tuple, size);
|
||||
|
||||
stup.tuple = bstup;
|
||||
stup.datum1 = tuple->bt_blkno;
|
||||
stup.datum1 = UInt32GetDatum(tuple->bt_blkno);
|
||||
stup.isnull1 = false;
|
||||
|
||||
/* GetMemoryChunkSpace is not supported for bump contexts */
|
||||
@@ -1836,7 +1836,7 @@ removeabbrev_index_brin(Tuplesortstate *state, SortTuple *stups, int count)
|
||||
BrinSortTuple *tuple;
|
||||
|
||||
tuple = stups[i].tuple;
|
||||
stups[i].datum1 = tuple->tuple.bt_blkno;
|
||||
stups[i].datum1 = UInt32GetDatum(tuple->tuple.bt_blkno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1893,7 +1893,7 @@ readtup_index_brin(Tuplesortstate *state, SortTuple *stup,
|
||||
stup->tuple = tuple;
|
||||
|
||||
/* set up first-column key value, which is block number */
|
||||
stup->datum1 = tuple->tuple.bt_blkno;
|
||||
stup->datum1 = UInt32GetDatum(tuple->tuple.bt_blkno);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user