-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor(c-bindings): userdata #785
Conversation
Jenkins BuildsClick to see older builds (41)
|
b9c78bc
to
cdad87e
Compare
cdad87e
to
8c7d25c
Compare
8c7d25c
to
b3bd45f
Compare
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.
It looks really nice!Thanks for this!
However, the approach may be a little bit different from what we need in nwaku
. In nwaku
we have this global variable (now in master
branch) which holds the internal Context struct:
You don't have such a similar context variable, do you?
And, in an upcoming PR we will extract this as a void*
when a waku_init
or waku_new
is called. Then, we will need to pass down this "context" variable from outside the library to the rest of the library function invocations.
On the other hand, I was considering the userData
parameter as a user-defined context, which in the case of Rust, is the address of the closure. I had suggested the creation of the next function, which links the library Context to the user-defined context, although I'd like to revisit this approach: https://github.com/waku-org/nwaku/blob/653a712ba1f6ccab016ddc1ebc9319b572db275f/library/libwaku.nim#L121
@Ivansete-status, For having an extra A problem I also identified while doing this PR is that in the end I might end up adding an additional parameter to the callback: the return code, as I ended up noticing that from inside the callback it is actually not possible to know whether the function was executed correctly or not. So in the end WakuCallback might look like this:
|
Yes correct!
I completely agree with that! I will avoid using the
Sorry but I don't fully understand this reasoning. Let's comment that tomorrow :) |
b3bd45f
to
1fe14c0
Compare
1e2d8ac
to
f29008f
Compare
@harsh-98 @chaitanyaprem sorry for the large PR :( @Ivansete-status I'll extract the context from |
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.
LGTM
Left some minor comments.
f29008f
to
c031167
Compare
Description
Adds an
void* user_data
parameter to all c-bindings API functions so it's possible to use them without having to use global variablesNew API:
Tests