-
Notifications
You must be signed in to change notification settings - Fork 190
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
base: master
Are you sure you want to change the base?
Safe Calls #839
Conversation
I can't use catch(Dynamic e) in CFFI integration. Dynamic object not accessible here. Only way is to use callback function. |
Yes, catching is problematic. |
I am using callback from haxe, not cpp. Passing callback haxe function as parameter to CFFI on initializtion. Because it’s on haxe side, callback code can be easily modified. I’ll check how it can be done from cpp. |
Dynamic basically has a single member, mPtr, which is a hx::Object *, which is actually a 'value'. To do the catching in haxe, you could make a "safecaller" instead of a callback. like: static function callback(e:Dynamic) { ... }
static function callSafe(func:Dynamic, arg1:Dynamic)
{
try {
func(arg1);
}
catch(e:Dynamic)
{
callback(e);
}
}
// Then, when you set the callback, do:
library.setSafeCall(callSafe);
// instead of
// library.setCallback(callback);
// from c++:
val_call2(callSafe, func, arg1)
// instead of
// val_call_safe1(func,arg1,callback) |
Using haxe safecaller I can't catch other cpp exceptions, only haxe Dynamic type. In cpp I can use catch(...) for any type, making call really safe. |
I think I am wrong, its possible if I wrap val_call in try / catch: For me performance important, need to check haxe safecaller version ... P.S. Only incontinence now I have two spots for handling exception, one in haxe and one in cpp P.P.S. and safecaller slower: val_call2 -> callsafe -> func chain of calls instead of more direct val_call_safe1 -> func |
This should work if you static-link the nme library. I'm not sure if the
type-information is consistent between dlls and the main program - but I
guess if the catch does not depend on the type, it might just work.
…On Tue, Aug 20, 2019 at 10:00 PM codeservice ***@***.***> wrote:
I think I am wrong, its possible if I wrap val_call in try / catch:
try {
val_call2(callSafe, func, arg1)
} catch(...){
//...
}
For me performance important, need to check haxe safecaller version ...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#839?email_source=notifications&email_token=AAMWTVR4DRWE7R5XPA4SALLQFP2GTA5CNFSM4IJBRPO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4WMPVI#issuecomment-523028437>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMWTVU4DRKPYE5LAFRSGFLQFP2GTANCNFSM4IJBRPOQ>
.
|
Its for different library, not NME. In some cases I can't statically link other libraries. For example, I didn't find way statically link LuaJIT, don't think this even possible. Probably easiest way for me to keep using custom hxcpp modification from my local hxcpp version. |
No description provided.