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

Improve handling of callback functions with scope=notified #125

Closed
jwharm opened this issue Aug 31, 2024 · 0 comments
Closed

Improve handling of callback functions with scope=notified #125

jwharm opened this issue Aug 31, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jwharm
Copy link
Owner

jwharm commented Aug 31, 2024

In Java an "upcall stub" is allocated in case native code wants to callback into a Java method. The upcall stub is allocated in an arena. When the arena is closed, the upcall stub is removed. This introduces a problem for callbacks with scope="notified", because they invoke a GDestroyNotify callback when the original callback is destroyed, and that leaves us with no way to close the arena of the upcall stub for the GDestroyNotify. The current implementation tries to close the arena from inside the GDestroyNotify callback itself, but that causes the JVM to segfault.

A solution could be to create a global static HashMap of arenas for notified callbacks, indexed by the arena hashcode. Then, create a globally-allocated static callback method that satisfies the GDestroyNotify function signature. It reads the arena hashcode from the data argument and closes that arena. Use this callback for all notified function parameters (passing the arena hashcode in the data argument).

If this works, the same principle can be used for g_signal_connect_data, to close the arena for disconnected signals. This currently is a manual action and requires a call to SignalHandler.close(). If that action is unnecessary, the entire SignalHandler API can probably be removed.

@jwharm jwharm added the bug Something isn't working label Aug 31, 2024
@jwharm jwharm closed this as completed in c8734ce Sep 22, 2024
jwharm added a commit that referenced this issue Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant