Skip to content

Commit e21656e

Browse files
committed
wait for GC to clean up weak refs
1 parent a7ee8e7 commit e21656e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ public void exitCApiContext() {
958958
* deallocating objects may run arbitrary guest code that can again call into the
959959
* interpreter.
960960
*/
961-
CApiTransitions.pollReferenceQueue();
961+
CApiTransitions.exitPollCleanup();
962962
PythonThreadState threadState = getContext().getThreadState(getContext().getLanguage());
963963
Object nativeThreadState = PThreadState.getNativeThreadState(threadState);
964964
if (nativeThreadState != null) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ public static PyCapsuleReference registerPyCapsuleDestructor(PyCapsule capsule)
407407
return ref;
408408
}
409409

410+
@TruffleBoundary
411+
public static void exitPollCleanup() {
412+
PythonContext context = PythonContext.get(null);
413+
HandleContext handleContext = context.nativeContext;
414+
int len = handleContext.nativeStubLookup.length;
415+
int idx = 0;
416+
while (idx < len) {
417+
if (handleContext.nativeStubLookup[idx] == null || handleContext.nativeStubLookup[idx].get() != null) {
418+
idx++;
419+
} else {
420+
pollReferenceQueue();
421+
}
422+
}
423+
}
424+
410425
@TruffleBoundary
411426
@SuppressWarnings("try")
412427
public static void pollReferenceQueue() {

0 commit comments

Comments
 (0)