Skip to content

Commit 7fdb35d

Browse files
committed
warn, but not crash, on unbalanced protect/unprotect
1 parent 6f5390e commit 7fdb35d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,11 +1617,20 @@ public Object Rf_protect(Object x) {
16171617
public void Rf_unprotect(int x) {
16181618
RFFIContext context = getContext();
16191619
ArrayList<RObject> stack = context.rffiContextState.protectStack;
1620-
for (int i = 0; i < x; i++) {
1621-
context.registerReferenceUsedInNative(stack.remove(stack.size() - 1));
1620+
try {
1621+
for (int i = 0; i < x; i++) {
1622+
context.registerReferenceUsedInNative(stack.remove(stack.size() - 1));
1623+
}
1624+
} catch (ArrayIndexOutOfBoundsException e) {
1625+
debugWarning("mismatched protect/unprotect (unprotect with empty protect stack)");
16221626
}
16231627
}
16241628

1629+
private static boolean debugWarning(String message) {
1630+
RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, message);
1631+
return true;
1632+
}
1633+
16251634
@Override
16261635
@TruffleBoundary
16271636
public int R_ProtectWithIndex(Object x) {

0 commit comments

Comments
 (0)