From: <cg...@us...> - 2008-11-28 09:13:21
|
Revision: 5653 http://jython.svn.sourceforge.net/jython/?rev=5653&view=rev Author: cgroves Date: 2008-11-28 09:13:19 +0000 (Fri, 28 Nov 2008) Log Message: ----------- PyObject needs to handle primitive conversion in the new world Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyInstance.java branches/newstyle-java-types/src/org/python/core/PyObject.java Modified: branches/newstyle-java-types/src/org/python/core/PyInstance.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-28 08:59:49 UTC (rev 5652) +++ branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-28 09:13:19 UTC (rev 5653) @@ -82,23 +82,6 @@ if (c.isInstance(this)) return this; - if (c.isPrimitive()) { - if (primitiveMap == null) { - primitiveMap = new Hashtable(); - primitiveMap.put(Character.TYPE, Character.class); - primitiveMap.put(Boolean.TYPE, Boolean.class); - primitiveMap.put(Byte.TYPE, Byte.class); - primitiveMap.put(Short.TYPE, Short.class); - primitiveMap.put(Integer.TYPE, Integer.class); - primitiveMap.put(Long.TYPE, Long.class); - primitiveMap.put(Float.TYPE, Float.class); - primitiveMap.put(Double.TYPE, Double.class); - } - Class tmp = (Class)primitiveMap.get(c); - if (tmp != null) - c = tmp; - } - if (instclass.__tojava__ != null) { // try { PyObject ret = instclass.__tojava__.__call__(this, PyType.fromClass(c)); Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-28 08:59:49 UTC (rev 5652) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-28 09:13:19 UTC (rev 5653) @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import org.python.expose.ExposedDelete; @@ -15,6 +16,7 @@ import org.python.expose.ExposedNew; import org.python.expose.ExposedSet; import org.python.expose.ExposedType; +import org.python.util.Generic; /** * All objects known to the Jython runtime system are represented by an instance @@ -253,12 +255,30 @@ if (c.isInstance(this)) { return this; } + if (c.isPrimitive()) { + Class<?> tmp = primitiveMap.get(c); + if (tmp != null) { + c = tmp; + } + } if (c.isInstance(javaProxy)) { return javaProxy; } return Py.NoConversion; } + protected static final Map<Class<?>, Class<?>> primitiveMap = Generic.map(); + static { + primitiveMap.put(Character.TYPE, Character.class); + primitiveMap.put(Boolean.TYPE, Boolean.class); + primitiveMap.put(Byte.TYPE, Byte.class); + primitiveMap.put(Short.TYPE, Short.class); + primitiveMap.put(Integer.TYPE, Integer.class); + primitiveMap.put(Long.TYPE, Long.class); + primitiveMap.put(Float.TYPE, Float.class); + primitiveMap.put(Double.TYPE, Double.class); + } + /** * The basic method to override when implementing a callable object. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |