|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
|
44 | 44 |
|
45 | 45 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ClearNativeWrapperNode;
|
46 | 46 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
|
| 47 | +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext; |
47 | 48 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter;
|
| 49 | +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonObjectReference; |
48 | 50 | import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CArrayWrapper;
|
49 | 51 | import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
|
50 | 52 | import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccessFactory;
|
@@ -123,12 +125,21 @@ static void releaseNativeWrapper(PythonNativeWrapper nativeWrapper, CStructAcces
|
123 | 125 | }
|
124 | 126 | if (HandlePointerConverter.pointsToPyHandleSpace(nativePointer)) {
|
125 | 127 | // In this case, we are up to free a native object stub.
|
126 |
| - nativePointer = HandlePointerConverter.pointerToStub(nativePointer); |
127 |
| - assert CApiTransitions.nativeStubLookupGet(PythonContext.get(freeNode).nativeContext, nativePointer) == null; |
| 128 | + assert tableEntryRemoved(PythonContext.get(freeNode).nativeContext, nativeWrapper); |
128 | 129 | } else {
|
129 | 130 | CApiTransitions.nativeLookupRemove(PythonContext.get(freeNode).nativeContext, nativePointer);
|
130 | 131 | }
|
131 | 132 | freeNode.free(nativePointer);
|
132 | 133 | }
|
133 | 134 | }
|
| 135 | + |
| 136 | + private static boolean tableEntryRemoved(HandleContext context, PythonNativeWrapper nativeWrapper) { |
| 137 | + PythonObjectReference ref = nativeWrapper.ref; |
| 138 | + if (ref != null) { |
| 139 | + int id = ref.getId(); |
| 140 | + return id <= 0 || CApiTransitions.nativeStubLookupGet(context, nativeWrapper.getNativePointer(), id) == null; |
| 141 | + } |
| 142 | + // there cannot be a table entry if the wrapper does not have a PythonObjectReference |
| 143 | + return true; |
| 144 | + } |
134 | 145 | }
|
0 commit comments