Skip to content

Commit 5bf53a2

Browse files
committed
Introduce common superclass for all native wrappers.
1 parent dee42c6 commit 5bf53a2

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CArrayWrappers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
package com.oracle.graal.python.builtins.objects.cext;
4040

41+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4142
import com.oracle.truffle.api.interop.ForeignAccess;
4243
import com.oracle.truffle.api.interop.TruffleObject;
4344

@@ -48,7 +49,7 @@
4849
*/
4950
public abstract class CArrayWrappers {
5051

51-
public abstract static class CArrayWrapper implements TruffleObject {
52+
public abstract static class CArrayWrapper extends NativeWrapper {
5253

5354
private Object nativePointer;
5455

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.AsPythonObjectNodeGen;
4646
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.ToJavaNodeGen;
4747
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.ToSulongNodeGen;
48+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4849
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonClassNativeWrapper;
4950
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonNativeWrapper;
5051
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonObjectNativeWrapper;
@@ -128,7 +129,7 @@ Object runNativeObject(PythonAbstractObject object) {
128129
return PythonObjectNativeWrapper.wrap(object);
129130
}
130131

131-
@Specialization(guards = {"isForeignObject(object)"})
132+
@Specialization(guards = {"isForeignObject(object)", "!isNativeWrapper(object)"})
132133
Object doPythonClass(TruffleObject object) {
133134
return TruffleObjectNativeWrapper.wrap(object);
134135
}
@@ -151,8 +152,8 @@ protected static boolean isNativeObject(PythonAbstractObject o) {
151152
return o instanceof PythonNativeObject;
152153
}
153154

154-
protected static boolean isForeignObject(Object o) {
155-
return !(o instanceof PythonAbstractObject);
155+
protected static boolean isNativeWrapper(Object o) {
156+
return o instanceof NativeWrapper;
156157
}
157158

158159
public static ToSulongNode create() {
@@ -220,7 +221,7 @@ protected boolean isForeignObject(TruffleObject obj) {
220221
}
221222

222223
protected boolean isNativeWrapper(Object obj) {
223-
return obj instanceof PythonNativeWrapper;
224+
return obj instanceof NativeWrapper;
224225
}
225226

226227
@TruffleBoundary
@@ -376,13 +377,13 @@ public static FromCharPointerNode create() {
376377
public static class GetNativeClassNode extends PBaseNode {
377378

378379
@Child PCallNativeNode callGetObTypeNode;
379-
@Child ToSulongNode toSulongNode;
380380
@Child ToJavaNode toJavaNode;
381381

382382
@CompilationFinal private TruffleObject func;
383383

384384
public PythonClass execute(PythonNativeObject object) {
385-
Object[] args = new Object[]{getToSulongNode().execute(object.object)};
385+
// do not convert wrap 'object.object' since that is really the native pointer object
386+
Object[] args = new Object[]{object.object};
386387
return (PythonClass) getToJavaNode().execute(getCallGetObTypeNode().execute(getObTypeFunction(), args));
387388
}
388389

@@ -394,14 +395,6 @@ private ToJavaNode getToJavaNode() {
394395
return toJavaNode;
395396
}
396397

397-
private ToSulongNode getToSulongNode() {
398-
if (toSulongNode == null) {
399-
CompilerDirectives.transferToInterpreterAndInvalidate();
400-
toSulongNode = insert(ToSulongNode.create());
401-
}
402-
return toSulongNode;
403-
}
404-
405398
private PCallNativeNode getCallGetObTypeNode() {
406399
if (callGetObTypeNode == null) {
407400
CompilerDirectives.transferToInterpreterAndInvalidate();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/ManagedMethodWrappers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
package com.oracle.graal.python.builtins.objects.cext;
4040

41+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4142
import com.oracle.truffle.api.interop.ForeignAccess;
4243
import com.oracle.truffle.api.interop.TruffleObject;
4344

@@ -46,7 +47,7 @@
4647
*/
4748
public abstract class ManagedMethodWrappers {
4849

49-
public abstract static class MethodWrapper implements TruffleObject {
50+
public abstract static class MethodWrapper extends NativeWrapper {
5051
private final Object method;
5152

5253
public MethodWrapper(Object method) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/NativeWrappers.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
import com.oracle.truffle.api.object.Shape;
5050

5151
public abstract class NativeWrappers {
52-
public abstract static class PythonNativeWrapper implements TruffleObject {
52+
public abstract static class NativeWrapper implements TruffleObject {
53+
}
54+
55+
public abstract static class PythonNativeWrapper extends NativeWrapper {
5356

5457
private Object nativePointer;
5558

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PyAttributeProcsWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
*/
3939
package com.oracle.graal.python.builtins.objects.cext;
4040

41+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4142
import com.oracle.truffle.api.interop.ForeignAccess;
4243
import com.oracle.truffle.api.interop.TruffleObject;
4344

44-
public abstract class PyAttributeProcsWrapper implements TruffleObject {
45+
public abstract class PyAttributeProcsWrapper extends NativeWrapper {
4546

4647
private final Object delegate;
4748

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PyBufferProcsWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
*/
3939
package com.oracle.graal.python.builtins.objects.cext;
4040

41+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4142
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4243
import com.oracle.truffle.api.interop.ForeignAccess;
4344
import com.oracle.truffle.api.interop.TruffleObject;
4445

45-
public class PyBufferProcsWrapper implements TruffleObject {
46+
public class PyBufferProcsWrapper extends NativeWrapper {
4647

4748
private final PythonClass delegate;
4849

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PyNumberMethodsWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
*/
3939
package com.oracle.graal.python.builtins.objects.cext;
4040

41+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.NativeWrapper;
4142
import com.oracle.truffle.api.interop.ForeignAccess;
4243
import com.oracle.truffle.api.interop.TruffleObject;
4344

4445
/**
4546
* Wraps a PythonObject to proviate a native view with a shape like {@code PyNumberMethods}.
4647
*/
47-
public class PyNumberMethodsWrapper implements TruffleObject {
48+
public class PyNumberMethodsWrapper extends NativeWrapper {
4849

4950
private final Object delegate;
5051

0 commit comments

Comments
 (0)