From: <fwi...@us...> - 2009-04-05 18:30:08
|
Revision: 6165 http://jython.svn.sourceforge.net/jython/?rev=6165&view=rev Author: fwierzbicki Date: 2009-04-05 18:29:58 +0000 (Sun, 05 Apr 2009) Log Message: ----------- Fix for http://bugs.jython.org/issue1264 'is not' test exhibits incorrect behaviour when wrapping Java objects Included is a reshuffling of the patch test so that a regression test can pick it up. It isn't perfect since I had to use raw "assert" statements in the python, but it is run by the Java unit test IdentityTest. Thanks to Geoffrey French for the patch. Modified Paths: -------------- trunk/jython/ACKNOWLEDGMENTS trunk/jython/NEWS trunk/jython/src/org/python/core/PyObject.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/identity/ trunk/jython/tests/java/org/python/tests/identity/IdentityObject.java trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java trunk/jython/tests/python/ trunk/jython/tests/python/identity_test.py Modified: trunk/jython/ACKNOWLEDGMENTS =================================================================== --- trunk/jython/ACKNOWLEDGMENTS 2009-04-05 17:22:40 UTC (rev 6164) +++ trunk/jython/ACKNOWLEDGMENTS 2009-04-05 18:29:58 UTC (rev 6165) @@ -66,6 +66,7 @@ Nathan Franzen Aleks Totic Randolph Brown + Geoffrey French Local Variables: mode: indented-text Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-04-05 17:22:40 UTC (rev 6164) +++ trunk/jython/NEWS 2009-04-05 18:29:58 UTC (rev 6165) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException - [ 1261 ] jython -c "import sys; sys.exit(1)" not giving correct exit code. Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-04-05 17:22:40 UTC (rev 6164) +++ trunk/jython/src/org/python/core/PyObject.java 2009-04-05 18:29:58 UTC (rev 6165) @@ -1633,7 +1633,7 @@ public PyObject _isnot(PyObject o) { // Access javaProxy directly here as is is for object identity, and at best getJavaProxy // will initialize a new object with a different identity - return this != o || javaProxy != o.javaProxy ? Py.True : Py.False; + return this != o && (javaProxy == null || javaProxy != o.javaProxy) ? Py.True : Py.False; } /** Added: trunk/jython/tests/java/org/python/tests/identity/IdentityObject.java =================================================================== --- trunk/jython/tests/java/org/python/tests/identity/IdentityObject.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/identity/IdentityObject.java 2009-04-05 18:29:58 UTC (rev 6165) @@ -0,0 +1,12 @@ +package org.python.tests.identity; + +public class IdentityObject { + + public IdentityObject() { + } + + public IdentityObject getThis() { + return this; + } + +} Added: trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-05 18:29:58 UTC (rev 6165) @@ -0,0 +1,28 @@ +package org.python.tests.identity; + +import junit.framework.TestCase; + +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.util.PythonInterpreter; + +public class IdentityTest extends TestCase { + + private PythonInterpreter interp; + + @Override + protected void setUp() throws Exception { + PySystemState sys = new PySystemState(); + sys.path.append(new PyString("dist/Lib")); + sys.path.append(new PyString("dist/javalib/constantine.jar")); + sys.path.append(new PyString("dist/javalib/jna.jar")); + sys.path.append(new PyString("dist/javalib/jna-posix.jar")); + interp = new PythonInterpreter(new PyStringMap(), sys); + } + + public void testReadonly() { + //This used to cause an NPE see http://bugs.jython.org/issue1295 + interp.execfile("tests/python/identity_test.py"); + } +} Added: trunk/jython/tests/python/identity_test.py =================================================================== --- trunk/jython/tests/python/identity_test.py (rev 0) +++ trunk/jython/tests/python/identity_test.py 2009-04-05 18:29:58 UTC (rev 6165) @@ -0,0 +1,18 @@ +from org.python.tests.identity import IdentityObject + +class PyIdentityObject (IdentityObject): + pass + +x = IdentityObject() +y = x.getThis() + +a = PyIdentityObject() +b = a.getThis() + +assert x is y +assert not(x is not y) +assert (x is y) != (x is not y) +assert a is b +assert not(a is not b) +assert (a is b) != (a is not b) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |