Commit 6c90996a authored by Magnus Hagander's avatar Magnus Hagander

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.
parent 7c17aac6
...@@ -51,7 +51,7 @@ bool plpgsql_check_syntax = false; ...@@ -51,7 +51,7 @@ bool plpgsql_check_syntax = false;
PLpgSQL_function *plpgsql_curr_compile; PLpgSQL_function *plpgsql_curr_compile;
/* A context appropriate for short-term allocs during compilation */ /* A context appropriate for short-term allocs during compilation */
MemoryContext compile_tmp_cxt; MemoryContext plpgsql_compile_tmp_cxt;
/* ---------- /* ----------
* Hash table for compiled functions * Hash table for compiled functions
...@@ -253,7 +253,7 @@ recheck: ...@@ -253,7 +253,7 @@ recheck:
* careful about pfree'ing their allocations, it is also wise to * careful about pfree'ing their allocations, it is also wise to
* switch into a short-term context before calling into the * switch into a short-term context before calling into the
* backend. An appropriate context for performing short-term * backend. An appropriate context for performing short-term
* allocations is the compile_tmp_cxt. * allocations is the plpgsql_compile_tmp_cxt.
* *
* NB: this code is not re-entrant. We assume that nothing we do here could * NB: this code is not re-entrant. We assume that nothing we do here could
* result in the invocation of another plpgsql function. * result in the invocation of another plpgsql function.
...@@ -343,7 +343,7 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -343,7 +343,7 @@ do_compile(FunctionCallInfo fcinfo,
ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt); plpgsql_compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
function->fn_signature = format_procedure(fcinfo->flinfo->fn_oid); function->fn_signature = format_procedure(fcinfo->flinfo->fn_oid);
function->fn_oid = fcinfo->flinfo->fn_oid; function->fn_oid = fcinfo->flinfo->fn_oid;
...@@ -387,7 +387,7 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -387,7 +387,7 @@ do_compile(FunctionCallInfo fcinfo,
* argument types. In validation mode we won't be able to, so we * argument types. In validation mode we won't be able to, so we
* arbitrarily assume we are dealing with integers. * arbitrarily assume we are dealing with integers.
*/ */
MemoryContextSwitchTo(compile_tmp_cxt); MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
numargs = get_func_arg_info(procTup, numargs = get_func_arg_info(procTup,
&argtypes, &argnames, &argmodes); &argtypes, &argnames, &argmodes);
...@@ -774,8 +774,8 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -774,8 +774,8 @@ do_compile(FunctionCallInfo fcinfo,
plpgsql_check_syntax = false; plpgsql_check_syntax = false;
MemoryContextSwitchTo(compile_tmp_cxt); MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
compile_tmp_cxt = NULL; plpgsql_compile_tmp_cxt = NULL;
return function; return function;
} }
...@@ -833,7 +833,7 @@ plpgsql_compile_inline(char *proc_source) ...@@ -833,7 +833,7 @@ plpgsql_compile_inline(char *proc_source)
ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt); plpgsql_compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
function->fn_signature = pstrdup(func_name); function->fn_signature = pstrdup(func_name);
function->fn_is_trigger = PLPGSQL_NOT_TRIGGER; function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
...@@ -911,8 +911,8 @@ plpgsql_compile_inline(char *proc_source) ...@@ -911,8 +911,8 @@ plpgsql_compile_inline(char *proc_source)
plpgsql_check_syntax = false; plpgsql_check_syntax = false;
MemoryContextSwitchTo(compile_tmp_cxt); MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
compile_tmp_cxt = NULL; plpgsql_compile_tmp_cxt = NULL;
return function; return function;
} }
...@@ -1325,7 +1325,7 @@ make_datum_param(PLpgSQL_expr *expr, int dno, int location) ...@@ -1325,7 +1325,7 @@ make_datum_param(PLpgSQL_expr *expr, int dno, int location)
param = makeNode(Param); param = makeNode(Param);
param->paramkind = PARAM_EXTERN; param->paramkind = PARAM_EXTERN;
param->paramid = dno + 1; param->paramid = dno + 1;
exec_get_datum_type_info(estate, plpgsql_exec_get_datum_type_info(estate,
datum, datum,
&param->paramtype, &param->paramtype,
&param->paramtypmod, &param->paramtypmod,
...@@ -1703,7 +1703,7 @@ plpgsql_parse_cwordtype(List *idents) ...@@ -1703,7 +1703,7 @@ plpgsql_parse_cwordtype(List *idents)
MemoryContext oldCxt; MemoryContext oldCxt;
/* Avoid memory leaks in the long-term function context */ /* Avoid memory leaks in the long-term function context */
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt); oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
if (list_length(idents) == 2) if (list_length(idents) == 2)
{ {
...@@ -1786,7 +1786,7 @@ plpgsql_parse_cwordtype(List *idents) ...@@ -1786,7 +1786,7 @@ plpgsql_parse_cwordtype(List *idents)
dtype = build_datatype(typetup, dtype = build_datatype(typetup,
attrStruct->atttypmod, attrStruct->atttypmod,
attrStruct->attcollation); attrStruct->attcollation);
MemoryContextSwitchTo(compile_tmp_cxt); MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
done: done:
if (HeapTupleIsValid(classtup)) if (HeapTupleIsValid(classtup))
...@@ -1837,7 +1837,7 @@ plpgsql_parse_cwordrowtype(List *idents) ...@@ -1837,7 +1837,7 @@ plpgsql_parse_cwordrowtype(List *idents)
return NULL; return NULL;
/* Avoid memory leaks in long-term function context */ /* Avoid memory leaks in long-term function context */
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt); oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
/* Look up relation name. Can't lock it - we might not have privileges. */ /* Look up relation name. Can't lock it - we might not have privileges. */
relvar = makeRangeVar(strVal(linitial(idents)), relvar = makeRangeVar(strVal(linitial(idents)),
...@@ -2309,7 +2309,7 @@ plpgsql_start_datums(void) ...@@ -2309,7 +2309,7 @@ plpgsql_start_datums(void)
datums_alloc = 128; datums_alloc = 128;
plpgsql_nDatums = 0; plpgsql_nDatums = 0;
/* This is short-lived, so needn't allocate in function's cxt */ /* This is short-lived, so needn't allocate in function's cxt */
plpgsql_Datums = MemoryContextAlloc(compile_tmp_cxt, plpgsql_Datums = MemoryContextAlloc(plpgsql_compile_tmp_cxt,
sizeof(PLpgSQL_datum *) * datums_alloc); sizeof(PLpgSQL_datum *) * datums_alloc);
/* datums_last tracks what's been seen by plpgsql_add_initdatums() */ /* datums_last tracks what's been seen by plpgsql_add_initdatums() */
datums_last = 0; datums_last = 0;
......
...@@ -423,8 +423,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo, ...@@ -423,8 +423,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_beg) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func); ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/* /*
* Now call the toplevel block of statements * Now call the toplevel block of statements
...@@ -556,8 +556,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo, ...@@ -556,8 +556,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_end) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func); ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */ /* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate); plpgsql_destroy_econtext(&estate);
...@@ -767,8 +767,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func, ...@@ -767,8 +767,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_beg) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func); ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/* /*
* Now call the toplevel block of statements * Now call the toplevel block of statements
...@@ -826,8 +826,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func, ...@@ -826,8 +826,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_end) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func); ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */ /* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate); plpgsql_destroy_econtext(&estate);
...@@ -885,8 +885,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata) ...@@ -885,8 +885,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_beg) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func); ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/* /*
* Now call the toplevel block of statements * Now call the toplevel block of statements
...@@ -909,8 +909,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata) ...@@ -909,8 +909,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
/* /*
* Let the instrumentation plugin peek at this function * Let the instrumentation plugin peek at this function
*/ */
if (*plugin_ptr && (*plugin_ptr)->func_end) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func); ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */ /* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate); plpgsql_destroy_econtext(&estate);
...@@ -1420,8 +1420,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) ...@@ -1420,8 +1420,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
estate->err_stmt = stmt; estate->err_stmt = stmt;
/* Let the plugin know that we are about to execute this statement */ /* Let the plugin know that we are about to execute this statement */
if (*plugin_ptr && (*plugin_ptr)->stmt_beg) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_beg)
((*plugin_ptr)->stmt_beg) (estate, stmt); ((*plpgsql_plugin_ptr)->stmt_beg) (estate, stmt);
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
...@@ -1529,8 +1529,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) ...@@ -1529,8 +1529,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
} }
/* Let the plugin know that we have finished executing this statement */ /* Let the plugin know that we have finished executing this statement */
if (*plugin_ptr && (*plugin_ptr)->stmt_end) if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_end)
((*plugin_ptr)->stmt_end) (estate, stmt); ((*plpgsql_plugin_ptr)->stmt_end) (estate, stmt);
estate->err_stmt = save_estmt; estate->err_stmt = save_estmt;
...@@ -2315,7 +2315,7 @@ exec_stmt_foreach_a(PLpgSQL_execstate *estate, PLpgSQL_stmt_foreach_a *stmt) ...@@ -2315,7 +2315,7 @@ exec_stmt_foreach_a(PLpgSQL_execstate *estate, PLpgSQL_stmt_foreach_a *stmt)
loop_var_elem_type = InvalidOid; loop_var_elem_type = InvalidOid;
} }
else else
loop_var_elem_type = get_element_type(exec_get_datum_type(estate, loop_var_elem_type = get_element_type(plpgsql_exec_get_datum_type(estate,
loop_var)); loop_var));
/* /*
...@@ -3350,13 +3350,13 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate, ...@@ -3350,13 +3350,13 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
* pointers so it can call back into PL/pgSQL for doing things like * pointers so it can call back into PL/pgSQL for doing things like
* variable assignments and stack traces * variable assignments and stack traces
*/ */
if (*plugin_ptr) if (*plpgsql_plugin_ptr)
{ {
(*plugin_ptr)->error_callback = plpgsql_exec_error_callback; (*plpgsql_plugin_ptr)->error_callback = plpgsql_exec_error_callback;
(*plugin_ptr)->assign_expr = exec_assign_expr; (*plpgsql_plugin_ptr)->assign_expr = exec_assign_expr;
if ((*plugin_ptr)->func_setup) if ((*plpgsql_plugin_ptr)->func_setup)
((*plugin_ptr)->func_setup) (estate, func); ((*plpgsql_plugin_ptr)->func_setup) (estate, func);
} }
} }
...@@ -4758,7 +4758,7 @@ exec_eval_datum(PLpgSQL_execstate *estate, ...@@ -4758,7 +4758,7 @@ exec_eval_datum(PLpgSQL_execstate *estate,
} }
/* /*
* exec_get_datum_type Get datatype of a PLpgSQL_datum * plpgsql_exec_get_datum_type Get datatype of a PLpgSQL_datum
* *
* This is the same logic as in exec_eval_datum, except that it can handle * This is the same logic as in exec_eval_datum, except that it can handle
* some cases where exec_eval_datum has to fail; specifically, we may have * some cases where exec_eval_datum has to fail; specifically, we may have
...@@ -4766,7 +4766,7 @@ exec_eval_datum(PLpgSQL_execstate *estate, ...@@ -4766,7 +4766,7 @@ exec_eval_datum(PLpgSQL_execstate *estate,
* happen only for a trigger's NEW/OLD records.) * happen only for a trigger's NEW/OLD records.)
*/ */
Oid Oid
exec_get_datum_type(PLpgSQL_execstate *estate, plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum) PLpgSQL_datum *datum)
{ {
Oid typeid; Oid typeid;
...@@ -4842,13 +4842,13 @@ exec_get_datum_type(PLpgSQL_execstate *estate, ...@@ -4842,13 +4842,13 @@ exec_get_datum_type(PLpgSQL_execstate *estate,
} }
/* /*
* exec_get_datum_type_info Get datatype etc of a PLpgSQL_datum * plpgsql_exec_get_datum_type_info Get datatype etc of a PLpgSQL_datum
* *
* An extended version of exec_get_datum_type, which also retrieves the * An extended version of plpgsql_exec_get_datum_type, which also retrieves the
* typmod and collation of the datum. * typmod and collation of the datum.
*/ */
void void
exec_get_datum_type_info(PLpgSQL_execstate *estate, plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum, PLpgSQL_datum *datum,
Oid *typeid, int32 *typmod, Oid *collation) Oid *typeid, int32 *typmod, Oid *collation)
{ {
......
...@@ -3518,7 +3518,7 @@ check_sql_expr(const char *stmt, int location, int leaderlen) ...@@ -3518,7 +3518,7 @@ check_sql_expr(const char *stmt, int location, int leaderlen)
syntax_errcontext.previous = error_context_stack; syntax_errcontext.previous = error_context_stack;
error_context_stack = &syntax_errcontext; error_context_stack = &syntax_errcontext;
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt); oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
(void) raw_parser(stmt); (void) raw_parser(stmt);
MemoryContextSwitchTo(oldCxt); MemoryContextSwitchTo(oldCxt);
......
...@@ -52,7 +52,7 @@ int plpgsql_extra_warnings; ...@@ -52,7 +52,7 @@ int plpgsql_extra_warnings;
int plpgsql_extra_errors; int plpgsql_extra_errors;
/* Hook for plugins */ /* Hook for plugins */
PLpgSQL_plugin **plugin_ptr = NULL; PLpgSQL_plugin **plpgsql_plugin_ptr = NULL;
static bool static bool
...@@ -197,7 +197,7 @@ _PG_init(void) ...@@ -197,7 +197,7 @@ _PG_init(void)
RegisterSubXactCallback(plpgsql_subxact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
/* Set up a rendezvous point with optional instrumentation plugin */ /* Set up a rendezvous point with optional instrumentation plugin */
plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); plpgsql_plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin");
inited = true; inited = true;
} }
......
...@@ -938,9 +938,9 @@ extern PLpgSQL_datum **plpgsql_Datums; ...@@ -938,9 +938,9 @@ extern PLpgSQL_datum **plpgsql_Datums;
extern char *plpgsql_error_funcname; extern char *plpgsql_error_funcname;
extern PLpgSQL_function *plpgsql_curr_compile; extern PLpgSQL_function *plpgsql_curr_compile;
extern MemoryContext compile_tmp_cxt; extern MemoryContext plpgsql_compile_tmp_cxt;
extern PLpgSQL_plugin **plugin_ptr; extern PLpgSQL_plugin **plpgsql_plugin_ptr;
/********************************************************************** /**********************************************************************
* Function declarations * Function declarations
...@@ -999,9 +999,9 @@ extern void plpgsql_exec_event_trigger(PLpgSQL_function *func, ...@@ -999,9 +999,9 @@ extern void plpgsql_exec_event_trigger(PLpgSQL_function *func,
extern void plpgsql_xact_cb(XactEvent event, void *arg); extern void plpgsql_xact_cb(XactEvent event, void *arg);
extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
SubTransactionId parentSubid, void *arg); SubTransactionId parentSubid, void *arg);
extern Oid exec_get_datum_type(PLpgSQL_execstate *estate, extern Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum); PLpgSQL_datum *datum);
extern void exec_get_datum_type_info(PLpgSQL_execstate *estate, extern void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum, PLpgSQL_datum *datum,
Oid *typeid, int32 *typmod, Oid *collation); Oid *typeid, int32 *typmod, Oid *collation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment