8000 Rearrange use of plpgsql_add_initdatums() so that only the parsing of a · danielcode/postgres@6eb61d5 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 6eb61d5

Browse files
committed
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.
1 parent af8a424 commit 6eb61d5

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/pl/plpgsql/src/gram.y

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* procedural language
55
*
66
* IDENTIFICATION
7-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.39.2.3 2006/05/21 19:56:41 momjian Exp $
7+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.39.2.4 2007/02/08 18:38:28 tgl Exp $
88
*
99
* This software is copyrighted by Jan Wieck - Hamburg.
1010
*
@@ -263,15 +263,13 @@ decl_sect : opt_label
263263
$$.label = $1;
264264
$$.n_initvars = 0;
265265
$$.initvarnos = NULL;
266-
plpgsql_add_initdatums(NULL);
267266
}
268267
| opt_label decl_start
269268
{
270269
plpgsql_ns_setlocal(false);
271270
$$.label = $1;
272271
$$.n_initvars = 0;
273272
$$.initvarnos = NULL;
274-
plpgsql_add_initdatums(NULL);
275273
}
276274
| opt_label decl_start decl_stmts
277275
{
@@ -280,12 +278,16 @@ decl_sect : opt_label
280278
$$.label = $3;
281279
else
282280
$$.label = $1;
281+
/* Remember variables declared in decl_stmts */
283282
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
284283
}
285284
;
286285

287286
decl_start : K_DECLARE
288287
{
288+
/* Forget any variables created before block */
289+
plpgsql_add_initdatums(NULL);
290+
/* Make variable names be local to block */
289291
plpgsql_ns_setlocal(true);
290292
}
291293
;
@@ -982,8 +984,6 @@ fori_var : fori_varname
982984
plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR, new->varno,
983985
$1.name);
984986

985-
plpgsql_add_initdatums(NULL);
986-
987987
$$ = new;
988988
}
989989
;

src/pl/plpgsql/src/pl_comp.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.53.2.1 2003/01/31 00:32:00 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.53.2.2 2007/02/08 18:38:28 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -504,12 +504,7 @@ plpgsql_compile(Oid fn_oid, int functype)
504504
function->found_varno = var->varno;
505505

506506
/*
507-
* Forget about the above created variables
508-
*/
509-
plpgsql_add_initdatums(NULL);
510-
511-
/*
512-
* Now parse the functions text
507+
* Now parse the function's text
513508
*/
514509
parse_rc = plpgsql_yyparse();
515510
if (parse_rc != 0)
@@ -1477,11 +1472,17 @@ plpgsql_adddatum(PLpgSQL_datum * new)
14771472

14781473

14791474
/* ----------
1480-
* plpgsql_add_initdatums Put all datum entries created
1481-
* since the last call into the
1482-
* finishing code block so the
1483-
* block knows which variables to
1484-
* reinitialize when entered.
1475+
* plpgsql_add_initdatums Make an array of the datum numbers of
1476+
* all the simple VAR datums created since the last call
1477+
* to this function.
1478+
*
1479+
* If varnos is NULL, we just forget any datum entries created since the
1480+
* last call.
1481+
*
1482+
* This is used around a DECLARE section to create a list of the VARs
1483+
* that have to be initialized at block entry. Note that VARs can also
1484+
* be created elsewhere than DECLARE, eg by a FOR-loop, but it is then
1485+
* the responsibility of special-purpose code to initialize them.
14851486
* ----------
14861487
*/
14871488
int

0 commit comments

Comments
 (0)
0