]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Mop-up for Datum conversion cleanups.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Aug 2025 22:44:57 +0000 (18:44 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Aug 2025 22:44:57 +0000 (18:44 -0400)
Fix a couple more places where an explicit Datum conversion
is needed (not clear how we missed these in ff89e182d and
previous commits).

Replace the minority usage "(Datum) NULL" with "(Datum) 0".
The former depends on the assumption that Datum is the same
width as Pointer, the latter doesn't.  Anyway consistency
is a good thing.

This is, I believe, the last of the notational mop-up needed
before we can consider changing Datum to uint64 everywhere.
It's also important cleanup for more aggressive ideas such
as making Datum a struct.

Discussion: https://postgr.es/m/1749799.1752797397@sss.pgh.pa.us
Discussion: https://postgr.es/m/8246d7ff-f4b7-4363-913e-827dadfeb145@eisentraut.org

13 files changed:
contrib/ltree/_ltree_gist.c
src/backend/catalog/pg_aggregate.c
src/backend/catalog/pg_constraint.c
src/backend/catalog/pg_conversion.c
src/backend/catalog/pg_namespace.c
src/backend/catalog/pg_operator.c
src/backend/catalog/pg_type.c
src/backend/executor/spi.c
src/backend/nodes/readfuncs.c
src/backend/utils/adt/jsonfuncs.c
src/backend/utils/adt/rangetypes.c
src/include/access/htup_details.h
src/include/access/itup.h

index 286ad24fbe847987e8c77d1f396446ecbc224e80..30d516e60bc214a54257db0e9e67b76bc7d5bfeb 100644 (file)
@@ -84,7 +84,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
                                          entry->rel, entry->page,
                                          entry->offset, false);
        }
-       else if (!LTG_ISALLTRUE(entry->key))
+       else if (!LTG_ISALLTRUE(DatumGetPointer(entry->key)))
        {
                int32           i;
                ltree_gist *key;
index a05f8a87c1f8353a12a679baebefb4ec6761ccb2..c62e8acd413757c80fada0085a340020d1443175 100644 (file)
@@ -654,7 +654,7 @@ AggregateCreate(const char *aggName,
        for (i = 0; i < Natts_pg_aggregate; i++)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;
+               values[i] = (Datum) 0;
                replaces[i] = true;
        }
        values[Anum_pg_aggregate_aggfnoid - 1] = ObjectIdGetDatum(procOid);
index 2d5ac1ea8138b92e6eb05cb7dcab97f5b845ac6a..6002fd0002fc9fba45c44343c538ee7b8c948552 100644 (file)
@@ -179,7 +179,7 @@ CreateConstraintEntry(const char *constraintName,
        for (i = 0; i < Natts_pg_constraint; i++)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;
+               values[i] = (Datum) 0;
        }
 
        conOid = GetNewOidWithIndex(conDesc, ConstraintOidIndexId,
index 04cc375caea8ccd33a3b32109053f036f4de3cc1..090f680d1908f298a2ba403743c0046825fd01b1 100644 (file)
@@ -87,7 +87,7 @@ ConversionCreate(const char *conname, Oid connamespace,
        for (i = 0; i < Natts_pg_conversion; i++)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;
+               values[i] = (Datum) 0;
        }
 
        /* form a tuple */
index 6f5634a4de69be9db27c5c5fea63700671244df7..616bcc78521134f988ba2e116e5ed16dd2f473ee 100644 (file)
@@ -76,7 +76,7 @@ NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
        for (i = 0; i < Natts_pg_namespace; i++)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;
+               values[i] = (Datum) 0;
        }
 
        nspoid = GetNewOidWithIndex(nspdesc, NamespaceOidIndexId,
index bfcfa643464ac62574e06e79a610162ee83af046..44d2ccb6788e990e0b64b2f178e208614c00cdc8 100644 (file)
@@ -225,7 +225,7 @@ OperatorShellMake(const char *operatorName,
        for (i = 0; i < Natts_pg_operator; ++i)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;       /* redundant, but safe */
+               values[i] = (Datum) 0;  /* redundant, but safe */
        }
 
        /*
@@ -453,7 +453,7 @@ OperatorCreate(const char *operatorName,
 
        for (i = 0; i < Natts_pg_operator; ++i)
        {
-               values[i] = (Datum) NULL;
+               values[i] = (Datum) 0;
                replaces[i] = true;
                nulls[i] = false;
        }
index b36f81afb9d3ff808a4bea55e7f74ac6bd61c65e..1ec523ee3e59eb096771d0fed5f794d77ca7130f 100644 (file)
@@ -80,7 +80,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
        for (i = 0; i < Natts_pg_type; ++i)
        {
                nulls[i] = false;
-               values[i] = (Datum) NULL;       /* redundant, but safe */
+               values[i] = (Datum) 0;  /* redundant, but safe */
        }
 
        /*
index ecb2e4ccaa1ca281bc5d9f687c6a9d5281518c47..50fcd0237768e3c74e18203886062eb766796dd6 100644 (file)
@@ -1258,7 +1258,7 @@ SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
        {
                SPI_result = SPI_ERROR_NOATTRIBUTE;
                *isnull = true;
-               return (Datum) NULL;
+               return (Datum) 0;
        }
 
        return heap_getattr(tuple, fnumber, tupdesc, isnull);
index 48b5d13b9b62c121a11ef31e57d8b79ff977286e..2f933e95cb95e949e69455a80df69eac0b2f5419 100644 (file)
@@ -630,7 +630,7 @@ readDatum(bool typbyval)
                }
        }
        else if (length <= 0)
-               res = (Datum) NULL;
+               res = (Datum) 0;
        else
        {
                s = (char *) palloc(length);
index 370456408bfba41dd4004cd8a2c27eb361a2c519..c5e1a027956bc2d236d33241307497cd9f4168cc 100644 (file)
@@ -2027,7 +2027,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
                                {
                                        /* a json null is an sql null in text mode */
                                        nulls[1] = true;
-                                       values[1] = (Datum) NULL;
+                                       values[1] = (Datum) 0;
                                }
                                else
                                        values[1] = PointerGetDatum(JsonbValueAsText(&v));
