[Python-checkins] python/dist/src/Python compile.c,2.234.4.7,2.234.4.8 symtable.c,2.10,2.10.6.1
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
2003年5月22日 09:43:06 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv24293/Python
Modified Files:
Tag: release22-maint
compile.c symtable.c
Log Message:
Backport fix for SF bug 734869 and sundry compiler cleanups.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.234.4.7
retrieving revision 2.234.4.8
diff -C2 -d -r2.234.4.7 -r2.234.4.8
*** compile.c 3 May 2003 10:53:51 -0000 2.234.4.7
--- compile.c 22 May 2003 16:43:03 -0000 2.234.4.8
***************
*** 562,565 ****
--- 562,566 ----
static void symtable_assign(struct symtable *, node *, int);
static void symtable_list_comprehension(struct symtable *, node *);
+ static void symtable_list_for(struct symtable *, node *);
static int symtable_update_free_vars(struct symtable *);
***************
*** 1382,1385 ****
--- 1383,1388 ----
/* listmaker: test list_for */
char tmpname[30];
+
+ REQ(n, listmaker);
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->c_tmpname);
com_addoparg(c, BUILD_LIST, 0);
***************
*** 4390,4396 ****
}
}
! if (list == NULL) /* There used to be a check here for the size of */
! return 0; /* the list being 0, which would have leaked the */
! /* list if that condition was ever possible. JRH */
/* There are cellvars that are also arguments. Create a dict
to replace cellvars and put the args at the front.
--- 4393,4399 ----
}
}
! if (list == NULL)
! return 0;
!
/* There are cellvars that are also arguments. Create a dict
to replace cellvars and put the args at the front.
***************
*** 4407,4410 ****
--- 4410,4414 ----
if (PyDict_DelItem(*cellvars, PyList_GET_ITEM(list, i)) < 0)
goto fail;
+ Py_DECREF(v);
}
pos = 0;
***************
*** 4417,4420 ****
--- 4421,4425 ----
if (PyDict_SetItem(d, v, w) < 0) {
Py_DECREF(w);
+ v = NULL;
goto fail;
}
***************
*** 4426,4429 ****
--- 4431,4435 ----
fail:
Py_DECREF(d);
+ Py_XDECREF(v);
return -1;
}
***************
*** 4689,4693 ****
st->st_nscopes = 0;
st->st_errors = 0;
- st->st_tmpname = 0;
st->st_private = NULL;
return st;
--- 4695,4698 ----
***************
*** 4733,4745 ****
int pos = 0;
! if (list)
! if (PyList_SetSlice(list, 0,
! ((PyVarObject*)list)->ob_size, 0) < 0)
return -1;
- /* Yes, the above call CAN fail, even though it's reducing
- the size of the list. The current implementation will
- allocate temp memory equal to the size of the list: this
- is avoidable in this specific case, but probably not
- worth the effort of special-casing it. - JRH */
child = (PySymtableEntryObject *)
PyList_GET_ITEM(ste->ste_children, i);
--- 4738,4744 ----
int pos = 0;
! if (list && PyList_SetSlice(list, 0,
! PyList_GET_SIZE(list), 0) < 0)
return -1;
child = (PySymtableEntryObject *)
PyList_GET_ITEM(ste->ste_children, i);
***************
*** 4891,4897 ****
prev = st->st_cur;
if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
- /* Py_DECREF(st->st_cur); */
- /* I believe the previous line would lead to a
- double-DECREF when st is disposed - JRH */
st->st_errors++;
return;
--- 4890,4893 ----
***************
*** 5155,5164 ****
goto loop;
case list_iter:
n = CHILD(n, 0);
! if (TYPE(n) == list_for) {
! st->st_tmpname++;
! symtable_list_comprehension(st, n);
! st->st_tmpname--;
! } else {
REQ(n, list_if);
symtable_node(st, CHILD(n, 1));
--- 5151,5160 ----
goto loop;
case list_iter:
+ /* only occurs when there are multiple for loops
+ in a list comprehension */
n = CHILD(n, 0);
! if (TYPE(n) == list_for)
! symtable_list_for(st, n);
! else {
REQ(n, list_if);
symtable_node(st, CHILD(n, 1));
***************
*** 5188,5195 ****
case listmaker:
if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) {
! st->st_tmpname++;
! symtable_list_comprehension(st, CHILD(n, 1));
! symtable_node(st, CHILD(n, 0));
! st->st_tmpname--;
break;
}
--- 5184,5188 ----
case listmaker:
if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) {
! symtable_list_comprehension(st, n);
break;
}
***************
*** 5230,5234 ****
/* The next two functions parse the argument tuple.
! symtable_default_arg() checks for names in the default arguments,
which are references in the defining scope. symtable_params()
parses the parameter names, which are defined in the function's
--- 5223,5227 ----
/* The next two functions parse the argument tuple.
! symtable_default_args() checks for names in the default arguments,
which are references in the defining scope. symtable_params()
parses the parameter names, which are defined in the function's
***************
*** 5389,5396 ****
symtable_list_comprehension(struct symtable *st, node *n)
{
char tmpname[30];
! PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", st->st_tmpname);
symtable_add_def(st, tmpname, DEF_LOCAL);
symtable_assign(st, CHILD(n, 1), 0);
symtable_node(st, CHILD(n, 3));
--- 5382,5402 ----
symtable_list_comprehension(struct symtable *st, node *n)
{
+ /* listmaker: test list_for */
char tmpname[30];
! REQ(n, listmaker);
! PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
! ++st->st_cur->ste_tmpname);
symtable_add_def(st, tmpname, DEF_LOCAL);
+ symtable_list_for(st, CHILD(n, 1));
+ symtable_node(st, CHILD(n, 0));
+ --st->st_cur->ste_tmpname;
+ }
+
+ static void
+ symtable_list_for(struct symtable *st, node *n)
+ {
+ REQ(n, list_for);
+ /* list_for: for v in expr [list_iter] */
symtable_assign(st, CHILD(n, 1), 0);
symtable_node(st, CHILD(n, 3));
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10
retrieving revision 2.10.6.1
diff -C2 -d -r2.10 -r2.10.6.1
*** symtable.c 10 Dec 2001 00:53:18 -0000 2.10
--- symtable.c 22 May 2003 16:43:04 -0000 2.10.6.1
***************
*** 62,65 ****
--- 62,66 ----
ste->ste_optimized = 0;
ste->ste_opt_lineno = 0;
+ ste->ste_tmpname = 0;
ste->ste_lineno = lineno;
switch (type) {