Re: vars() without parameter goes into infinite loop

Guido.van.Rossum@cwi.nl
Sat, 25 Jun 1994 09:47:51 +0200

> The subject says it all. The '_' object references itself. Is there a
> fix/remedy for this or is the solution not to use vars() without parameter?

Here's a fix that moves '_' to the built-in module. It patches
bltinmodule.c and ceval.c.

===================================================================
RCS file: /hosts/voorn/ufs/guido/python-RCS/new/Python/RCS/bltinmodule.c,v
retrieving revision 2.51.2.7
diff -c -r2.51.2.7 bltinmodule.c
*** 2.51.2.7 1994/05/03 14:51:37
--- bltinmodule.c 1994/05/06 14:24:06
***************
*** 1183,1189 ****
getbuiltin(name)
object *name;
{
! return dict2lookup(builtin_dict, name);
}

/* Predefined exceptions */
--- 1183,1197 ----
getbuiltin(name)
object *name;
{
! return mappinglookup(builtin_dict, name);
! }
!
! int
! setbuiltin(cname, value)
! char *cname;
! object *value;
! {
! return dictinsert(builtin_dict, cname, value);
}

/* Predefined exceptions */
===================================================================
RCS file: /hosts/voorn/ufs/guido/python-RCS/new/Python/RCS/ceval.c,v
retrieving revision 2.64.2.7
retrieving revision 2.64.2.8
diff -c -r2.64.2.7 -r2.64.2.8
*** 2.64.2.7 1994/05/04 07:41:12
--- 2.64.2.8 1994/05/06 14:24:09
***************
*** 646,652 ****
/* Print value except if procedure result */
/* Before printing, also assign to '_' */
if (v != None &&
! (err = dictinsert(f->f_locals, "_", v)) == 0) {
flushline();
x = sysget("stdout");
softspace(x, 1);
--- 646,652 ----
/* Print value except if procedure result */
/* Before printing, also assign to '_' */
if (v != None &&
! (err = setbuiltin("_", v)) == 0) {
flushline();
x = sysget("stdout");
softspace(x, 1);

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>