Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe Calls #839

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions include/hx/CFFIAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,28 @@ DEFFUNC_1(value,alloc_raw_string,int)

// Call Function
DEFFUNC_1(value,val_call0,value)
DEFFUNC_2(value,val_call0_catchexcept,value,value)
DEFFUNC_2(value,val_call1,value,value)
DEFFUNC_3(value,val_call1_catchexcept,value,value,value)
DEFFUNC_3(value,val_call2,value,value,value)
DEFFUNC_4(value,val_call2_catchexcept,value,value,value,value)
DEFFUNC_4(value,val_call3,value,value,value,value)
DEFFUNC_5(value,val_call3_catchexcept,value,value,value,value,value)
DEFFUNC_3(value,val_callN,value,value *,int)
DEFFUNC_4(value,val_callN_catchexcept,value,value *,int,value)

// Call the function - catch and print any exceptions
DEFFUNC_1(value,val_call0_traceexcept,value)

// Call object field
DEFFUNC_2(value,val_ocall0,value,int)
DEFFUNC_3(value,val_ocall0_catchexcept,value,int,value)
DEFFUNC_3(value,val_ocall1,value,int,value)
DEFFUNC_4(value,val_ocall1_catchexcept,value,int,value,value)
DEFFUNC_4(value,val_ocall2,value,int,value,value)
DEFFUNC_5(value,val_ocall2_catchexcept,value,int,value,value,value)
DEFFUNC_4(value,val_ocallN,value,int,value *,int)
DEFFUNC_5(value,val_ocallN_catchexcept,value,int,value *,int,value)

// Objects access
DEFFUNC_1(int,val_id,const char *)
Expand Down
193 changes: 193 additions & 0 deletions src/hx/CFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,25 @@ hx::Object * val_call0(hx::Object * arg1) THROWS
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run().GetPtr();
}
hx::Object * val_call0_catchexcept(hx::Object * arg1, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run().GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}

hx::Object * val_call0_traceexcept(hx::Object * arg1) THROWS
{
Expand All @@ -707,20 +726,77 @@ hx::Object * val_call1(hx::Object * arg1,hx::Object * arg2) THROWS
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2).GetPtr();
}
hx::Object * val_call1_catchexcept(hx::Object * arg1,hx::Object * arg2, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_call2(hx::Object * arg1,hx::Object * arg2,hx::Object * arg3) THROWS
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2,arg3).GetPtr();
}
hx::Object * val_call2_catchexcept(hx::Object * arg1,hx::Object * arg2,hx::Object * arg3, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2,arg3).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_call3(hx::Object * arg1,hx::Object * arg2,hx::Object * arg3,hx::Object * arg4) THROWS
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2,arg3,arg4).GetPtr();
}
hx::Object * val_call3_catchexcept(hx::Object * arg1,hx::Object * arg2,hx::Object * arg3,hx::Object * arg4, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) Dynamic::ThrowBadFunctionError();
return arg1->__run(arg2,arg3,arg4).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_callN(hx::Object * arg1,hx::Object ** arg2, int nCount) THROWS
Expand All @@ -731,6 +807,28 @@ hx::Object * val_callN(hx::Object * arg1,hx::Object ** arg2, int nCount) THROWS
args << *arg2++;
return arg1->__Run( args ).GetPtr();
}
hx::Object * val_callN_catchexcept(hx::Object * arg1,hx::Object ** arg2, int nCount, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) Dynamic::ThrowBadFunctionError();
Array<Dynamic> args = Array_obj<Dynamic>::__new(0, nCount);
while (nCount--)
args << *arg2++;
return arg1->__Run( args ).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


// Call object field
Expand All @@ -739,34 +837,129 @@ hx::Object * val_ocall0(hx::Object * arg1,int arg2) THROWS
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run().GetPtr();
}
hx::Object * val_ocall0_catchexcept(hx::Object * arg1,int arg2, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run().GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_ocall1(hx::Object * arg1,int arg2,hx::Object * arg3) THROWS
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3).GetPtr();
}
hx::Object * val_ocall1_catchexcept(hx::Object * arg1,int arg2,hx::Object * arg3, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_ocall2(hx::Object * arg1,int arg2,hx::Object * arg3,hx::Object * arg4) THROWS
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3,arg4).GetPtr();
}
hx::Object * val_ocall2_catchexcept(hx::Object * arg1,int arg2,hx::Object * arg3,hx::Object * arg4, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3,arg4).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_ocall3(hx::Object * arg1,int arg2,hx::Object * arg3,hx::Object * arg4,hx::Object * arg5) THROWS
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3,arg4,arg5).GetPtr();
}
hx::Object * val_ocall3_catchexcept(hx::Object * arg1,int arg2,hx::Object * arg3,hx::Object * arg4,hx::Object * arg5, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(arg3,arg4,arg5).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}


hx::Object * val_ocallN(hx::Object * arg1,int arg2,hx::Object * arg3) THROWS
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(Dynamic(arg3)).GetPtr();
}
hx::Object * val_ocallN_catchexcept(hx::Object * arg1,int arg2,hx::Object * arg3, hx::Object * fcatch) THROWS
{
try
{
if (!arg1) hx::Throw(HX_INVALID_OBJECT);
return arg1->__IField(arg2)->__run(Dynamic(arg3)).GetPtr();
}
catch(Dynamic e)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(e);
}
catch(...)
{
if(fcatch && fcatch->__ArgCount() == 1)
fcatch->__run(HX_CSTRING("Unknown error"));
}
return 0;
}



Expand Down