summaryrefslogtreecommitdiff
path: root/src/pl
diff options
context:
space:
mode:
authorTom Lane2024-09-09 16:18:32 +0000
committerTom Lane2024-09-09 16:18:34 +0000
commit218527d01456b65decdc7596c6f6d5ac2bdeb78b (patch)
tree6aceaaac941dd92421d0a16dd65ded4426f421d0 /src/pl
parentcdb6b0fdb0b2face270406905d31f8f513b015cc (diff)
Don't bother checking the result of SPI_connect[_ext] anymore.
SPI_connect/SPI_connect_ext have not returned any value other than SPI_OK_CONNECT since commit 1833f1a1c in v10; any errors are thrown via ereport. (The most likely failure is out-of-memory, which has always been thrown that way, so callers had better be prepared for such errors.) This makes it somewhat pointless to check these functions' result, and some callers within our code haven't been bothering; indeed, the only usage example within spi.sgml doesn't bother. So it's likely that the omission has propagated into extensions too. Hence, let's standardize on not checking, and document the return value as historical, while not actually changing these functions' behavior. (The original proposal was to change their return type to "void", but that would needlessly break extensions that are conforming to the old practice.) This saves a small amount of boilerplate code in a lot of places. Stepan Neretin Discussion: https://postgr.es/m/CAMaYL5Z9Uk8cD9qGz9QaZ2UBJFOu7jFx5Mwbznz-1tBbPDQZow@mail.gmail.com
Diffstat (limited to 'src/pl')
-rw-r--r--src/pl/plperl/plperl.c12
-rw-r--r--src/pl/plpgsql/src/pl_handler.c9
-rw-r--r--src/pl/plpython/plpy_main.c6
-rw-r--r--src/pl/tcl/pltcl.c9
4 files changed, 12 insertions, 24 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index d68ad7be345..fe719935c67 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1947,8 +1947,7 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
current_call_data = &this_call_data;
- if (SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC) != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC);
select_perl_context(desc.lanpltrusted);
@@ -2412,8 +2411,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
IsA(fcinfo->context, CallContext) &&
!castNode(CallContext, fcinfo->context)->atomic;
- if (SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0) != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0);
prodesc = compile_plperl_function(fcinfo->flinfo->fn_oid, false, false);
current_call_data->prodesc = prodesc;
@@ -2530,8 +2528,7 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
int rc PG_USED_FOR_ASSERTS_ONLY;
/* Connect to SPI manager */
- if (SPI_connect() != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect();
/* Make transition tables visible to this SPI connection */
tdata = (TriggerData *) fcinfo->context;
@@ -2638,8 +2635,7 @@ plperl_event_trigger_handler(PG_FUNCTION_ARGS)
ErrorContextCallback pl_error_context;
/* Connect to SPI manager */
- if (SPI_connect() != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect();
/* Find or compile the function */
prodesc = compile_plperl_function(fcinfo->flinfo->fn_oid, false, true);
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 980f0961bc8..adfbbc8a7b7 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -235,8 +235,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS)
/*
* Connect to SPI manager
*/
- if ((rc = SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0)) != SPI_OK_CONNECT)
- elog(ERROR, "SPI_connect failed: %s", SPI_result_code_string(rc));
+ SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0);
/* Find or compile the function */
func = plpgsql_compile(fcinfo, false);
@@ -326,8 +325,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
/*
* Connect to SPI manager
*/
- if ((rc = SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC)) != SPI_OK_CONNECT)
- elog(ERROR, "SPI_connect failed: %s", SPI_result_code_string(rc));
+ SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC);
/* Compile the anonymous code block */
func = plpgsql_compile_inline(codeblock->source_text);
@@ -510,8 +508,7 @@ plpgsql_validator(PG_FUNCTION_ARGS)
/*
* Connect to SPI manager (is this needed for compilation?)
*/
- if ((rc = SPI_connect()) != SPI_OK_CONNECT)
- elog(ERROR, "SPI_connect failed: %s", SPI_result_code_string(rc));
+ SPI_connect();
/*
* Set up a fake fcinfo with just enough info to satisfy
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 010a97378c9..8117e20efa2 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -202,8 +202,7 @@ plpython3_call_handler(PG_FUNCTION_ARGS)
!castNode(CallContext, fcinfo->context)->atomic;
/* Note: SPI_finish() happens in plpy_exec.c, which is dubious design */
- if (SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0) != SPI_OK_CONNECT)
- elog(ERROR, "SPI_connect failed");
+ SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0);
/*
* Push execution context onto stack. It is important that this get
@@ -272,8 +271,7 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
PLy_initialize();
/* Note: SPI_finish() happens in plpy_exec.c, which is dubious design */
- if (SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC) != SPI_OK_CONNECT)
- elog(ERROR, "SPI_connect failed");
+ SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC);
MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
MemSet(&flinfo, 0, sizeof(flinfo));
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 21b2b045933..e2ccaa84f3f 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -808,8 +808,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS, pltcl_call_state *call_state,
!castNode(CallContext, fcinfo->context)->atomic;
/* Connect to SPI manager */
- if (SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0) != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect_ext(nonatomic ? SPI_OPT_NONATOMIC : 0);
/* Find or compile the function */
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid, InvalidOid,
@@ -1072,8 +1071,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, pltcl_call_state *call_state,
call_state->trigdata = trigdata;
/* Connect to SPI manager */
- if (SPI_connect() != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect();
/* Make transition tables visible to this SPI connection */
rc = SPI_register_trigger_data(trigdata);
@@ -1321,8 +1319,7 @@ pltcl_event_trigger_handler(PG_FUNCTION_ARGS, pltcl_call_state *call_state,
int tcl_rc;
/* Connect to SPI manager */
- if (SPI_connect() != SPI_OK_CONNECT)
- elog(ERROR, "could not connect to SPI manager");
+ SPI_connect();
/* Find or compile the function */
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid,