[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.245,2.246 ceval.c,2.296,2.297 compile.c,2.233,2.234

Jeremy Hylton jhylton@users.sourceforge.net
2001年12月13日 11:51:58 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv1354/Python
Modified Files:
	bltinmodule.c ceval.c compile.c 
Log Message:
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Based on the patch from Danny Yoo. The fix is in exec_statement() in
ceval.c.
There are also changes to introduce use of PyCode_GetNumFree() in
several places.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.245
retrieving revision 2.246
diff -C2 -d -r2.245 -r2.246
*** bltinmodule.c	2001年11月28日 20:36:42	2.245
--- bltinmodule.c	2001年12月13日 19:51:51	2.246
***************
*** 498,502 ****
 
 	if (PyCode_Check(cmd)) {
! 		if (PyTuple_GET_SIZE(((PyCodeObject *)cmd)->co_freevars) > 0) {
 			PyErr_SetString(PyExc_TypeError,
 		"code object passed to eval() may not contain free variables");
--- 498,502 ----
 
 	if (PyCode_Check(cmd)) {
! 		if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) {
 			PyErr_SetString(PyExc_TypeError,
 		"code object passed to eval() may not contain free variables");
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.296
retrieving revision 2.297
diff -C2 -d -r2.296 -r2.297
*** ceval.c	2001年12月06日 21:28:18	2.296
--- ceval.c	2001年12月13日 19:51:53	2.297
***************
*** 2095,2099 ****
 			v = POP(); /* code object */
 			x = PyFunction_New(v, f->f_globals);
! 			nfree = PyTuple_GET_SIZE(((PyCodeObject *)v)->co_freevars);
 			Py_DECREF(v);
 			/* XXX Maybe this should be a separate opcode? */
--- 2095,2099 ----
 			v = POP(); /* code object */
 			x = PyFunction_New(v, f->f_globals);
! 			nfree = PyCode_GetNumFree((PyCodeObject *)v);
 			Py_DECREF(v);
 			/* XXX Maybe this should be a separate opcode? */
***************
*** 3632,3635 ****
--- 3632,3640 ----
 		PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
 	if (PyCode_Check(prog)) {
+ 		if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {
+ 			PyErr_SetString(PyExc_TypeError,
+ 		"code object passed to exec may not contain free variables");
+ 			return -1;
+ 		}
 		v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
 	}
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.233
retrieving revision 2.234
diff -C2 -d -r2.233 -r2.234
*** compile.c	2001年12月04日 02:41:46	2.233
--- compile.c	2001年12月13日 19:51:56	2.234
***************
*** 2274,2278 ****
 com_make_closure(struct compiling *c, PyCodeObject *co)
 {
! 	int i, free = PyTuple_GET_SIZE(co->co_freevars);
 	if (free == 0)
 		return 0;
--- 2274,2278 ----
 com_make_closure(struct compiling *c, PyCodeObject *co)
 {
! 	int i, free = PyCode_GetNumFree(co);
 	if (free == 0)
 		return 0;
***************
*** 2334,2338 ****
 		if (closure) {
 			com_addoparg(c, MAKE_CLOSURE, ndefs);
! 			com_pop(c, PyTuple_GET_SIZE(co->co_freevars));
 		} else
 			com_addoparg(c, MAKE_FUNCTION, ndefs);
--- 2334,2338 ----
 		if (closure) {
 			com_addoparg(c, MAKE_CLOSURE, ndefs);
! 			com_pop(c, PyCode_GetNumFree(co));
 		} else
 			com_addoparg(c, MAKE_FUNCTION, ndefs);
***************
*** 3591,3595 ****
 		if (closure) {
 			com_addoparg(c, MAKE_CLOSURE, 0);
! 			com_pop(c, PyTuple_GET_SIZE(co->co_freevars));
 		} else
 			com_addoparg(c, MAKE_FUNCTION, 0);
--- 3591,3595 ----
 		if (closure) {
 			com_addoparg(c, MAKE_CLOSURE, 0);
! 			com_pop(c, PyCode_GetNumFree(co));
 		} else
 			com_addoparg(c, MAKE_FUNCTION, 0);

AltStyle によって変換されたページ (->オリジナル) /