Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/hx/cppia/Cppia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@ struct CallHaxe : public CppiaExpr
{
unsigned char *pointer = ctx->pointer;
ctx->pushObject(isStatic ? 0: thisExpr ? thisExpr->runObject(ctx) : ctx->getThis(false));
BCR_VCHECK;

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

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

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

void runVoid(CppiaCtx *ctx)
{
CALL_VTABLE_SETUP
CALL_VTABLE_SETUP()
ctx->runVoid(func);
}
int runInt(CppiaCtx *ctx)
{
CALL_VTABLE_SETUP
return runContextConvertInt(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
CALL_VTABLE_SETUP(BCRReturn())
return runContextConvertInt(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
}

Float runFloat(CppiaCtx *ctx)
{
CALL_VTABLE_SETUP
return runContextConvertFloat(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
CALL_VTABLE_SETUP(BCRReturn())
return runContextConvertFloat(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
}
String runString(CppiaCtx *ctx)
{
CALL_VTABLE_SETUP
return runContextConvertString(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
CALL_VTABLE_SETUP(BCRReturn())
return runContextConvertString(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
}
hx::Object *runObject(CppiaCtx *ctx)
{
CALL_VTABLE_SETUP
return runContextConvertObject(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
CALL_VTABLE_SETUP(BCRReturn())
return runContextConvertObject(ctx, checkInterfaceReturnType ? func->getReturnType() : returnType, func);
}

bool isBoolInt() { return boolResult; }
Expand Down Expand Up @@ -3088,6 +3091,8 @@ struct Call : public CppiaDynamicExpr
hx::Object *runObject(CppiaCtx *ctx)
{
hx::Object *funcVal = func->runObject(ctx);
BCR_CHECK;

CPPIA_CHECK_FUNC(funcVal);
int size = args.size();
switch(size)
Expand Down
2 changes: 1 addition & 1 deletion src/hx/cppia/Cppia.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ struct BCRReturn


#define BCR_CHECK if (ctx->breakContReturn || ctx->exception) return BCRReturn();
#define BCR_CHECK_RET(x) if (ctx->breakContReturn) return x;
#define BCR_CHECK_RET(x) if (ctx->breakContReturn || ctx->exception) return x;
#define BCR_VCHECK if (ctx->breakContReturn || ctx->exception) return;


Expand Down
21 changes: 21 additions & 0 deletions test/cppia/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ class Client
default:
}

switch LocalFunctionExceptions.testObjMethodOnReturn() {
case Error(message):
Common.status = 'Failed test for running object method on returned value: ' + message;
return;
default:
}

switch LocalFunctionExceptions.testClassMethodOnReturn() {
case Error(message):
Common.status = 'Failed test for running class method on returned value: ' + message;
return;
default:
}

switch LocalFunctionExceptions.testHostClassMethodOnHostReturn() {
case Error(message):
Common.status = 'Failed test for running host class method on returned value: ' + message;
return;
default:
}

final extending = new ClientExtendedExtendedRoot();

extending.addValue();
Expand Down
1 change: 1 addition & 0 deletions test/cppia/Common.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class Common
public static var callbackSet:Int = 0;
public static var callback: Void->Void;

public function dummyMethod() {}
}
60 changes: 59 additions & 1 deletion test/cppia/LocalFunctionExceptions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ enum Status {
Error(message:String);
}

class DummyClass {
public function run() {}
}

class LocalFunctionExceptions {
static function staticFunction() {
static function staticFunction():Dynamic {
throw 'Thrown from static';
}

Expand Down Expand Up @@ -65,4 +69,58 @@ class LocalFunctionExceptions {

return Error("No exception caught");
}

public static function testObjMethodOnReturn():Status {
function localFunction() {
(staticFunction() : Dynamic).run();
}

try {
localFunction();
} catch (e:Dynamic) {
if (e == 'Thrown from static') {
return Ok;
} else {
return Error("Incorrect exception caught from local function call: " + e);
}
}

return Error("No exception caught");
}

public static function testClassMethodOnReturn():Status {
function localFunction() {
(staticFunction() : DummyClass).run();
}

try {
localFunction();
} catch (e:Dynamic) {
if (e == 'Thrown from static') {
return Ok;
} else {
return Error("Incorrect exception caught from local function call: " + e);
}
}

return Error("No exception caught");
}

public static function testHostClassMethodOnHostReturn():Status {
function localFunction() {
(staticFunction() : Common).dummyMethod();
}

try {
localFunction();
} catch (e:Dynamic) {
if (e == 'Thrown from static') {
return Ok;
} else {
return Error("Incorrect exception caught from local function call: " + e);
}
}

return Error("No exception caught");
}
}
3 changes: 2 additions & 1 deletion test/cppia/compile-host.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
-D dll_export=host_classes.info
-L utest
--dce no
--cpp bin
--cpp bin
-D HXCPP_CATCH_SEGV