From: <wme...@us...> - 2009-09-04 01:31:58
|
Revision: 6747 http://jython.svn.sourceforge.net/jython/?rev=6747&view=rev Author: wmeissner Date: 2009-09-04 01:31:51 +0000 (Fri, 04 Sep 2009) Log Message: ----------- Remove getAddress() from the Pointer interface Modified Paths: -------------- branches/ctypes-jffi/src/org/python/modules/jffi/AbstractMemoryCData.java branches/ctypes-jffi/src/org/python/modules/jffi/ByReference.java branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java branches/ctypes-jffi/src/org/python/modules/jffi/Function.java branches/ctypes-jffi/src/org/python/modules/jffi/MemoryOp.java branches/ctypes-jffi/src/org/python/modules/jffi/Pointer.java branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java Added Paths: ----------- branches/ctypes-jffi/src/org/python/modules/jffi/BasePointer.java Modified: branches/ctypes-jffi/src/org/python/modules/jffi/AbstractMemoryCData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/AbstractMemoryCData.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/AbstractMemoryCData.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -19,10 +19,6 @@ m.putAddress(0, memory); } - public final long getAddress() { - return getMemory().getAddress(); - } - public final DirectMemory getMemory() { return hasReferenceMemory() ? getReferenceMemory().getMemory(0) : memory; } Added: branches/ctypes-jffi/src/org/python/modules/jffi/BasePointer.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/BasePointer.java (rev 0) +++ branches/ctypes-jffi/src/org/python/modules/jffi/BasePointer.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -0,0 +1,33 @@ +package org.python.modules.jffi; + +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedGet; + +public abstract class BasePointer extends PyObject implements Pointer { + + BasePointer(PyType subtype) { + super(subtype); + } + + @ExposedGet(name = "address") + public PyObject address() { + return Py.newInteger(getMemory().getAddress()); + } + + @Override + public boolean __nonzero__() { + return !getMemory().isNull(); + } + + @Override + public PyObject __int__() { + return address(); + } + + @Override + public PyObject __long__() { + return address(); + } +} Modified: branches/ctypes-jffi/src/org/python/modules/jffi/ByReference.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/ByReference.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/ByReference.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -16,11 +16,12 @@ this.memory = memory; } - public long getAddress() { - return getMemory().getAddress(); - } - public final DirectMemory getMemory() { return memory; } + + @Override + public boolean __nonzero__() { + return !getMemory().isNull(); + } } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -445,7 +445,7 @@ public void marshal(HeapInvocationBuffer buffer, PyObject parameter) { if (parameter instanceof Pointer) { - buffer.putAddress(((Pointer) parameter).getAddress()); + buffer.putAddress(((Pointer) parameter).getMemory().getAddress()); } else if (parameter == Py.None) { buffer.putAddress(0); } else { Modified: branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -56,37 +56,25 @@ } @ExposedType(name = "jffi.DynamicLibrary.Symbol", base = PyObject.class) - public static class Symbol extends PyObject implements Pointer { + public static class Symbol extends BasePointer { public static final PyType TYPE = PyType.fromClass(Symbol.class); final DynamicLibrary library; final DirectMemory memory; @ExposedGet - public final long address; - - @ExposedGet public final String name; public Symbol(DynamicLibrary library, String name, DirectMemory memory) { + super(TYPE); this.library = library; this.name = name; this.memory = memory; - this.address = memory.getAddress(); } - public final long getAddress() { - return address; - } - public final DirectMemory getMemory() { return memory; } - - @Override - public boolean __nonzero__() { - return !getMemory().isNull(); - } } public static final class TextSymbol extends Symbol implements ExposeAsSuperclass { Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Function.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -13,7 +13,7 @@ import org.python.expose.ExposedType; @ExposedType(name = "jffi.Function", base = PyObject.class) -public class Function extends PyObject implements Pointer { +public class Function extends BasePointer implements Pointer { public static final PyType TYPE = PyType.fromClass(Function.class); private final Pointer pointer; @@ -29,15 +29,11 @@ public final String name; @ExposedGet - public final long address; - - @ExposedGet @ExposedSet public PyObject restype; Function(PyType type, Pointer address) { super(type); - this.address = address.getAddress(); this.library = null; this.name = "<anonymous>"; this.pointer = address; @@ -48,7 +44,6 @@ this.library = sym.library; this.name = sym.name; this.pointer = sym; - this.address = sym.getAddress(); } @ExposedNew @@ -66,14 +61,10 @@ } } - public long getAddress() { - return address; - } - public DirectMemory getMemory() { return pointer.getMemory(); } - + @Override public PyObject fastGetDict() { return dict; @@ -166,7 +157,7 @@ if (invoker != null) { return invoker; } - return createInvoker(address, returnType, parameterTypes); + return createInvoker(getMemory().getAddress(), returnType, parameterTypes); } private synchronized final Invoker createInvoker(long address, CType returnType, CType[] parameterTypes) { Modified: branches/ctypes-jffi/src/org/python/modules/jffi/MemoryOp.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/MemoryOp.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/MemoryOp.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -201,7 +201,7 @@ public final void put(Memory mem, long offset, PyObject value) { if (value instanceof Pointer) { - mem.putAddress(offset, ((Pointer) value).getAddress()); + mem.putAddress(offset, ((Pointer) value).getMemory().getAddress()); } else if (value == Py.None) { mem.putAddress(offset, 0); } else { Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Pointer.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Pointer.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Pointer.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -2,6 +2,5 @@ package org.python.modules.jffi; public interface Pointer { - long getAddress(); DirectMemory getMemory(); } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java 2009-09-04 00:43:55 UTC (rev 6746) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java 2009-09-04 01:31:51 UTC (rev 6747) @@ -67,10 +67,6 @@ f.op.put(getReferenceMemory(), f.offset, value); } - public long getAddress() { - return getMemory().getAddress(); - } - public DirectMemory getMemory() { return getReferenceMemory(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |