From: <wme...@us...> - 2009-08-31 01:13:45
|
Revision: 6731 http://jython.svn.sourceforge.net/jython/?rev=6731&view=rev Author: wmeissner Date: 2009-08-30 23:31:13 +0000 (Sun, 30 Aug 2009) Log Message: ----------- Fix some pointer and unsigned int parameter handling Modified Paths: -------------- branches/ctypes-jffi/Lib/ctypes/__init__.py branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java branches/ctypes-jffi/src/org/python/modules/jffi/Util.java Property Changed: ---------------- branches/ctypes-jffi/Lib/ctypes/ Property changes on: branches/ctypes-jffi/Lib/ctypes ___________________________________________________________________ Added: svn:ignore + *.class Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-08-30 22:17:24 UTC (rev 6730) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-08-30 23:31:13 UTC (rev 6731) @@ -37,7 +37,8 @@ return cdata.pointer() def POINTER(type): - return jffi.Type.Pointer(type._jffi_type, type) +# return jffi.Type.Pointer(type) + return c_void_p class c_byte(_ScalarCData): _jffi_type = jffi.Type.BYTE Modified: branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-08-30 22:17:24 UTC (rev 6730) +++ branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-08-30 23:31:13 UTC (rev 6731) @@ -372,7 +372,7 @@ public static final ParameterMarshaller INSTANCE = new Unsigned32Marshaller(); public void marshal(HeapInvocationBuffer buffer, PyObject arg) { - buffer.putInt((int) Util.int32Value(arg)); + buffer.putInt((int) Util.uint32Value(arg)); } } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Util.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Util.java 2009-08-30 22:17:24 UTC (rev 6730) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Util.java 2009-08-30 23:31:13 UTC (rev 6731) @@ -67,8 +67,14 @@ return parameter.asInt(); } - public static final int uint32Value(PyObject parameter) { - return parameter.asInt(); + public static final int uint32Value(PyObject value) { + if (value instanceof PyInteger) { + return value.asInt(); + } else if (value instanceof PyLong) { + return (int) ((PyLong) value).asLong(0); + } else { + return (int) __long__value(value); + } } public static final long int64Value(PyObject value) { @@ -82,7 +88,13 @@ } public static final long uint64Value(PyObject value) { - return int64Value(value); + if (value instanceof PyLong) { + return ((PyLong) value).getValue().longValue(); + } else if (value instanceof PyInteger) { + return value.asInt(); + } else { + return __long__value(value); + } } public static final float floatValue(PyObject parameter) { @@ -93,6 +105,16 @@ return parameter.asDouble(); } + private static final long __long__value(PyObject value) { + PyObject l = value.__long__(); + if (l instanceof PyLong) { + return ((PyLong) l).getValue().longValue(); + } else if (l instanceof PyInteger) { + return value.asInt(); + } + throw Py.TypeError("invalid __long__() result"); + } + public static final void checkBounds(long size, long off, long len) { if ((off | len | (off + len) | (size - (off + len))) < 0) { throw Py.IndexError("Memory access offset=" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |