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.
This commit is contained in:
Magnus Hagander 2016-03-03 10:45:59 +01:00
parent 7c17aac69d
commit 6c90996a4c
5 changed files with 48 additions and 48 deletions

View File

@ -51,7 +51,7 @@ bool plpgsql_check_syntax = false;
PLpgSQL_function *plpgsql_curr_compile;
/* A context appropriate for short-term allocs during compilation */
MemoryContext compile_tmp_cxt;
MemoryContext plpgsql_compile_tmp_cxt;
/* ----------
* Hash table for compiled functions
@ -253,7 +253,7 @@ recheck:
* careful about pfree'ing their allocations, it is also wise to
* switch into a short-term context before calling into the
* 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
* result in the invocation of another plpgsql function.
@ -343,7 +343,7 @@ do_compile(FunctionCallInfo fcinfo,
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
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_oid = fcinfo->flinfo->fn_oid;
@ -387,7 +387,7 @@ do_compile(FunctionCallInfo fcinfo,
* argument types. In validation mode we won't be able to, so we
* arbitrarily assume we are dealing with integers.
*/
MemoryContextSwitchTo(compile_tmp_cxt);
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
numargs = get_func_arg_info(procTup,
&argtypes, &argnames, &argmodes);
@ -774,8 +774,8 @@ do_compile(FunctionCallInfo fcinfo,
plpgsql_check_syntax = false;
MemoryContextSwitchTo(compile_tmp_cxt);
compile_tmp_cxt = NULL;
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
plpgsql_compile_tmp_cxt = NULL;
return function;
}
@ -833,7 +833,7 @@ plpgsql_compile_inline(char *proc_source)
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
plpgsql_compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
function->fn_signature = pstrdup(func_name);
function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
@ -911,8 +911,8 @@ plpgsql_compile_inline(char *proc_source)
plpgsql_check_syntax = false;
MemoryContextSwitchTo(compile_tmp_cxt);
compile_tmp_cxt = NULL;
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
plpgsql_compile_tmp_cxt = NULL;
return function;
}
@ -1325,7 +1325,7 @@ make_datum_param(PLpgSQL_expr *expr, int dno, int location)
param = makeNode(Param);
param->paramkind = PARAM_EXTERN;
param->paramid = dno + 1;
exec_get_datum_type_info(estate,
plpgsql_exec_get_datum_type_info(estate,
datum,
&param->paramtype,
&param->paramtypmod,
@ -1703,7 +1703,7 @@ plpgsql_parse_cwordtype(List *idents)
MemoryContext oldCxt;
/* 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)
{
@ -1786,7 +1786,7 @@ plpgsql_parse_cwordtype(List *idents)
dtype = build_datatype(typetup,
attrStruct->atttypmod,
attrStruct->attcollation);
MemoryContextSwitchTo(compile_tmp_cxt);
MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
done:
if (HeapTupleIsValid(classtup))
@ -1837,7 +1837,7 @@ plpgsql_parse_cwordrowtype(List *idents)
return NULL;
/* 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. */
relvar = makeRangeVar(strVal(linitial(idents)),
@ -2309,7 +2309,7 @@ plpgsql_start_datums(void)
datums_alloc = 128;
plpgsql_nDatums = 0;
/* 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);
/* datums_last tracks what's been seen by plpgsql_add_initdatums() */
datums_last = 0;

View File

@ -423,8 +423,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/*
* Now call the toplevel block of statements
@ -556,8 +556,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate);
@ -767,8 +767,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/*
* Now call the toplevel block of statements
@ -826,8 +826,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate);
@ -885,8 +885,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_beg)
((*plugin_ptr)->func_beg) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
/*
* Now call the toplevel block of statements
@ -909,8 +909,8 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
/*
* Let the instrumentation plugin peek at this function
*/
if (*plugin_ptr && (*plugin_ptr)->func_end)
((*plugin_ptr)->func_end) (&estate, func);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
((*plpgsql_plugin_ptr)->func_end) (&estate, func);
/* Clean up any leftover temporary memory */
plpgsql_destroy_econtext(&estate);
@ -1420,8 +1420,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
estate->err_stmt = stmt;
/* Let the plugin know that we are about to execute this statement */
if (*plugin_ptr && (*plugin_ptr)->stmt_beg)
((*plugin_ptr)->stmt_beg) (estate, stmt);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_beg)
((*plpgsql_plugin_ptr)->stmt_beg) (estate, stmt);
CHECK_FOR_INTERRUPTS();
@ -1529,8 +1529,8 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
}
/* Let the plugin know that we have finished executing this statement */
if (*plugin_ptr && (*plugin_ptr)->stmt_end)
((*plugin_ptr)->stmt_end) (estate, stmt);
if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->stmt_end)
((*plpgsql_plugin_ptr)->stmt_end) (estate, stmt);
estate->err_stmt = save_estmt;
@ -2315,7 +2315,7 @@ exec_stmt_foreach_a(PLpgSQL_execstate *estate, PLpgSQL_stmt_foreach_a *stmt)
loop_var_elem_type = InvalidOid;
}
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));
/*
@ -3350,13 +3350,13 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
* pointers so it can call back into PL/pgSQL for doing things like
* variable assignments and stack traces
*/
if (*plugin_ptr)
if (*plpgsql_plugin_ptr)
{
(*plugin_ptr)->error_callback = plpgsql_exec_error_callback;
(*plugin_ptr)->assign_expr = exec_assign_expr;
(*plpgsql_plugin_ptr)->error_callback = plpgsql_exec_error_callback;
(*plpgsql_plugin_ptr)->assign_expr = exec_assign_expr;
if ((*plugin_ptr)->func_setup)
((*plugin_ptr)->func_setup) (estate, func);
if ((*plpgsql_plugin_ptr)->func_setup)
((*plpgsql_plugin_ptr)->func_setup) (estate, func);
}
}
@ -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
* some cases where exec_eval_datum has to fail; specifically, we may have
@ -4766,7 +4766,7 @@ exec_eval_datum(PLpgSQL_execstate *estate,
* happen only for a trigger's NEW/OLD records.)
*/
Oid
exec_get_datum_type(PLpgSQL_execstate *estate,
plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum)
{
Oid typeid;
@ -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.
*/
void
exec_get_datum_type_info(PLpgSQL_execstate *estate,
plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum,
Oid *typeid, int32 *typmod, Oid *collation)
{

View File

@ -3518,7 +3518,7 @@ check_sql_expr(const char *stmt, int location, int leaderlen)
syntax_errcontext.previous = error_context_stack;
error_context_stack = &syntax_errcontext;
oldCxt = MemoryContextSwitchTo(compile_tmp_cxt);
oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
(void) raw_parser(stmt);
MemoryContextSwitchTo(oldCxt);

View File

@ -52,7 +52,7 @@ int plpgsql_extra_warnings;
int plpgsql_extra_errors;
/* Hook for plugins */
PLpgSQL_plugin **plugin_ptr = NULL;
PLpgSQL_plugin **plpgsql_plugin_ptr = NULL;
static bool
@ -197,7 +197,7 @@ _PG_init(void)
RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
/* 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;
}

View File

@ -938,9 +938,9 @@ extern PLpgSQL_datum **plpgsql_Datums;
extern char *plpgsql_error_funcname;
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
@ -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_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
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);
extern void exec_get_datum_type_info(PLpgSQL_execstate *estate,
extern void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
PLpgSQL_datum *datum,
Oid *typeid, int32 *typmod, Oid *collation);