postgres.git / summary / log / commit / refs
commit 5767fece95ccb58c25cee0567dd83457b8e15b37
Author: Peter Eisentraut <peter@eisentraut.org>
Date: Tue Aug 25 08:26:50 2026 +0000
Change InputFunctionCall* to take a const char *str
It's reasonable to specify that the input string passed to these
functions isn't modified.
In each case, the input string is passed down to CStringGetDatum(),
which already takes a const char *, so this change just pushes that
API specification one level up.
A couple of callers benefit from this by no longer having to cast away
a const qualifier.
A few more functions that call input functions internally are changed
so that they can now offer a const qualified input string to their
callers.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/459217ca-3840-4452-8cd1-8f9b47e8d479%40eisentraut.org
contrib/postgres_fdw/postgres_fdw.c | 4 ++--
src/backend/bootstrap/bootstrap.c | 6 +++---
src/backend/parser/parse_type.c | 2 +-
src/backend/statistics/extended_stats_funcs.c | 2 +-
src/backend/utils/adt/domains.c | 2 +-
src/backend/utils/adt/rowtypes.c | 2 +-
src/backend/utils/fmgr/fmgr.c | 8 ++++----
src/include/bootstrap/bootstrap.h | 2 +-
src/include/fmgr.h | 8 ++++----
src/include/parser/parse_type.h | 2 +-
10 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index b330cfb46a2..709c0d91812 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -6438,7 +6438,7 @@ set_floatarr_arg(NullableDatum *arg, const char *s)
Datum val;
fmgr_info(F_ARRAY_IN, &flinfo);
- val = InputFunctionCall(&flinfo, (char *) s, FLOAT4OID, -1);
+ val = InputFunctionCall(&flinfo, s, FLOAT4OID, -1);
arg->value = val;
arg->isnull = false;
@@ -8941,7 +8941,7 @@ make_tuple_from_result_row(PGresult *res,
foreach(lc, retrieved_attrs)
{
int i = lfirst_int(lc);
- char *valstr;
+ const char *valstr;
/* fetch next column's textual value */
if (PQgetisnull(res, row, j))
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index a678f345230..63e4d71b96b 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -51,7 +51,7 @@
static void CheckerModeMain(void);
static void bootstrap_signals(void);
static Form_pg_attribute AllocateAttribute(void);
-static void InsertOneProargdefaultsValue(char *value);
+static void InsertOneProargdefaultsValue(const char *value);
static void populate_typ_list(void);
static Oid gettype(char *type);
static void cleanup(void);
@@ -698,7 +698,7 @@ InsertOneTuple(void)
* ----------------
*/
void
-InsertOneValue(char *value, int i)
+InsertOneValue(const char *value, int i)
{
Form_pg_attribute attr;
Oid typoid;
@@ -765,7 +765,7 @@ InsertOneValue(char *value, int i)
* ----------------
*/
static void
-InsertOneProargdefaultsValue(char *value)
+InsertOneProargdefaultsValue(const char *value)
{
int pronargs;
oidvector *proargtypes;
diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c
index bb7eccde9fd..262f2742b02 100644
--- a/src/backend/parser/parse_type.c
+++ b/src/backend/parser/parse_type.c
@@ -651,7 +651,7 @@ typeTypeCollation(Type typ)
* (which might result in failure, if the input function rejects NULLs).
*/
Datum
-stringTypeDatum(Type tp, char *string, int32 atttypmod)
+stringTypeDatum(Type tp, const char *string, int32 atttypmod)
{
Form_pg_type typform = (Form_pg_type) GETSTRUCT(tp);
Oid typinput = typform->typinput;
diff --git a/src/backend/statistics/extended_stats_funcs.c b/src/backend/statistics/extended_stats_funcs.c
index a3e56933b91..988f81c6be4 100644
--- a/src/backend/statistics/extended_stats_funcs.c
+++ b/src/backend/statistics/extended_stats_funcs.c
@@ -1059,7 +1059,7 @@ array_in_safe(FmgrInfo *array_in, const char *s, Oid typid, int32 typmod,
* Overwriting the existing hint (if any) is not ideal, and an error
* context would only work for level >= ERROR.
*/
- if (!InputFunctionCallSafe(array_in, (char *) s, typid, typmod,
+ if (!InputFunctionCallSafe(array_in, s, typid, typmod,
(Node *) &escontext, &result))
{
StringInfoData hint_str;
diff --git a/src/backend/utils/adt/domains.c b/src/backend/utils/adt/domains.c
index 50cd257e0bf..331439046a8 100644
--- a/src/backend/utils/adt/domains.c
+++ b/src/backend/utils/adt/domains.c
@@ -226,7 +226,7 @@ fail:
Datum
domain_in(PG_FUNCTION_ARGS)
{
- char *string;
+ const char *string;
Oid domainType;
Node *escontext = fcinfo->context;
DomainIOData *my_extra;
diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c
index d94989ad116..0da0f10c2a0 100644
--- a/src/backend/utils/adt/rowtypes.c
+++ b/src/backend/utils/adt/rowtypes.c
@@ -167,7 +167,7 @@ record_in(PG_FUNCTION_ARGS)
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
ColumnIOData *column_info = &my_extra->columns[i];
Oid column_type = att->atttypid;
- char *column_data;
+ const char *column_data;
/* Ignore dropped columns in datatype, but fill with nulls */
if (att->attisdropped)
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index bfeceb7a92f..b2fd6dbb73d 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1529,7 +1529,7 @@ OidFunctionCall9Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2,
* the same as FunctionCall3.
*/
Datum
-InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
+InputFunctionCall(FmgrInfo *flinfo, const char *str, Oid typioparam, int32 typmod)
{
LOCAL_FCINFO(fcinfo, 3);
Datum result;
@@ -1583,7 +1583,7 @@ InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
* InputFunctionCall; the result will always be true if control returns.
*/
bool
-InputFunctionCallSafe(FmgrInfo *flinfo, char *str,
+InputFunctionCallSafe(FmgrInfo *flinfo, const char *str,
Oid typioparam, int32 typmod,
Node *escontext,
Datum *result)
@@ -1638,7 +1638,7 @@ InputFunctionCallSafe(FmgrInfo *flinfo, char *str,
* look at FmgrInfo, since there won't be any.
*/
bool
-DirectInputFunctionCallSafe(PGFunction func, char *str,
+DirectInputFunctionCallSafe(PGFunction func, const char *str,
Oid typioparam, int32 typmod,
Node *escontext,
Datum *result)
@@ -1752,7 +1752,7 @@ SendFunctionCall(FmgrInfo *flinfo, Datum val)
* in seldom-executed code paths. They are not only slow but leak memory.
*/
Datum
-OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
+OidInputFunctionCall(Oid functionId, const char *str, Oid typioparam, int32 typmod)
{
FmgrInfo flinfo;
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index c0bba03a5ee..165eb03de2e 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -41,7 +41,7 @@ extern void boot_openrel(char *relname);
extern void DefineAttr(char *name, char *type, int attnum, int nullness);
extern void InsertOneTuple(void);
-extern void InsertOneValue(char *value, int i);
+extern void InsertOneValue(const char *value, int i);
extern void InsertOneNull(int i);
extern void index_register(Oid heap, Oid ind, const IndexInfo *indexInfo);
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 38e143ac670..04b7914095f 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -744,17 +744,17 @@ extern Datum OidFunctionCall9Coll(Oid functionId, Oid collation,
/* Special cases for convenient invocation of datatype I/O functions. */
-extern Datum InputFunctionCall(FmgrInfo *flinfo, char *str,
+extern Datum InputFunctionCall(FmgrInfo *flinfo, const char *str,
Oid typioparam, int32 typmod);
-extern bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str,
+extern bool InputFunctionCallSafe(FmgrInfo *flinfo, const char *str,
Oid typioparam, int32 typmod,
Node *escontext,
Datum *result);
-extern bool DirectInputFunctionCallSafe(PGFunction func, char *str,
+extern bool DirectInputFunctionCallSafe(PGFunction func, const char *str,
Oid typioparam, int32 typmod,
Node *escontext,
Datum *result);
-extern Datum OidInputFunctionCall(Oid functionId, char *str,
+extern Datum OidInputFunctionCall(Oid functionId, const char *str,
Oid typioparam, int32 typmod);
extern char *OutputFunctionCall(FmgrInfo *flinfo, Datum val);
extern char *OidOutputFunctionCall(Oid functionId, Datum val);
diff --git a/src/include/parser/parse_type.h b/src/include/parser/parse_type.h
index a335807b0b0..79f10b5b5b2 100644
--- a/src/include/parser/parse_type.h
+++ b/src/include/parser/parse_type.h
@@ -46,7 +46,7 @@ extern bool typeByVal(Type t);
extern char *typeTypeName(Type t);
extern Oid typeTypeRelid(Type typ);
extern Oid typeTypeCollation(Type typ);
-extern Datum stringTypeDatum(Type tp, char *string, int32 atttypmod);
+extern Datum stringTypeDatum(Type tp, const char *string, int32 atttypmod);
extern Oid typeidTypeRelid(Oid type_id);
extern Oid typeOrDomainTypeRelid(Oid type_id);
[parent: e58994c30199]