[Jython-checkins] jython: Added traverseprocs to some classes in org.python.modules.jffi.
stefan.richthofer
jython-checkins at python.org
Thu Feb 23 13:44:31 EST 2017
https://hg.python.org/jython/rev/d57b03d7489c
changeset: 8026:d57b03d7489c
user: Stefan Richthofer <stefan.richthofer at gmx.de>
date: Thu Feb 23 19:44:18 2017 +0100
summary:
Added traverseprocs to some classes in org.python.modules.jffi.
files:
src/org/python/modules/jffi/AbstractMemoryCData.java | 1 +
src/org/python/modules/jffi/CType.java | 46 +++++++-
src/org/python/modules/jffi/DynamicLibrary.java | 5 +-
src/org/python/modules/jffi/Function.java | 54 +++++++++-
src/org/python/modules/jffi/JITInvoker.java | 4 -
src/org/python/modules/jffi/JITInvoker0.java | 4 -
src/org/python/modules/jffi/JITInvoker1.java | 3 -
src/org/python/modules/jffi/JITInvoker2.java | 3 -
src/org/python/modules/jffi/JITInvoker3.java | 3 -
src/org/python/modules/jffi/JITInvoker4.java | 3 -
src/org/python/modules/jffi/JITInvoker5.java | 3 -
src/org/python/modules/jffi/JITInvoker6.java | 3 -
src/org/python/modules/jffi/JITMethodGenerator.java | 3 -
src/org/python/modules/jffi/JITRuntime.java | 3 -
src/org/python/modules/jffi/JITSignature.java | 4 -
src/org/python/modules/jffi/Memory.java | 1 -
src/org/python/modules/jffi/MemoryOp.java | 1 -
src/org/python/modules/jffi/NativeDataConverter.java | 4 -
src/org/python/modules/jffi/NativeMemory.java | 1 -
src/org/python/modules/jffi/NativeType.java | 2 -
src/org/python/modules/jffi/NullMemory.java | 2 -
src/org/python/modules/jffi/Pointer.java | 1 -
src/org/python/modules/jffi/PointerCData.java | 1 -
src/org/python/modules/jffi/ScalarCData.java | 30 ++++-
src/org/python/modules/jffi/StringCData.java | 4 -
src/org/python/modules/jffi/StructLayout.java | 43 +++++++-
src/org/python/modules/jffi/Structure.java | 24 ++++-
src/org/python/modules/jffi/Util.java | 1 -
src/org/python/modules/jffi/jffi.java | 1 -
29 files changed, 186 insertions(+), 72 deletions(-)
diff --git a/src/org/python/modules/jffi/AbstractMemoryCData.java b/src/org/python/modules/jffi/AbstractMemoryCData.java
--- a/src/org/python/modules/jffi/AbstractMemoryCData.java
+++ b/src/org/python/modules/jffi/AbstractMemoryCData.java
@@ -10,6 +10,7 @@
super(subtype, type);
this.memory = memory;
}
+
@Override
public boolean __nonzero__() {
return !getMemory().isNull();
diff --git a/src/org/python/modules/jffi/CType.java b/src/org/python/modules/jffi/CType.java
--- a/src/org/python/modules/jffi/CType.java
+++ b/src/org/python/modules/jffi/CType.java
@@ -8,6 +8,8 @@
import org.python.core.PyObject;
import org.python.core.PyType;
import org.python.core.Untraversable;
+import org.python.core.Traverseproc;
+import org.python.core.Visitproc;
import org.python.expose.ExposeAsSuperclass;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedMethod;
@@ -98,6 +100,7 @@
}
}
+ @Untraversable
@ExposedType(name = "jffi.Type.Custom", base = CType.class)
static class Custom extends CType {
final com.kenai.jffi.Type jffiType;
@@ -127,7 +130,7 @@
}
@ExposedType(name = "jffi.Type.Array", base = CType.class)
- static final class Array extends CType.Custom {
+ static final class Array extends CType.Custom implements Traverseproc {
public static final PyType TYPE = PyType.fromClass(Array.class);
final CType componentType;
final PyType pyComponentType;
@@ -178,16 +181,33 @@
throw Py.TypeError("only scalar and struct types supported");
}
}
+
+
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ if (componentType != null) {
+ int res = visit.visit(componentType, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ return pyComponentType != null ? visit.visit(pyComponentType, arg) : 0;
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ return ob != null && (ob == componentType || ob == pyComponentType);
+ }
}
-
@ExposedType(name = "jffi.Type.Pointer", base = CType.class)
- final static class Pointer extends Custom {
+ final static class Pointer extends Custom implements Traverseproc {
public static final PyType TYPE = PyType.fromClass(Pointer.class);
private static final ConcurrentMap<PyObject, Pointer> typeCache
= new ConcurrentHashMap<PyObject, Pointer>();
-
+
final CType componentType;
final PyType pyComponentType;
final MemoryOp componentMemoryOp;
@@ -234,7 +254,7 @@
public final String toString() {
return String.format("<jffi.Type.Pointer component_type=%s>", componentType.toString());
}
-
+
private static final class ScalarOp extends MemoryOp {
private final MemoryOp op;
private final PyType type;
@@ -262,5 +282,21 @@
}
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ if (componentType != null) {
+ int res = visit.visit(componentType, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ return pyComponentType != null ? visit.visit(pyComponentType, arg) : 0;
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ return ob != null && (ob == componentType || ob == pyComponentType);
+ }
}
}
diff --git a/src/org/python/modules/jffi/DynamicLibrary.java b/src/org/python/modules/jffi/DynamicLibrary.java
--- a/src/org/python/modules/jffi/DynamicLibrary.java
+++ b/src/org/python/modules/jffi/DynamicLibrary.java
@@ -57,6 +57,7 @@
return new DataSymbol(this, name.asString(), findSymbol(name));
}
+ @Untraversable
@ExposedType(name = "jffi.DynamicLibrary.Symbol", base = PyObject.class)
public static class Symbol extends BasePointer {
public static final PyType TYPE = PyType.fromClass(Symbol.class);
@@ -78,13 +79,15 @@
return memory;
}
}
-
+
+ @Untraversable
public static final class TextSymbol extends Symbol implements ExposeAsSuperclass {
public TextSymbol(DynamicLibrary lib, String name, long address) {
super(lib, name, new SymbolMemory(lib, address));
}
}
+ @Untraversable
public static final class DataSymbol extends Symbol implements ExposeAsSuperclass {
public DataSymbol(DynamicLibrary lib, String name, long address) {
super(lib, name, new SymbolMemory(lib, address));
diff --git a/src/org/python/modules/jffi/Function.java b/src/org/python/modules/jffi/Function.java
--- a/src/org/python/modules/jffi/Function.java
+++ b/src/org/python/modules/jffi/Function.java
@@ -9,13 +9,15 @@
import org.python.core.PySequenceList;
import org.python.core.PyStringMap;
import org.python.core.PyType;
+import org.python.core.Traverseproc;
+import org.python.core.Visitproc;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedNew;
import org.python.expose.ExposedSet;
import org.python.expose.ExposedType;
@ExposedType(name = "jffi.Function", base = PyObject.class)
-public class Function extends BasePointer implements Pointer {
+public class Function extends BasePointer implements Traverseproc {
public static final PyType TYPE = PyType.fromClass(Function.class);
private final Pointer pointer;
@@ -262,4 +264,54 @@
return errcheck.__call__(invoker.invoke(arg1, arg2, arg3, arg4, arg5, arg6));
}
}
+
+
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ int res = 0;
+ if (pointer != null && pointer instanceof PyObject) {
+ res = visit.visit((PyObject) pointer, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ if (dict != null) {
+ res = visit.visit(dict, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ if (restype != null) {
+ res = visit.visit(restype, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ if (argtypes != null) {
+ for (PyObject obj: argtypes) {
+ res = visit.visit(obj, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) throws UnsupportedOperationException {
+ if (ob != null && (pointer == ob || dict == ob || restype == ob)) {
+ return true;
+ };
+ if (argtypes != null)
+ {
+ for (PyObject obj: argtypes) {
+ if (obj == ob) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/src/org/python/modules/jffi/JITInvoker.java b/src/org/python/modules/jffi/JITInvoker.java
--- a/src/org/python/modules/jffi/JITInvoker.java
+++ b/src/org/python/modules/jffi/JITInvoker.java
@@ -1,12 +1,8 @@
package org.python.modules.jffi;
-import com.kenai.jffi.*;
import org.python.core.Py;
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker extends Invoker {
protected static final com.kenai.jffi.Invoker jffiInvoker = com.kenai.jffi.Invoker.getInstance();
protected final com.kenai.jffi.Function jffiFunction;
diff --git a/src/org/python/modules/jffi/JITInvoker0.java b/src/org/python/modules/jffi/JITInvoker0.java
--- a/src/org/python/modules/jffi/JITInvoker0.java
+++ b/src/org/python/modules/jffi/JITInvoker0.java
@@ -1,11 +1,7 @@
package org.python.modules.jffi;
-import com.kenai.jffi.*;
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker0 extends JITInvoker {
public JITInvoker0(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(0, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker1.java b/src/org/python/modules/jffi/JITInvoker1.java
--- a/src/org/python/modules/jffi/JITInvoker1.java
+++ b/src/org/python/modules/jffi/JITInvoker1.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker1 extends JITInvoker {
public JITInvoker1(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(1, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker2.java b/src/org/python/modules/jffi/JITInvoker2.java
--- a/src/org/python/modules/jffi/JITInvoker2.java
+++ b/src/org/python/modules/jffi/JITInvoker2.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker2 extends JITInvoker {
public JITInvoker2(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(2, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker3.java b/src/org/python/modules/jffi/JITInvoker3.java
--- a/src/org/python/modules/jffi/JITInvoker3.java
+++ b/src/org/python/modules/jffi/JITInvoker3.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker3 extends JITInvoker {
public JITInvoker3(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(3, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker4.java b/src/org/python/modules/jffi/JITInvoker4.java
--- a/src/org/python/modules/jffi/JITInvoker4.java
+++ b/src/org/python/modules/jffi/JITInvoker4.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker4 extends JITInvoker {
public JITInvoker4(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(4, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker5.java b/src/org/python/modules/jffi/JITInvoker5.java
--- a/src/org/python/modules/jffi/JITInvoker5.java
+++ b/src/org/python/modules/jffi/JITInvoker5.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker5 extends JITInvoker {
public JITInvoker5(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(5, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITInvoker6.java b/src/org/python/modules/jffi/JITInvoker6.java
--- a/src/org/python/modules/jffi/JITInvoker6.java
+++ b/src/org/python/modules/jffi/JITInvoker6.java
@@ -2,9 +2,6 @@
import org.python.core.PyObject;
-/**
- *
- */
abstract public class JITInvoker6 extends JITInvoker {
public JITInvoker6(com.kenai.jffi.Function function, Invoker fallbackInvoker) {
super(6, function, fallbackInvoker);
diff --git a/src/org/python/modules/jffi/JITMethodGenerator.java b/src/org/python/modules/jffi/JITMethodGenerator.java
--- a/src/org/python/modules/jffi/JITMethodGenerator.java
+++ b/src/org/python/modules/jffi/JITMethodGenerator.java
@@ -1,8 +1,5 @@
package org.python.modules.jffi;
-/**
- *
- */
public interface JITMethodGenerator {
public boolean isSupported(JITSignature signature);
diff --git a/src/org/python/modules/jffi/JITRuntime.java b/src/org/python/modules/jffi/JITRuntime.java
--- a/src/org/python/modules/jffi/JITRuntime.java
+++ b/src/org/python/modules/jffi/JITRuntime.java
@@ -5,9 +5,6 @@
import java.math.BigInteger;
-/**
- *
- */
public final class JITRuntime {
private static final com.kenai.jffi.MemoryIO IO = com.kenai.jffi.MemoryIO.getInstance();
diff --git a/src/org/python/modules/jffi/JITSignature.java b/src/org/python/modules/jffi/JITSignature.java
--- a/src/org/python/modules/jffi/JITSignature.java
+++ b/src/org/python/modules/jffi/JITSignature.java
@@ -1,12 +1,8 @@
package org.python.modules.jffi;
import com.kenai.jffi.CallingConvention;
-
import java.util.Arrays;
-/**
- *
- */
public final class JITSignature {
private final NativeType resultType;
private final NativeType[] parameterTypes;
diff --git a/src/org/python/modules/jffi/Memory.java b/src/org/python/modules/jffi/Memory.java
--- a/src/org/python/modules/jffi/Memory.java
+++ b/src/org/python/modules/jffi/Memory.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
/**
diff --git a/src/org/python/modules/jffi/MemoryOp.java b/src/org/python/modules/jffi/MemoryOp.java
--- a/src/org/python/modules/jffi/MemoryOp.java
+++ b/src/org/python/modules/jffi/MemoryOp.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import org.python.core.Py;
diff --git a/src/org/python/modules/jffi/NativeDataConverter.java b/src/org/python/modules/jffi/NativeDataConverter.java
--- a/src/org/python/modules/jffi/NativeDataConverter.java
+++ b/src/org/python/modules/jffi/NativeDataConverter.java
@@ -1,11 +1,7 @@
package org.python.modules.jffi;
-
import org.python.core.PyObject;
-/**
- *
- */
abstract public class NativeDataConverter {
private final boolean referenceRequired;
private final boolean postInvokeRequired;
diff --git a/src/org/python/modules/jffi/NativeMemory.java b/src/org/python/modules/jffi/NativeMemory.java
--- a/src/org/python/modules/jffi/NativeMemory.java
+++ b/src/org/python/modules/jffi/NativeMemory.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import com.kenai.jffi.Platform;
diff --git a/src/org/python/modules/jffi/NativeType.java b/src/org/python/modules/jffi/NativeType.java
--- a/src/org/python/modules/jffi/NativeType.java
+++ b/src/org/python/modules/jffi/NativeType.java
@@ -1,7 +1,5 @@
-
package org.python.modules.jffi;
-
public enum NativeType {
VOID,
BOOL,
diff --git a/src/org/python/modules/jffi/NullMemory.java b/src/org/python/modules/jffi/NullMemory.java
--- a/src/org/python/modules/jffi/NullMemory.java
+++ b/src/org/python/modules/jffi/NullMemory.java
@@ -1,5 +1,3 @@
-
-
package org.python.modules.jffi;
/**
diff --git a/src/org/python/modules/jffi/Pointer.java b/src/org/python/modules/jffi/Pointer.java
--- a/src/org/python/modules/jffi/Pointer.java
+++ b/src/org/python/modules/jffi/Pointer.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
public interface Pointer {
diff --git a/src/org/python/modules/jffi/PointerCData.java b/src/org/python/modules/jffi/PointerCData.java
--- a/src/org/python/modules/jffi/PointerCData.java
+++ b/src/org/python/modules/jffi/PointerCData.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import org.python.core.Py;
diff --git a/src/org/python/modules/jffi/ScalarCData.java b/src/org/python/modules/jffi/ScalarCData.java
--- a/src/org/python/modules/jffi/ScalarCData.java
+++ b/src/org/python/modules/jffi/ScalarCData.java
@@ -1,14 +1,11 @@
-
package org.python.modules.jffi;
import org.python.core.Py;
import org.python.core.PyFloat;
-import org.python.core.PyInteger;
-import org.python.core.PyLong;
import org.python.core.PyNewWrapper;
import org.python.core.PyObject;
-import org.python.core.PyObject.ConversionException;
import org.python.core.PyType;
+import org.python.core.Visitproc;
import org.python.expose.ExposedClassMethod;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedMethod;
@@ -19,9 +16,9 @@
@ExposedType(name = "jffi.ScalarCData", base = CData.class)
public class ScalarCData extends CData {
public static final PyType TYPE = PyType.fromClass(ScalarCData.class);
- static {
+// static {
// TYPE.fastGetDict().__setitem__("in_dll", new InDll());
- }
+// }
private PyObject value;
@ExposedNew
@@ -121,4 +118,25 @@
public final String toString() {
return getType().getName() + "(" + getValue().toString() + ")";
}
+
+
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ if (value != null) {
+ int res = visit.visit(value, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ return super.traverse(visit, arg);
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ if (ob != null && ob == value) {
+ return true;
+ }
+ return super.refersDirectlyTo(ob);
+ }
}
diff --git a/src/org/python/modules/jffi/StringCData.java b/src/org/python/modules/jffi/StringCData.java
--- a/src/org/python/modules/jffi/StringCData.java
+++ b/src/org/python/modules/jffi/StringCData.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import org.python.core.Py;
@@ -52,7 +51,6 @@
: Py.None;
}
-
@ExposedSet(name = "value")
public void setValue(PyObject value) {
byte[] str = value.asString().getBytes();
@@ -76,6 +74,4 @@
? new String(m.getZeroTerminatedByteArray(0))
: null;
}
-
-
}
diff --git a/src/org/python/modules/jffi/StructLayout.java b/src/org/python/modules/jffi/StructLayout.java
--- a/src/org/python/modules/jffi/StructLayout.java
+++ b/src/org/python/modules/jffi/StructLayout.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import java.util.Arrays;
@@ -20,7 +19,7 @@
import org.python.expose.ExposedType;
@ExposedType(name = "jffi.StructLayout", base = CType.class)
-public class StructLayout extends CType.Custom {
+public class StructLayout extends CType.Custom implements Traverseproc {
public static final PyType TYPE = PyType.fromClass(StructLayout.class);
static {
TYPE.fastGetDict().__setitem__("Field", Field.TYPE);
@@ -207,4 +206,44 @@
StructLayout.Field f = getField(key);
return f != null ? f : Py.None;
}
+
+
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ int res = 0;
+ if (fields != null) {
+ for (Field fld: fields) {
+ res = visit.visit(fld, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ if (fieldMap != null) {
+ for (Object key: fieldMap.keySet()) {
+ if (key instanceof PyObject) {
+ res = visit.visit((PyObject) key, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ if (ob == null) {
+ return false;
+ }
+ if (fields != null && fields.contains(ob)) {
+ return true;
+ }
+ if (fieldMap != null && fieldMap.containsKey(ob)) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/src/org/python/modules/jffi/Structure.java b/src/org/python/modules/jffi/Structure.java
--- a/src/org/python/modules/jffi/Structure.java
+++ b/src/org/python/modules/jffi/Structure.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import java.util.List;
@@ -6,12 +5,14 @@
import org.python.core.PyNewWrapper;
import org.python.core.PyObject;
import org.python.core.PyType;
+import org.python.core.Traverseproc;
+import org.python.core.Visitproc;
import org.python.expose.ExposedClassMethod;
import org.python.expose.ExposedNew;
import org.python.expose.ExposedType;
@ExposedType(name = "jffi.Structure", base = CData.class)
-public class Structure extends CData implements Pointer {
+public class Structure extends CData implements Pointer, Traverseproc {
public static final PyType TYPE = PyType.fromClass(Structure.class);
private final StructLayout layout;
@@ -100,4 +101,23 @@
return getReferenceMemory();
}
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ if (layout != null) {
+ int res = visit.visit(layout, arg);
+ if (res != 0) {
+ return res;
+ }
+ }
+ return super.traverse(visit, arg);
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ if (ob != null && layout == ob) {
+ return true;
+ }
+ return super.refersDirectlyTo(ob);
+ }
}
diff --git a/src/org/python/modules/jffi/Util.java b/src/org/python/modules/jffi/Util.java
--- a/src/org/python/modules/jffi/Util.java
+++ b/src/org/python/modules/jffi/Util.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import java.math.BigInteger;
diff --git a/src/org/python/modules/jffi/jffi.java b/src/org/python/modules/jffi/jffi.java
--- a/src/org/python/modules/jffi/jffi.java
+++ b/src/org/python/modules/jffi/jffi.java
@@ -1,4 +1,3 @@
-
package org.python.modules.jffi;
import com.kenai.jffi.Library;
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list