Skip to content

Commit 862fc05

Browse files
committed
Don't free native wrappers before finalizers are called
1 parent 22a9871 commit 862fc05

File tree

1 file changed

+12
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ public Object execute(VirtualFrame frame) {
446446
startTime = System.currentTimeMillis();
447447
}
448448

449+
/*
450+
* Note about the order of operations - we need to call the finalizers first before
451+
* removing the objects from the wrapper list because the finalizers may still make
452+
* upcalls and those need the wrappers to work correctly.
453+
*/
454+
455+
callBulkSubref.call(NativeCAPISymbol.FUN_BULK_SUBREF, new PointerArrayWrapper(nativeObjectReferences), new RefCountArrayWrapper(nativeObjectReferences), (long) n);
456+
457+
if (loggable) {
458+
middleTime = System.currentTimeMillis();
459+
}
460+
449461
if (LOGGER.isLoggable(Level.FINER)) {
450462
// it's not an OSR loop, so we do this before the loop
451463
if (n > 0 && pointerObjectLib == null) {
@@ -474,12 +486,6 @@ public Object execute(VirtualFrame frame) {
474486
}
475487
}
476488

477-
if (loggable) {
478-
middleTime = System.currentTimeMillis();
479-
}
480-
481-
callBulkSubref.call(NativeCAPISymbol.FUN_BULK_SUBREF, new PointerArrayWrapper(nativeObjectReferences), new RefCountArrayWrapper(nativeObjectReferences), (long) n);
482-
483489
if (loggable) {
484490
final long countDuration = middleTime - startTime;
485491
final long duration = System.currentTimeMillis() - middleTime;

0 commit comments

Comments
 (0)