Skip to content

Commit 090bcaa

Browse files
committed
Use indexed table to resolve tagged pointers
1 parent caa0769 commit 090bcaa

File tree

5 files changed

+160
-34
lines changed

5 files changed

+160
-34
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -44,7 +44,9 @@
4444

4545
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ClearNativeWrapperNode;
4646
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
47+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext;
4748
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;
4850
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CArrayWrapper;
4951
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
5052
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccessFactory;
@@ -123,12 +125,21 @@ static void releaseNativeWrapper(PythonNativeWrapper nativeWrapper, CStructAcces
123125
}
124126
if (HandlePointerConverter.pointsToPyHandleSpace(nativePointer)) {
125127
// 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);
128129
} else {
129130
CApiTransitions.nativeLookupRemove(PythonContext.get(freeNode).nativeContext, nativePointer);
130131
}
131132
freeNode.free(nativePointer);
132133
}
133134
}
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+
}
134145
}

0 commit comments

Comments
 (0)