1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-21 10:42:50 +03:00

Rearrange use of plpgsql_add_initdatums() so that only the parsing of a

DECLARE section needs to know about it.  Formerly, everyplace besides DECLARE
that created variables needed to do "plpgsql_add_initdatums(NULL)" to prevent
those variables from being sucked up as part of a subsequent DECLARE block.
This is obviously error-prone, and in fact the SQLSTATE/SQLERRM patch had
failed to do it for those two variables, leading to the bug recently exhibited
by Asif Ali Rehman: a DECLARE within an exception handler tried to reinitialize
SQLERRM.

Although the SQLSTATE/SQLERRM patch isn't in any pre-8.1 branches, and so
I can't point to a demonstrable failure there, it seems wise to back-patch
this into the older branches anyway, just to keep the logic similar to HEAD.
This commit is contained in:
Tom Lane
2007-02-08 18:38:03 +00:00
parent dc80902bcc
commit 3e94cf51d7
2 changed files with 17 additions and 17 deletions

View File

@@ -4,7 +4,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.64.4.4 2006/05/21 19:57:39 momjian Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.64.4.5 2007/02/08 18:38:03 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@@ -276,7 +276,6 @@ decl_sect : opt_label
$$.label = $1; $$.label = $1;
$$.n_initvars = 0; $$.n_initvars = 0;
$$.initvarnos = NULL; $$.initvarnos = NULL;
plpgsql_add_initdatums(NULL);
} }
| opt_label decl_start | opt_label decl_start
{ {
@@ -284,7 +283,6 @@ decl_sect : opt_label
$$.label = $1; $$.label = $1;
$$.n_initvars = 0; $$.n_initvars = 0;
$$.initvarnos = NULL; $$.initvarnos = NULL;
plpgsql_add_initdatums(NULL);
} }
| opt_label decl_start decl_stmts | opt_label decl_start decl_stmts
{ {
@@ -293,12 +291,16 @@ decl_sect : opt_label
$$.label = $3; $$.label = $3;
else else
$$.label = $1; $$.label = $1;
/* Remember variables declared in decl_stmts */
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos)); $$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
} }
; ;
decl_start : K_DECLARE decl_start : K_DECLARE
{ {
/* Forget any variables created before block */
plpgsql_add_initdatums(NULL);
/* Make variable names be local to block */
plpgsql_ns_setlocal(true); plpgsql_ns_setlocal(true);
} }
; ;
@@ -986,9 +988,6 @@ for_control : lno for_variable K_IN
-1), -1),
true); true);
/* put the for-variable into the local block */
plpgsql_add_initdatums(NULL);
new = malloc(sizeof(PLpgSQL_stmt_fori)); new = malloc(sizeof(PLpgSQL_stmt_fori));
memset(new, 0, sizeof(PLpgSQL_stmt_fori)); memset(new, 0, sizeof(PLpgSQL_stmt_fori));

View File

@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.83 2004/11/30 03:50:29 neilc Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.83.4.1 2007/02/08 18:38:03 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@@ -589,11 +589,6 @@ do_compile(FunctionCallInfo fcinfo,
true); true);
function->found_varno = var->dno; function->found_varno = var->dno;
/*
* Forget about the above created variables
*/
plpgsql_add_initdatums(NULL);
/* /*
* Now parse the function's text * Now parse the function's text
*/ */
@@ -1806,11 +1801,17 @@ plpgsql_adddatum(PLpgSQL_datum *new)
/* ---------- /* ----------
* plpgsql_add_initdatums Put all datum entries created * plpgsql_add_initdatums Make an array of the datum numbers of
* since the last call into the * all the simple VAR datums created since the last call
* finishing code block so the * to this function.
* block knows which variables to *
* reinitialize when entered. * If varnos is NULL, we just forget any datum entries created since the
* last call.
*
* This is used around a DECLARE section to create a list of the VARs
* that have to be initialized at block entry. Note that VARs can also
* be created elsewhere than DECLARE, eg by a FOR-loop, but it is then
* the responsibility of special-purpose code to initialize them.
* ---------- * ----------
*/ */
int int