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

Callback on a CLang code block? #571

Open
srs opened this issue Dec 31, 2015 · 6 comments
Open

Callback on a CLang code block? #571

srs opened this issue Dec 31, 2015 · 6 comments

Comments

@srs
Copy link

srs commented Dec 31, 2015

Hi.

I am trying to call a method on OSX that takes a closure (CLang Block) as an argument. The method is xpc_connection_set_event_handler and the signature is as follows:

typedef void (*xpc_connection_handler_t)(xpc_connection_t connection);

typedef void (^xpc_handler_t)(xpc_object_t object);

void xpc_connection_set_event_handler(xpc_connection_t connection, xpc_handler_t handler); 

Right now I am calling it using a JNA Callback but that does not seem to work. Anyone that have done the same or similar calling to a closure (or code block)?

BR,
Sten Roger

@twall
Copy link
Contributor

twall commented Jan 1, 2016

JNA doesn’t have any built-in awareness of clang blocks. You might be able to manually construct the required data to pass as an argument, but that would require delving into the runtime specifics of the blocks implementation.

JNA will create a stack-based code stub, the address of which is used as a function pointer and which, when run, transfers execution to the associated JNA Callback.

On Dec 31, 2015, at 5:12 PM, Sten Roger Sandvik [email protected] wrote:

Hi.

I am trying to call a method on OSX that takes a closure (CLang Block) as an argument. The method is xpc_connection_set_event_handler and the signature is as follows:

typedef void (*xpc_connection_handler_t)(xpc_connection_t connection);

typedef void (^xpc_handler_t)(xpc_object_t object);

void xpc_connection_set_event_handler(xpc_connection_t connection, xpc_handler_t handler);

Right now I am calling it using a JNA Callback but that does not seem to work. Anyone that have done the same or similar calling to a closure (or code block)?

BR,
Sten Roger


Reply to this email directly or view it on GitHub.

@srs
Copy link
Author

srs commented Jan 2, 2016

Thanks.

Well, it seems to me that I need to do some plain JNI code here. Have tried to construct the code-block struct and pass that without any luck. Maybe I'm missing some pieces here and there.

BR,
Sten Roger

@srs srs closed this as completed Jan 2, 2016
@srs srs reopened this Jan 2, 2016
@srs srs closed this as completed Jan 2, 2016
@ghazel
Copy link

ghazel commented Apr 30, 2016

It would be pretty helpful for JNA to support clang blocks. Creating the struct and code stub is totally possible, here's an example using libffi just like JNA does: https://www.mikeash.com/pyblog/friday-qa-2011-05-06-a-tour-of-mablockclosure.html

@twall
Copy link
Contributor

twall commented May 8, 2016

PRs are welcome.

@dkocher
Copy link
Contributor

dkocher commented Dec 21, 2020

I would like to fund development of this implementation. Please reach out if interested to make this happen.

@dkocher
Copy link
Contributor

dkocher commented Dec 27, 2020

@twall I would like to see this issue reopened to keep it as a label:"feature request".

mstyura pushed a commit to mstyura/jna that referenced this issue Sep 9, 2024
Motivation:

Let's use the commit sha of quiche for the 0.18.0 release.

Modifications:

- Change quiche sha
- Skip building of apps as its not needed

Result:

Use sha that represent the latest quiche release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants