[Jython-checkins] jython: Fix #2090 (also #1494) on behaviour of long in the JSR-223 engine.

jeff.allen jython-checkins at python.org
Wed Oct 15 00:04:14 CEST 2014


https://hg.python.org/jython/rev/4ed64dc6c895
changeset:   7400:4ed64dc6c895
user:        Raphael Jolly <rjolly at users.sourceforge.net>
date:        Tue Oct 14 22:21:46 2014 +0100
summary:
  Fix #2090 (also #1494) on behaviour of long in the JSR-223 engine.

java.lang.BigInteger is recognised by the classic object adapter as
adaptable to PyLong. Scopes in the JSR-223 script engine, which strip
the PyLong wrapper, to share a BigInteger with Java, now restore the
PyLong wrapper when Jython accesses them.

files:
  ACKNOWLEDGMENTS                                         |   1 +
  src/org/python/core/adapter/ClassicPyObjectAdapter.java |  12 ++++++++++
  tests/java/org/python/jsr223/ScriptEngineTest.java      |  12 ++++++++-
  3 files changed, 23 insertions(+), 2 deletions(-)


diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS
--- a/ACKNOWLEDGMENTS
+++ b/ACKNOWLEDGMENTS
@@ -113,6 +113,7 @@
     Werner Mendizabal
     Henning Jacobs
     Darjus Loktevic
+    Raphael Jolly
 
 Local Variables:
 mode: indented-text
diff --git a/src/org/python/core/adapter/ClassicPyObjectAdapter.java b/src/org/python/core/adapter/ClassicPyObjectAdapter.java
--- a/src/org/python/core/adapter/ClassicPyObjectAdapter.java
+++ b/src/org/python/core/adapter/ClassicPyObjectAdapter.java
@@ -1,5 +1,7 @@
 package org.python.core.adapter;
 
+import java.math.BigInteger;
+
 import org.python.core.Py;
 import org.python.core.PyArray;
 import org.python.core.PyFloat;
@@ -88,6 +90,15 @@
             }
 
         });
+
+        add(new ClassAdapter(BigInteger.class) {
+
+            public PyObject adapt(Object o) {
+                return new PyLong((BigInteger)o);
+            }
+
+        });
+
         add(new ClassAdapter(Boolean.class) {
 
             public PyObject adapt(Object o) {
@@ -95,6 +106,7 @@
             }
 
         });
+
         addPostClass(new PyObjectAdapter() {
 
             public PyObject adapt(Object o) {
diff --git a/tests/java/org/python/jsr223/ScriptEngineTest.java b/tests/java/org/python/jsr223/ScriptEngineTest.java
--- a/tests/java/org/python/jsr223/ScriptEngineTest.java
+++ b/tests/java/org/python/jsr223/ScriptEngineTest.java
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.math.BigInteger;
 
 import javax.script.Bindings;
 import javax.script.Compilable;
@@ -15,8 +16,8 @@
 
 import junit.framework.TestCase;
 
+import org.python.core.Options;
 import org.python.core.PyString;
-import org.python.core.Options;
 
 public class ScriptEngineTest extends TestCase {
 
@@ -260,7 +261,7 @@
                 + "class MyPythonCallable(PythonCallable):\n"
                 + "    def getAString(self): return 'a string'\n\n"
                 + "result = MyPythonCallable().getAString()\n" //
-                + "test = MyPythonCallable()\n"
+                + "test = MyPythonCallable()\n" //
                 + "result2 = test.getAString()");
         assertEquals("a string", pythonEngine.get("result"));
         assertEquals("a string", pythonEngine.get("result2"));
@@ -294,4 +295,11 @@
         }
     }
 
+    public void testIssue2090() throws ScriptException {
+        ScriptEngineManager manager = new ScriptEngineManager();
+        ScriptEngine pythonEngine = manager.getEngineByName("python");
+        pythonEngine.eval("a = 10L\n" + "b = a-1");
+        Object r = pythonEngine.get("b");
+        assertEquals(new BigInteger("9"), r);
+    }
 }

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list