Skip to content

Commit 6c90996

Browse files
committed
Add prefix to pl/pgsql global variables and functions
Rename pl/pgsql global variables to always have a plpgsql_ prefix, so they don't conflict with other shared libraries loaded.
1 parent 7c17aac commit 6c90996

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

src/pl/plpgsql/src/pl_comp.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool plpgsql_check_syntax = false;
5151
PLpgSQL_function *plpgsql_curr_compile;
5252

5353
/* A context appropriate for short-term allocs during compilation */
54-
MemoryContext compile_tmp_cxt;
54+
MemoryContext plpgsql_compile_tmp_cxt;
5555

5656
/* ----------
5757
* Hash table for compiled functions
@@ -253,7 +253,7 @@ plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator)
253253
* careful about pfree'ing their allocations, it is also wise to
254254
* switch into a short-term context before calling into the
255255
* backend. An appropriate context for performing short-term
256-
* allocations is the compile_tmp_cxt.
256+
* allocations is the plpgsql_compile_tmp_cxt.
257257
*
258258
* NB: this code is not re-entrant. We assume that nothing we do here could
259259
* result in the invocation of another plpgsql function.
@@ -343,7 +343,7 @@ do_compile(FunctionCallInfo fcinfo,
343343
ALLOCSET_DEFAULT_MINSIZE,
344344
ALLOCSET_DEFAULT_INITSIZE,
345345
ALLOCSET_DEFAULT_MAXSIZE);
346-
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
346+
plpgsql_compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
347347

348348
function->fn_signature = format_procedure(fcinfo->flinfo->fn_oid);
349349
function->fn_oid = fcinfo->flinfo->fn_oid;
@@ -387,7 +387,7 @@ do_compile(FunctionCallInfo fcinfo,
387387
* argument types. In validation mode we won't be able to, so we
388388
* arbitrarily assume we are dealing with integers.
389389
*/
390-
MemoryContextSwitchTo(compile_tmp_cxt);
390+
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
391391

392392
numargs = get_func_arg_info(procTup,
393393
&argtypes, &argnames, &argmodes);
@@ -774,8 +774,8 @@ do_compile(FunctionCallInfo fcinfo,
774774

775775
plpgsql_check_syntax = false;
776776

777-
MemoryContextSwitchTo(compile_tmp_cxt);
778-
compile_tmp_cxt = NULL;
777+
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
778+
plpgsql_compile_tmp_cxt = NULL;
779779
return function;
780780
}
781781

@@ -833,7 +833,7 @@ plpgsql_compile_inline(char *proc_source)
833833
ALLOCSET_DEFAULT_MINSIZE,
834834
ALLOCSET_DEFAULT_INITSIZE,
835835
ALLOCSET_DEFAULT_MAXSIZE);
836-
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
836+
plpgsql_compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
837837

838838
function->fn_signature = pstrdup(func_name);
839839
function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
@@ -911,8 +911,8 @@ plpgsql_compile_inline(char *proc_source)
911911

912912
plpgsql_check_syntax = false;
913913

914-
MemoryContextSwitchTo(compile_tmp_cxt);
915-
compile_tmp_cxt = NULL;
914+
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
915+
plpgsql_compile_tmp_cxt = NULL;
916916
return function;
917917
}
918918

@@ -1325,7 +1325,7 @@ make_datum_param(PLpgSQL_expr *expr, int dno, int location)
13251325
param = makeNode(Param);
13261326
param->paramkind = PARAM_EXTERN;
13271327
param->paramid = dno + 1;
1328-
exec_get_datum_type_info(estate,
1328+
plpgsql_exec_get_datum_type_info(estate,
13291329
datum,
13301330
&param->paramtype,
13311331
&param->paramtypmod,
@@ -1703,7 +1703,7 @@ plpgsql_parse_cwordtype(List *idents)
17031703
MemoryContext oldCxt;
17041704

17051705
/* Avoid memory leaks in the long-term function context */
1706-
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt);
1706+
oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
17071707

17081708
if (list_length(idents) == 2)
17091709
{
@@ -1786,7 +1786,7 @@ plpgsql_parse_cwordtype(List *idents)
17861786
dtype = build_datatype(typetup,
17871787
attrStruct->atttypmod,
17881788
attrStruct->attcollation);
1789-
MemoryContextSwitchTo(compile_tmp_cxt);
1789+
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
17901790

17911791
done:
17921792
if (HeapTupleIsValid(classtup))
@@ -1837,7 +1837,7 @@ plpgsql_parse_cwordrowtype(List *idents)
18371837
return NULL;
18381838

18391839
/* Avoid memory leaks in long-term function context */
1840-
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt);
1840+
oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
18411841

18421842
/* Look up relation name. Can't lock it - we might not have privileges. */
18431843
relvar = makeRangeVar(strVal(linitial(idents)),
@@ -2309,7 +2309,7 @@ plpgsql_start_datums(void)
23092309
datums_alloc = 128;
23102310
plpgsql_nDatums = 0;
23112311
/* This is short-lived, so needn't allocate in function's cxt */
2312-
plpgsql_Datums = MemoryContextAlloc(compile_tmp_cxt,
2312+
plpgsql_Datums = MemoryContextAlloc(plpgsql_compile_tmp_cxt,
23132313
sizeof(PLpgSQL_datum *) * datums_alloc);
23142314
/* datums_last tracks what's been seen by plpgsql_add_initdatums() */
23152315
datums_last = 0;

src/pl/plpgsql/src/pl_exec.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
423423
/*
424424
* Let the instrumentation plugin peek at this function
425425
*/
426-
if (*plugin_ptr && (*plugin_ptr)->func_beg)
427-
((*plugin_ptr)->func_beg) (&estate, func);
426+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
427+
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
428428

429429
/*
430430
* Now call the toplevel block of statements
@@ -556,8 +556,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
556556
/*
557557
* Let the instrumentation plugin peek at this function
558558
*/
559-
if (*plugin_ptr && (*plugin_ptr)->func_end)
560-
((*plugin_ptr)->func_end) (&estate, func);
559+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
560+
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
561561

562562
/* Clean up any leftover temporary memory */
563563
plpgsql_destroy_econtext(&estate);
@@ -767,8 +767,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
767767
/*
768768
* Let the instrumentation plugin peek at this function
769769
*/
770-
if (*plugin_ptr && (*plugin_ptr)->func_beg)
771-
((*plugin_ptr)->func_beg) (&estate, func);
770+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
771+
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
772772

773773
/*
774774
* Now call the toplevel block of statements
@@ -826,8 +826,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
826826
/*
827827
* Let the instrumentation plugin peek at this function
828828
*/
829-
if (*plugin_ptr && (*plugin_ptr)->func_end)
830-
((*plugin_ptr)->func_end) (&estate, func);
829+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
830+
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
831831

832832
/* Clean up any leftover temporary memory */
833833
plpgsql_destroy_econtext(&estate);
@@ -885,8 +885,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
885885
/*
886886
* Let the instrumentation plugin peek at this function
887887
*/
888-
if (*plugin_ptr && (*plugin_ptr)->func_beg)
889-
((*plugin_ptr)->func_beg) (&estate, func);
888+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
889+
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
890890

891891
/*
892892
* Now call the toplevel block of statements
@@ -909,8 +909,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
909909
/*
910910
* Let the instrumentation plugin peek at this function
911911
*/
912-
if (*plugin_ptr && (*plugin_ptr)->func_end)
913-
((*plugin_ptr)->func_end) (&estate, func);
912+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
913+
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
914914

915915
/* Clean up any leftover temporary memory */
916916
plpgsql_destroy_econtext(&estate);
@@ -1420,8 +1420,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
14201420
estate->err_stmt = stmt;
14211421

14221422
/* Let the plugin know that we are about to execute this statement */
1423-
if (*plugin_ptr && (*plugin_ptr)->stmt_beg)
1424-
((*plugin_ptr)->stmt_beg) (estate, stmt);
1423+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_beg)
1424+
((*plpgsql_plugin_ptr)->stmt_beg) (estate, stmt);
14251425

14261426
CHECK_FOR_INTERRUPTS();
14271427

@@ -1529,8 +1529,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
15291529
}
15301530

15311531
/* Let the plugin know that we have finished executing this statement */
1532-
if (*plugin_ptr && (*plugin_ptr)->stmt_end)
1533-
((*plugin_ptr)->stmt_end) (estate, stmt);
1532+
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_end)
1533+
((*plpgsql_plugin_ptr)->stmt_end) (estate, stmt);
15341534

15351535
estate->err_stmt = save_estmt;
15361536

