-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add C++ FFI wrappers and use them in CLI. #2133
Conversation
a108e4a
to
80d5b25
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2133 +/- ##
==========================================
+ Coverage 76.88% 76.91% +0.02%
==========================================
Files 193 194 +1
Lines 36976 37042 +66
==========================================
+ Hits 28430 28490 +60
- Misses 8546 8552 +6 ☔ View full report in Codecov by Sentry. |
6c884bd
to
abcb26c
Compare
…o cli_rnp_t methods.
abcb26c
to
c6c702e
Compare
@antonsviridenko @maxirmx @ronaldtse Could you please check whether this approach is good to you? Basically, idea is to add C++ header wrapper around C calls, to make things easier regarding to the memory management (and for those who would like to use library from C++ code). Currently it implements just few functions, but later it could be finalized to the header with full functionality, sitting next to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO there is something wrong with error handling
If you look at the typical call sequence
--> Key::alg --> rnp_key_get_alg -->
rnp_key_get_alg
- returns either RNP_SUCCESS
which is NULL
or catches an exception and returns ffi_exception object
with detailed info (FFI_GUARD
macro)
Key::alg
- if rnp_key_get_alg
return is not RNP_SUCCESS
, creates another exception with less error info and throws it (CALL_FFI
macro)
I think
#define CALL_FFI(func_call) \
do { \
auto __ret__ = func_call; \
if (__ret__) { \
throw ffi_exception(__ret__, #func_call); \
} \
} while (0)
shall be somthing like
template<typename Func, typename... Args>
void call_ffi(Func&& func, Args&&... args) {
auto __ret__ = func(std::forward<Args>(args)...);
if (__ret__) {
throw __ret__;
}
}
so that an exceptions returned from rnp_key_get_alg
and similar functions are propagated
It is also very possible that I did not get the idea :)
@maxirmx
|
Later, once filled up, we could export this header as well for C++ library users.