|
80 | 80 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
|
81 | 81 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext;
|
82 | 82 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
|
| 83 | +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonObjectReference; |
83 | 84 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.ToPythonWrapperNode;
|
84 | 85 | import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.CheckFunctionResultNode;
|
85 | 86 | import com.oracle.graal.python.builtins.objects.cext.common.CExtContext;
|
@@ -875,16 +876,28 @@ public void finalizeCapi() {
|
875 | 876 | CApiTransitions.disableReferenceQueuePolling(getContext().nativeContext);
|
876 | 877 | // TODO(fa): remove GIL acquisition (GR-51314)
|
877 | 878 | try (GilNode.UncachedAcquire gil = GilNode.uncachedAcquire()) {
|
| 879 | + HandleContext nativeContext = getContext().nativeContext; |
878 | 880 | freeSmallInts();
|
879 | 881 | for (int i = 0; i < singletonNativePtrs.length; i++) {
|
880 | 882 | PythonNativeWrapper singletonNativeWrapper = singletonNativePtrs[i];
|
881 | 883 | singletonNativePtrs[i] = null;
|
882 | 884 | assert singletonNativeWrapper != null;
|
883 | 885 | if (singletonNativeWrapper.ref != null) {
|
884 |
| - CApiTransitions.nativeStubLookupRemove(getContext().nativeContext, singletonNativeWrapper.ref); |
| 886 | + CApiTransitions.nativeStubLookupRemove(nativeContext, singletonNativeWrapper.ref); |
885 | 887 | }
|
886 | 888 | PyTruffleObjectFree.releaseNativeWrapperUncached(singletonNativeWrapper);
|
887 | 889 | }
|
| 890 | + /* |
| 891 | + * Clear all remaining native object stubs. This must be done after the small int and |
| 892 | + * the singleton wrappers were cleared because they might also end up in the lookup |
| 893 | + * table and may otherwise be double-free'd. |
| 894 | + */ |
| 895 | + for (PythonObjectReference ref : nativeContext.nativeStubLookup) { |
| 896 | + if (ref != null) { |
| 897 | + CApiTransitions.nativeStubLookupRemove(nativeContext, ref); |
| 898 | + CApiTransitions.freeNativeStub(ref); |
| 899 | + } |
| 900 | + } |
888 | 901 | }
|
889 | 902 | if (pyDateTimeCAPICapsule != null) {
|
890 | 903 | PyDateTimeCAPIWrapper.destroyWrapper(pyDateTimeCAPICapsule);
|
|
0 commit comments