@@ -2315,7 +2315,7 @@ exec_stmt_foreach_a(PLpgSQL_execstate *estate, PLpgSQL_stmt_foreach_a *stmt)
23152315
loop_var_elem_type = InvalidOid;
23162316
}
23172317
else
2318-
loop_var_elem_type = get_element_type(exec_get_datum_type(estate,
2318+
loop_var_elem_type = get_element_type(plpgsql_exec_get_datum_type(estate,
23192319
loop_var));
23202320

23212321
/*
@@ -3350,13 +3350,13 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
33503350
* pointers so it can call back into PL/pgSQL for doing things like
33513351
* variable assignments and stack traces
33523352
*/
3353-
if (*plugin_ptr)
3353+
if (*plpgsql_plugin_ptr)
33543354
{
3355-
(*plugin_ptr)->error_callback = plpgsql_exec_error_callback;
3356-
(*plugin_ptr)->assign_expr = exec_assign_expr;
3355+
(*plpgsql_plugin_ptr)->error_callback = plpgsql_exec_error_callback;
3356+
(*plpgsql_plugin_ptr)->assign_expr = exec_assign_expr;
33573357

3358-
if ((*plugin_ptr)->func_setup)
3359-
((*plugin_ptr)->func_setup) (estate, func);
3358+
if ((*plpgsql_plugin_ptr)->func_setup)
3359+
((*plpgsql_plugin_ptr)->func_setup) (estate, func);
33603360
}
33613361
}
33623362

@@ -4758,15 +4758,15 @@ exec_eval_datum(PLpgSQL_execstate *estate,
47584758
}
47594759

47604760
/*
4761-
* exec_get_datum_type Get datatype of a PLpgSQL_datum
4761+
* plpgsql_exec_get_datum_type Get datatype of a PLpgSQL_datum
47624762
*
47634763
* This is the same logic as in exec_eval_datum, except that it can handle
47644764
* some cases where exec_eval_datum has to fail; specifically, we may have
47654765
* a tupdesc but no row value for a record variable. (This currently can
47664766
* happen only for a trigger's NEW/OLD records.)
47674767
*/
47684768
Oid
4769-
exec_get_datum_type(PLpgSQL_execstate *estate,
4769+
plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
47704770
PLpgSQL_datum *datum)
47714771
{
47724772
Oid typeid;
@@ -4842,13 +4842,13 @@ exec_get_datum_type(PLpgSQL_execstate *estate,
48424842
}
48434843

48444844
/*
4845-
* exec_get_datum_type_info Get datatype etc of a PLpgSQL_datum
4845+
* plpgsql_exec_get_datum_type_info Get datatype etc of a PLpgSQL_datum
48464846
*
4847-
* An extended version of exec_get_datum_type, which also retrieves the
4847+
* An extended version of plpgsql_exec_get_datum_type, which also retrieves the
48484848
* typmod and collation of the datum.
48494849
*/
48504850
void
4851-
exec_get_datum_type_info(PLpgSQL_execstate *estate,
4851+
plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
48524852
PLpgSQL_datum *datum,
48534853
Oid *typeid, int32 *typmod, Oid *collation)
48544854
{

src/pl/plpgsql/src/pl_gram.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ check_sql_expr(const char *stmt, int location, int leaderlen)
35183518
syntax_errcontext.previous = error_context_stack;
35193519
error_context_stack = &syntax_errcontext;
35203520

3521-
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt);
3521+
oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
35223522
(void) raw_parser(stmt);
35233523
MemoryContextSwitchTo(oldCxt);
35243524

src/pl/plpgsql/src/pl_handler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int plpgsql_extra_warnings;
5252
int plpgsql_extra_errors;
5353

5454
/* Hook for plugins */
55-
PLpgSQL_plugin **plugin_ptr = NULL;
55+
PLpgSQL_plugin **plpgsql_plugin_ptr = NULL;
5656

5757

5858
static bool
@@ -197,7 +197,7 @@ _PG_init(void)
197197
RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
198198

199199
/* Set up a rendezvous point with optional instrumentation plugin */
200-
plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin");
200+
plpgsql_plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin");
201201

202202
inited = true;
203203
}

src/pl/plpgsql/src/plpgsql.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,9 @@ extern PLpgSQL_datum **plpgsql_Datums;
938938
extern char *plpgsql_error_funcname;
939939

940940
extern PLpgSQL_function *plpgsql_curr_compile;
941-
extern MemoryContext compile_tmp_cxt;
941+
extern MemoryContext plpgsql_compile_tmp_cxt;
942942

943-
extern PLpgSQL_plugin **plugin_ptr;
943+
extern PLpgSQL_plugin **plpgsql_plugin_ptr;
944944

945945
/**********************************************************************
946946
* Function declarations
@@ -999,9 +999,9 @@ extern void plpgsql_exec_event_trigger(PLpgSQL_function *func,
999999
extern void plpgsql_xact_cb(XactEvent event, void *arg);
10001000
extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
10011001
SubTransactionId parentSubid, void *arg);
1002-
extern Oid exec_get_datum_type(PLpgSQL_execstate *estate,
1002+
extern Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
10031003
PLpgSQL_datum *datum);
1004-
extern void exec_get_datum_type_info(PLpgSQL_execstate *estate,
1004+
extern void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
10051005
PLpgSQL_datum *datum,
10061006
Oid *typeid, int32 *typmod, Oid *collation);
10071007

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy