From 8a27d418f8fc08b62f371c1b167efbfbf0a2a24e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 31 Oct 2025 10:45:02 +0100 Subject: 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 Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2msfT0knvzUa72ZBwu9LR_RLY4on85w2a9YpE-o2By5HQ@mail.gmail.com --- src/backend/utils/adt/jsonfuncs.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/backend/utils/adt/jsonfuncs.c') diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index c5e1a027956..41862872e8a 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -477,16 +477,16 @@ static Datum populate_domain(DomainIOData *io, Oid typid, const char *colname, /* functions supporting jsonb_delete, jsonb_set and jsonb_concat */ static JsonbValue *IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, JsonbParseState **state); -static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems, - bool *path_nulls, int path_len, +static JsonbValue *setPath(JsonbIterator **it, const Datum *path_elems, + const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, int op_type); -static void setPathObject(JsonbIterator **it, Datum *path_elems, - bool *path_nulls, int path_len, JsonbParseState **st, +static void setPathObject(JsonbIterator **it, const Datum *path_elems, + const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 npairs, int op_type); -static void setPathArray(JsonbIterator **it, Datum *path_elems, - bool *path_nulls, int path_len, JsonbParseState **st, +static void setPathArray(JsonbIterator **it, const Datum *path_elems, + const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 nelems, int op_type); @@ -1528,7 +1528,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text) } Datum -jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text) +jsonb_get_element(Jsonb *jb, const Datum *path, int npath, bool *isnull, bool as_text) { JsonbContainer *container = &jb->root; JsonbValue *jbvp = NULL; @@ -1676,7 +1676,7 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text) } Datum -jsonb_set_element(Jsonb *jb, Datum *path, int path_len, +jsonb_set_element(Jsonb *jb, const Datum *path, int path_len, JsonbValue *newval) { JsonbValue *res; @@ -1718,8 +1718,8 @@ push_null_elements(JsonbParseState **ps, int num) * Caller is responsible to make sure such path does not exist yet. */ static void -push_path(JsonbParseState **st, int level, Datum *path_elems, - bool *path_nulls, int path_len, JsonbValue *newval) +push_path(JsonbParseState **st, int level, const Datum *path_elems, + const bool *path_nulls, int path_len, JsonbValue *newval) { /* * tpath contains expected type of an empty jsonb created at each level @@ -5201,8 +5201,8 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, * whatever bits in op_type are set, or nothing is done. */ static JsonbValue * -setPath(JsonbIterator **it, Datum *path_elems, - bool *path_nulls, int path_len, +setPath(JsonbIterator **it, const Datum *path_elems, + const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, int op_type) { JsonbValue v; @@ -5283,7 +5283,7 @@ setPath(JsonbIterator **it, Datum *path_elems, * Object walker for setPath */ static void -setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, +setPathObject(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 npairs, int op_type) { @@ -5422,7 +5422,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, * Array walker for setPath */ static void -setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, +setPathArray(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 nelems, int op_type) { -- cgit v1.2.3