From: <cg...@us...> - 2006-10-09 01:35:50
|
Revision: 2949 http://svn.sourceforge.net/jython/?rev=2949&view=rev Author: cgroves Date: 2006-10-08 18:35:44 -0700 (Sun, 08 Oct 2006) Log Message: ----------- if eval or exec are called with code objects with freevars throw a TypeException as they have no locals to reference Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2006-09-29 15:55:10 UTC (rev 2948) +++ trunk/jython/src/org/python/core/Py.java 2006-10-09 01:35:44 UTC (rev 2949) @@ -1190,11 +1190,7 @@ public static PyObject runCode(PyCode code, PyObject locals, PyObject globals) { - //System.out.println("run code"); PyFrame f; - /*if (globals == null && locals == null) { - f = Py.getFrame(); - } else {*/ if (locals == null) { if (globals != null) { locals = globals; @@ -1212,15 +1208,18 @@ f = new PyFrame(tc, locals, globals, Py.getThreadState().systemState.builtins); - //} return code.call(f); } public static void exec(PyObject o, PyObject globals, PyObject locals) { PyCode code; - if (o instanceof PyCode) + if(o instanceof PyCode) { code = (PyCode)o; - else { + if(locals == null && o instanceof PyTableCode + && ((PyTableCode)o).co_freevars.length > 0) { + throw Py.TypeError("code object passed to exec may not contain free variables"); + } + }else { String contents = null; if (o instanceof PyString) contents = o.toString(); @@ -1389,7 +1388,7 @@ } public static long py2long(PyObject o) { - if (o instanceof PyInteger) + if(o instanceof PyInteger) return (long)((PyInteger)o).getValue(); Object i = o.__tojava__(Long.TYPE); Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2006-09-29 15:55:10 UTC (rev 2948) +++ trunk/jython/src/org/python/core/__builtin__.java 2006-10-09 01:35:44 UTC (rev 2949) @@ -287,6 +287,9 @@ } public static PyObject eval(PyObject o) { + if(o instanceof PyTableCode && ((PyTableCode)o).co_freevars.length > 0) { + throw Py.TypeError("code object passed to eval() may not contain free variables"); + } return eval(o, null, null); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |