From: <wme...@us...> - 2009-08-26 10:09:07
|
Revision: 6722 http://jython.svn.sourceforge.net/jython/?rev=6722&view=rev Author: wmeissner Date: 2009-08-26 10:08:56 +0000 (Wed, 26 Aug 2009) Log Message: ----------- Fixup CType exposure Modified Paths: -------------- branches/ctypes-jffi/CoreExposed.includes branches/ctypes-jffi/src/org/python/modules/jffi/CType.java Modified: branches/ctypes-jffi/CoreExposed.includes =================================================================== --- branches/ctypes-jffi/CoreExposed.includes 2009-08-26 07:18:30 UTC (rev 6721) +++ branches/ctypes-jffi/CoreExposed.includes 2009-08-26 10:08:56 UTC (rev 6722) @@ -53,14 +53,14 @@ org/python/modules/_functools/PyPartial.class org/python/modules/_hashlib$Hash.class org/python/modules/jffi/CData.class +org/python/modules/jffi/CType.class +org/python/modules/jffi/CType$Array.class +org/python/modules/jffi/CType$Pointer.class org/python/modules/jffi/DynamicLibrary.class org/python/modules/jffi/DynamicLibrary$Symbol.class org/python/modules/jffi/Function.class org/python/modules/jffi/Pointer.class org/python/modules/jffi/ScalarCData.class -org/python/modules/jffi/Type.class -org/python/modules/jffi/Type$Array.class -org/python/modules/jffi/Type$Pointer.class org/python/modules/_threading/Condition.class org/python/modules/_threading/Lock.class org/python/modules/_weakref/CallableProxyType.class Modified: branches/ctypes-jffi/src/org/python/modules/jffi/CType.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-08-26 07:18:30 UTC (rev 6721) +++ branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-08-26 10:08:56 UTC (rev 6722) @@ -6,14 +6,13 @@ import org.python.core.Py; import org.python.core.PyNewWrapper; import org.python.core.PyObject; -import org.python.core.PyObjectDerived; import org.python.core.PyType; import org.python.expose.ExposeAsSuperclass; import org.python.expose.ExposedGet; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; -@ExposedType(name = "jffi.Type", base = PyObjectDerived.class) +@ExposedType(name = "jffi.Type", base = PyObject.class) public class CType extends PyObject { public static final PyType TYPE = PyType.fromClass(CType.class); static { @@ -92,16 +91,30 @@ } } + private static CType typeOf(PyObject obj) { + if (obj instanceof CType) { + return (CType) obj; + } + + PyObject jffi_type = obj.__getattr__("_jffi_type"); + if (!(jffi_type instanceof CType)) { + throw Py.TypeError("invalid _jffi_type"); + } + return (CType) jffi_type; + } + @ExposedType(name = "jffi.Type.Array", base = CType.class) static final class Array extends CType { public static final PyType TYPE = PyType.fromClass(Array.class); final CType componentType; - + final PyObject pyComponentType; + @ExposedGet public final int length; - public Array(CType componentType, int length) { + public Array(PyObject pyComponentType, CType componentType, int length) { super(NativeType.ARRAY, new com.kenai.jffi.Array(componentType.jffiType, length), null); + this.pyComponentType = pyComponentType; this.componentType = componentType; this.length = length; } @@ -114,11 +127,7 @@ throw Py.TypeError(String.format("__init__() takes exactly 2 arguments (%d given)", args.length)); } - if (!(args[0] instanceof CType)) { - throw Py.TypeError("expected jffi.Type"); - } - - return new Array((CType) args[0], args[1].asInt()); + return new Array(args[0], typeOf(args[0]), args[1].asInt()); } @Override @@ -128,7 +137,7 @@ @Override public final String toString() { - return String.format("<jffi.Type.Array length=%d>", length); + return String.format("<ctypes.Array elem_type=%s length=%d>", pyComponentType.toString(), length); } } @@ -142,10 +151,11 @@ final PyType pyComponentType; final MemoryOp componentMemoryOp; - Pointer(PyType subtype, CType componentType, PyType pyComponentType) { + Pointer(PyType subtype, PyType pyComponentType, CType componentType) { super(NativeType.POINTER, com.kenai.jffi.Type.POINTER, MemoryOp.POINTER); + this.pyComponentType = pyComponentType; this.componentType = componentType; - this.pyComponentType = pyComponentType; + if (pyComponentType.isSubType(ScalarCData.TYPE)) { this.componentMemoryOp = new ScalarOp(MemoryOp.getMemoryOp(componentType.getNativeType()), pyComponentType); } else { @@ -163,18 +173,15 @@ return p; } - if (args.length < 1) { + if (args.length != 1) { throw Py.TypeError(String.format("__init__() takes exactly 1 argument (%d given)", args.length)); } - if (!(args[0] instanceof CType)) { - throw Py.TypeError("expected jffi.Type"); + if (!(args[0] instanceof PyType)) { + throw Py.TypeError("expected ctypes class"); } - if (args.length > 1 && !(args[1] instanceof PyType)) { - throw Py.TypeError("expected type"); - } - p = new Pointer(subtype, (CType) args[0], args.length > 1 ? (PyType) args[1] : Py.None.getType()); + p = new Pointer(subtype, (PyType) args[0], typeOf(args[0])); typeCache.put(args[0], p); return p; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |