Commit de3c2d6e authored by Tom Lane's avatar Tom Lane

Revert "Factor out functions responsible for caching I/O routines".

This reverts commit 740e54ca, which seems
to have tickled an optimization bug in gcc 4.5.x, as reported upstream at
https://bugzilla.redhat.com/show_bug.cgi?id=671899
Since this patch had no purpose beyond code beautification, it's not
worth expending a lot of effort to look for another workaround.
parent 10e99f15
......@@ -1361,15 +1361,57 @@ PLy_procedure_get(Oid fn_oid, bool is_trigger)
}
/*
* Set up output conversion functions for a procedure
* Create a new PLyProcedure structure
*/
static void
PLy_procedure_output_conversion(PLyProcedure *proc, Form_pg_proc procStruct)
static PLyProcedure *
PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
{
char procName[NAMEDATALEN + 256];
Form_pg_proc procStruct;
PLyProcedure *volatile proc;
char *volatile procSource = NULL;
Datum prosrcdatum;
bool isnull;
int i,
rv;
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
rv = snprintf(procName, sizeof(procName),
"__plpython_procedure_%s_%u",
NameStr(procStruct->proname),
fn_oid);
if (rv >= sizeof(procName) || rv < 0)
elog(ERROR, "procedure name would overrun buffer");
proc = PLy_malloc(sizeof(PLyProcedure));
proc->proname = PLy_strdup(NameStr(procStruct->proname));
proc->pyname = PLy_strdup(procName);
proc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
proc->fn_tid = procTup->t_self;
/* Remember if function is STABLE/IMMUTABLE */
proc->fn_readonly =
(procStruct->provolatile != PROVOLATILE_VOLATILE);
PLy_typeinfo_init(&proc->result);
for (i = 0; i < FUNC_MAX_ARGS; i++)
PLy_typeinfo_init(&proc->args[i]);
proc->nargs = 0;
proc->code = proc->statics = NULL;
proc->globals = NULL;
proc->is_setof = procStruct->proretset;
proc->setof = NULL;
proc->argnames = NULL;
PG_TRY();
{
/*
* get information required for output conversion of the return value,
* but only if this isn't a trigger.
*/
if (!is_trigger)
{
HeapTuple rvTypeTup;
Form_pg_type rvTypeStruct;
/* Get the return type */
rvTypeTup = SearchSysCache1(TYPEOID,
ObjectIdGetDatum(procStruct->prorettype));
if (!HeapTupleIsValid(rvTypeTup))
......@@ -1402,21 +1444,20 @@ PLy_procedure_output_conversion(PLyProcedure *proc, Form_pg_proc procStruct)
proc->result.is_rowtype = 2;
}
else
{
/* Do the real work */
PLy_output_datum_func(&proc->result, rvTypeTup);
}
ReleaseSysCache(rvTypeTup);
}
}
/*
* Set up output conversion functions for a procedure
/*
* Now get information required for input conversion of the
* procedure's arguments. Note that we ignore output arguments here
* --- since we don't support returning record, and that was already
* checked above, there's no need to worry about multiple output
* arguments.
*/
static void
PLy_procedure_input_conversion(PLyProcedure *proc, HeapTuple procTup,
Form_pg_proc procStruct)
{
if (procStruct->pronargs)
{
Oid *types;
char **names,
*modes;
......@@ -1424,10 +1465,10 @@ PLy_procedure_input_conversion(PLyProcedure *proc, HeapTuple procTup,
pos,
total;
/* Extract argument type info from the pg_proc tuple */
/* extract argument type info from the pg_proc tuple */
total = get_func_arg_info(procTup, &types, &names, &modes);
/* Count number of in+inout args into proc->nargs */
/* count number of in+inout args into proc->nargs */
if (modes == NULL)
proc->nargs = total;
else
......@@ -1460,7 +1501,7 @@ PLy_procedure_input_conversion(PLyProcedure *proc, HeapTuple procTup,
elog(ERROR, "cache lookup failed for type %u", types[i]);
argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup);
/* Check argument type is OK, set up I/O function info */
/* check argument type is OK, set up I/O function info */
switch (argTypeStruct->typtype)
{
case TYPTYPE_PSEUDO:
......@@ -1471,7 +1512,7 @@ PLy_procedure_input_conversion(PLyProcedure *proc, HeapTuple procTup,
format_type_be(types[i]))));
break;
case TYPTYPE_COMPOSITE:
/* We'll set IO funcs at first call */
/* we'll set IO funcs at first call */
proc->args[pos].is_rowtype = 2;
break;
default:
......@@ -1481,74 +1522,14 @@ PLy_procedure_input_conversion(PLyProcedure *proc, HeapTuple procTup,
break;
}
/* Get argument name */
/* get argument name */
proc->argnames[pos] = names ? PLy_strdup(names[i]) : NULL;
ReleaseSysCache(argTypeTup);
pos++;
}
}
/*
* Create a new PLyProcedure structure
*/
static PLyProcedure *
PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
{
char procName[NAMEDATALEN + 256];
Form_pg_proc procStruct;
PLyProcedure *volatile proc;
char *volatile procSource = NULL;
Datum prosrcdatum;
bool isnull;
int i,
rv;
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
rv = snprintf(procName, sizeof(procName),
"__plpython_procedure_%s_%u",
NameStr(procStruct->proname),
fn_oid);
if (rv >= sizeof(procName) || rv < 0)
elog(ERROR, "procedure name would overrun buffer");
proc = PLy_malloc(sizeof(PLyProcedure));
proc->proname = PLy_strdup(NameStr(procStruct->proname));
proc->pyname = PLy_strdup(procName);
proc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
proc->fn_tid = procTup->t_self;
/* Remember if function is STABLE/IMMUTABLE */
proc->fn_readonly =
(procStruct->provolatile != PROVOLATILE_VOLATILE);
PLy_typeinfo_init(&proc->result);
for (i = 0; i < FUNC_MAX_ARGS; i++)
PLy_typeinfo_init(&proc->args[i]);
proc->nargs = 0;
proc->code = proc->statics = NULL;
proc->globals = NULL;
proc->is_setof = procStruct->proretset;
proc->setof = NULL;
proc->argnames = NULL;
PG_TRY();
{
/*
* get information required for output conversion of the return value,
* but only if this isn't a trigger.
*/
if (!is_trigger)
PLy_procedure_output_conversion(proc, procStruct);
/*
* Now get information required for input conversion of the
* procedure's arguments. Note that we ignore output arguments here
* --- since we don't support returning record, and that was already
* checked above, there's no need to worry about multiple output
* arguments.
*/
if (procStruct->pronargs)
PLy_procedure_input_conversion(proc, procTup, procStruct);
}
/*
* get the text of the function.
......
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