@@ -2266,7 +2266,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname,
                                {
                                        /* a json null is an sql null in text mode */
                                        nulls[0] = true;
-                                       values[0] = (Datum) NULL;
+                                       values[0] = (Datum) 0;
                                }
                                else
                                        values[0] = PointerGetDatum(JsonbValueAsText(&v));
@@ -2389,7 +2389,7 @@ elements_array_element_end(void *state, bool isnull)
        if (isnull && _state->normalize_results)
        {
                nulls[0] = true;
-               values[0] = (Datum) NULL;
+               values[0] = (Datum) 0;
        }
        else if (_state->next_scalar)
        {
index 15398c72ea00483d00ff75eab5a4186a16155b5c..18e467bccd3a07313935bc90e22ce7715f9bff39 100644 (file)
@@ -1343,9 +1343,9 @@ range_fast_cmp(Datum a, Datum b, SortSupport ssup)
                        cmp = range_cmp_bounds(typcache, &upper1, &upper2);
        }
 
-       if ((Datum) range_a != a)
+       if ((Pointer) range_a != DatumGetPointer(a))
                pfree(range_a);
-       if ((Datum) range_b != b)
+       if ((Pointer) range_b != DatumGetPointer(b))
                pfree(range_b);
 
        return cmp;
index aa957cf3b0165f7530695a812bbf237633c004c5..ae813a790419e1dead6cefb855715253af0c3963 100644 (file)
@@ -884,7 +884,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
                if (att_isnull(attnum - 1, tup->t_data->t_bits))
                {
                        *isnull = true;
-                       return (Datum) NULL;
+                       return (Datum) 0;
                }
                else
                        return nocachegetattr(tup, attnum, tupleDesc);
index 7066c2a2868b370f3767b5741383c8736df25320..338e90749bd1fefdad9dbbe6aaeefd38959e774e 100644 (file)
@@ -154,7 +154,7 @@ index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
                if (att_isnull(attnum - 1, (bits8 *) tup + sizeof(IndexTupleData)))
                {
                        *isnull = true;
-                       return (Datum) NULL;
+                       return (Datum) 0;
                }
                else
                        return nocache_index_getattr(tup, attnum, tupleDesc);