From: <zy...@us...> - 2008-08-20 06:54:13
|
Revision: 5215 http://jython.svn.sourceforge.net/jython/?rev=5215&view=rev Author: zyasoft Date: 2008-08-20 06:54:10 +0000 (Wed, 20 Aug 2008) Log Message: ----------- A class definition needs to have __module__ set in frame locals, so that it is accessible by a metaclass, if defined. Fixes test_advice in zope.interfaces Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/core/PyFrame.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2008-08-20 05:26:20 UTC (rev 5214) +++ trunk/jython/src/org/python/compiler/Module.java 2008-08-20 06:54:10 UTC (rev 5215) @@ -405,6 +405,29 @@ CodeCompiler compiler = new CodeCompiler(this, printResults); + if (classBody) { + Label label_got_name = new Label(); + int module_tmp = c.getLocal("org/python/core/PyObject"); + + c.aload(1); + c.ldc("__module__"); + c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + c.dup(); + c.ifnonnull(label_got_name); + + c.pop(); + c.aload(1); + c.ldc("__name__"); + c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + + c.label(label_got_name); + c.astore(module_tmp); + c.aload(1); + c.ldc("__module__"); + c.aload(module_tmp); + c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); + } + Label genswitch = new Label(); if (scope.generator) { c.goto_(genswitch); Modified: trunk/jython/src/org/python/core/PyFrame.java =================================================================== --- trunk/jython/src/org/python/core/PyFrame.java 2008-08-20 05:26:20 UTC (rev 5214) +++ trunk/jython/src/org/python/core/PyFrame.java 2008-08-20 06:54:10 UTC (rev 5215) @@ -282,6 +282,20 @@ throw Py.NameError(String.format(NAME_ERROR_MSG, index)); } + public PyObject getname_or_null(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { + ret = doGetglobal(index); + } else { + ret = f_locals.__finditem__(index); + if (ret != null) { + return ret; + } + ret = doGetglobal(index); + } + return ret; + } + public PyObject getglobal(String index) { PyObject ret = doGetglobal(index); if (ret != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |