Skip to content

Commit ebfb2c3

Browse files
committed
[cppia] Respect jit exceptions in interp mode
When running in interp mode, native c++ exception handling is used, but when running jit mode, jumps are used along with ctx->exception. This means that an exception thrown from jit mode is not respected in interp mode. This can cause problems with local functions (which are interpreted even in jit mode). When a local function calls a compiled function that throws an exception, the exception is ignored until we return back into a compiled function. This patch fixes the problem by checking ctx->exception when running in interp mode, to make sure that no exception has been thrown from a jit compiled function.
1 parent 9687509 commit ebfb2c3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/hx/cppia/Cppia.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ struct BlockExpr : public CppiaExpr
439439
return;
440440
CppiaExpr **e = &expressions[0];
441441
CppiaExpr **end = e+expressions.size();
442-
for(;e<end && !ctx->breakContReturn;e++)
442+
for(;e<end && !ctx->breakContReturn && !ctx->exception;e++)
443443
{
444444
CPPIA_STACK_LINE((*e));
445445
(*e)->runVoid(ctx);
@@ -800,8 +800,7 @@ struct CallFunExpr : public CppiaExpr
800800
{
801801
unsigned char *pointer = ctx->pointer;
802802
function->pushArgs(ctx,thisExpr?thisExpr->runObject(ctx):ctx->getThis(false),args);
803-
if (ctx->breakContReturn)
804-
return;
803+
BCR_VCHECK;
805804

806805
AutoStack save(ctx,pointer);
807806
ctx->runVoid(function);
@@ -5948,7 +5947,7 @@ struct TVars : public CppiaVoidExpr
59485947
{
59495948
CppiaExpr **v = &vars[0];
59505949
CppiaExpr **end = v + vars.size();
5951-
for(;v<end && !ctx->breakContReturn;v++)
5950+
for(;v<end && !ctx->breakContReturn && !ctx->exception;v++)
59525951
(*v)->runVoid(ctx);
59535952
}
59545953

@@ -5998,8 +5997,14 @@ struct ForExpr : public CppiaVoidExpr
59985997

59995998
while(hasNext())
60005999
{
6000+
if (ctx->exception)
6001+
return;
60016002
var.set(ctx,getNext());
6003+
if (ctx->exception)
6004+
return;
60026005
loop->runVoid(ctx);
6006+
if (ctx->exception)
6007+
return;
60036008

60046009
if (ctx->breakContReturn)
60056010
{
@@ -6045,6 +6050,9 @@ struct WhileExpr : public CppiaVoidExpr
60456050
{
60466051
loop->runVoid(ctx);
60476052

6053+
if (ctx->exception)
6054+
break;
6055+
60486056
if (ctx->breakContReturn)
60496057
{
60506058
if (ctx->breakContReturn & (bcrBreak|bcrReturn))
@@ -6053,7 +6061,7 @@ struct WhileExpr : public CppiaVoidExpr
60536061
ctx->breakContReturn = 0;
60546062
}
60556063

6056-
if (!condition->runInt(ctx) || ctx->breakContReturn)
6064+
if (!condition->runInt(ctx) || ctx->breakContReturn || ctx->exception)
60576065
break;
60586066
}
60596067
ctx->breakContReturn &= ~bcrLoop;

src/hx/cppia/Cppia.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,9 @@ struct BCRReturn
834834
};
835835

836836

837-
#define BCR_CHECK if (ctx->breakContReturn) return BCRReturn();
837+
#define BCR_CHECK if (ctx->breakContReturn || ctx->exception) return BCRReturn();
838838
#define BCR_CHECK_RET(x) if (ctx->breakContReturn) return x;
839-
#define BCR_VCHECK if (ctx->breakContReturn) return;
839+
#define BCR_VCHECK if (ctx->breakContReturn || ctx->exception) return;
840840

841841

842842

0 commit comments

Comments
 (0)