|
110 | 110 | import com.oracle.graal.python.builtins.objects.cext.common.CExtContext;
|
111 | 111 | import com.oracle.graal.python.builtins.objects.cext.common.CExtContext.ModuleSpec;
|
112 | 112 | import com.oracle.graal.python.builtins.objects.cext.common.GetNextVaArgNode;
|
| 113 | +import com.oracle.graal.python.builtins.objects.cext.common.NativePointer; |
113 | 114 | import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
|
114 | 115 | import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
|
115 | 116 | import com.oracle.graal.python.builtins.objects.cext.structs.CStructs;
|
@@ -1104,20 +1105,36 @@ public static void executeUncached(Object pointer) {
|
1104 | 1105 | public abstract void execute(Node inliningTarget, Object pointer);
|
1105 | 1106 |
|
1106 | 1107 | @Specialization
|
1107 |
| - static void doDecref(Node inliningTarget, Object pointer, |
| 1108 | + static void doDecref(Node inliningTarget, Object pointerObj, |
| 1109 | + @CachedLibrary(limit = "2") InteropLibrary lib, |
1108 | 1110 | @Cached(inline = false) CApiTransitions.ToPythonWrapperNode toPythonWrapperNode,
|
1109 | 1111 | @Cached InlinedBranchProfile isWrapperProfile,
|
1110 | 1112 | @Cached InlinedBranchProfile isNativeObject,
|
1111 | 1113 | @Cached(inline = false) CStructAccess.ReadI64Node readRefcount,
|
1112 | 1114 | @Cached(inline = false) CStructAccess.WriteLongNode writeRefcount,
|
1113 | 1115 | @Cached(inline = false) PCallCapiFunction callDealloc) {
|
| 1116 | + long pointer; |
| 1117 | + if (pointerObj instanceof Long longPointer) { |
| 1118 | + pointer = longPointer; |
| 1119 | + } else { |
| 1120 | + if (lib.isPointer(pointerObj)) { |
| 1121 | + try { |
| 1122 | + pointer = lib.asPointer(pointerObj); |
| 1123 | + } catch (UnsupportedMessageException e) { |
| 1124 | + throw CompilerDirectives.shouldNotReachHere(); |
| 1125 | + } |
| 1126 | + } else { |
| 1127 | + // No refcounting in managed mode |
| 1128 | + return; |
| 1129 | + } |
| 1130 | + } |
1114 | 1131 | PythonNativeWrapper wrapper = toPythonWrapperNode.executeWrapper(pointer, false);
|
1115 | 1132 | if (wrapper instanceof PythonAbstractObjectNativeWrapper objectWrapper) {
|
1116 | 1133 | isWrapperProfile.enter(inliningTarget);
|
1117 | 1134 | objectWrapper.decRef();
|
1118 | 1135 | } else if (wrapper == null) {
|
1119 | 1136 | isNativeObject.enter(inliningTarget);
|
1120 |
| - assert NativeToPythonNode.executeUncached(pointer) instanceof PythonAbstractNativeObject; |
| 1137 | + assert NativeToPythonNode.executeUncached(new NativePointer(pointer)) instanceof PythonAbstractNativeObject; |
1121 | 1138 | long refcount = readRefcount.read(pointer, PyObject__ob_refcnt);
|
1122 | 1139 | if (refcount != IMMORTAL_REFCNT) {
|
1123 | 1140 | refcount--;
|
|
0 commit comments