Skip to content

Commit a48d222

Browse files
committed
[cppia] Add missing exception checks
In interp mode, we need to stop immediately if a jit exception has been thrown.
1 parent d570ba3 commit a48d222

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/hx/cppia/Cppia.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,7 @@ struct CallHaxe : public CppiaExpr
17441744
{
17451745
unsigned char *pointer = ctx->pointer;
17461746
ctx->pushObject(isStatic ? 0: thisExpr ? thisExpr->runObject(ctx) : ctx->getThis(false));
1747+
BCR_VCHECK;
17471748

17481749
const char *s = function.signature+1;
17491750
for(int a=0;a<args.size();a++)
@@ -1759,6 +1760,7 @@ struct CallHaxe : public CppiaExpr
17591760
case sigObject: ctx->pushObject( arg->runObject(ctx) ); break;
17601761
default: ;// huh?
17611762
}
1763+
BCR_VCHECK;
17621764
}
17631765

17641766
AutoStack a(ctx,pointer);
@@ -2148,8 +2150,9 @@ struct CallMemberVTable : public CppiaExpr
21482150
ExprType getType() { return returnType; }
21492151
// ScriptCallable **vtable = (ScriptCallable **)thisVal->__GetScriptVTable();
21502152

2151-
#define CALL_VTABLE_SETUP \
2153+
#define CALL_VTABLE_SETUP(errorValue) \
21522154
hx::Object *thisVal = thisExpr ? thisExpr->runObject(ctx) : ctx->getThis(); \
2155+
BCR_CHECK_RET(errorValue); \
21532156
CPPIA_CHECK(thisVal); \
21542157
ScriptCallable **vtable = (!isInterfaceCall ? (*(ScriptCallable ***)((char *)thisVal +scriptVTableOffset)) : (ScriptCallable **) thisVal->__GetScriptVTable()); \
21552158
unsigned char *pointer = ctx->pointer; \
@@ -2160,29 +2163,29 @@ struct CallMemberVTable : public CppiaExpr
21602163

21612164
void runVoid(CppiaCtx *ctx)
21622165
{
2163-
CALL_VTABLE_SETUP
2166+
CALL_VTABLE_SETUP()
21642167
ctx->runVoid(func);
21652168
}
21662169
int runInt(CppiaCtx *ctx)
21672170
{
2168-
CALL_VTABLE_SETUP
2169-
return runContextConvertInt(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
2171+
CALL_VTABLE_SETUP(BCRReturn())
2172+
return runContextConvertInt(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
21702173
}
2171-
2174+
21722175
Float runFloat(CppiaCtx *ctx)
21732176
{
2174-
CALL_VTABLE_SETUP
2175-
return runContextConvertFloat(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
2177+
CALL_VTABLE_SETUP(BCRReturn())
2178+
return runContextConvertFloat(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
21762179
}
21772180
String runString(CppiaCtx *ctx)
21782181
{
2179-
CALL_VTABLE_SETUP
2180-
return runContextConvertString(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
2182+
CALL_VTABLE_SETUP(BCRReturn())
2183+
return runContextConvertString(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
21812184
}
21822185
hx::Object *runObject(CppiaCtx *ctx)
21832186
{
2184-
CALL_VTABLE_SETUP
2185-
return runContextConvertObject(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
2187+
CALL_VTABLE_SETUP(BCRReturn())
2188+
return runContextConvertObject(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
21862189
}
21872190

21882191
bool isBoolInt() { return boolResult; }
@@ -3088,6 +3091,8 @@ struct Call : public CppiaDynamicExpr
30883091
hx::Object *runObject(CppiaCtx *ctx)
30893092
{
30903093
hx::Object *funcVal = func->runObject(ctx);
3094+
BCR_CHECK;
3095+
30913096
CPPIA_CHECK_FUNC(funcVal);
30923097
int size = args.size();
30933098
switch(size)

src/hx/cppia/Cppia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ struct BCRReturn
835835

836836

837837
#define BCR_CHECK if (ctx->breakContReturn || ctx->exception) return BCRReturn();
838-
#define BCR_CHECK_RET(x) if (ctx->breakContReturn) return x;
838+
#define BCR_CHECK_RET(x) if (ctx->breakContReturn || ctx->exception) return x;
839839
#define BCR_VCHECK if (ctx->breakContReturn || ctx->exception) return;
840840

841841

0 commit comments

Comments
 (0)