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

First stab at generating JNI callbacks #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jimrthy
Copy link
Owner

@jimrthy jimrthy commented Jun 4, 2017

This doesn't seem like a change to commit into master. It's more of a
starting point for a conversation about the pieces that are still
missing.

This doesn't seem like a change to commit into master. It's more of a
starting point for a conversation about the pieces that are still
missing.
Copy link
Owner Author

@jimrthy jimrthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the holes in the current approach that I'm not sure how to fill

. # TODO: verify that these don't duplicate
$(type)_cb_wrapper(\
. # This method signature needs to be built on the model's knowledge of
. # the function callback type
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a recurring theme here.

. elsif type = "zloop_timer_fn"
zloop_t *loop, int timer_id, void *arg\
. else
garbage *unknown, void *arg\
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a better way to shortcut on "unknown callback type."

But the root cause is that I don't know how to find out what we know about this callback

. else
Int\
. endif
Method(env, wrapper->obj, wrapper->mid, wrapper->args);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a different, but related, issue here.
We need to invoke the callback with the relevant callback args that we got here in addition to wrapper->args.
It's easy enough to do with the same sort of if/elsif construct I used above, but that approach already feels ridiculous.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to make this happen with the current approach, we really need multiple ICallback variations. Each with an appropriate method signature.

// Shortcut to throw a NoSuchMethodError
return;
}
$(type) $(c_name)_$(type) = $(type)_cb_wrapper;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This $(c_name)_$(type) approach to generating a parameter name leaves a lot to be desired.
If nothing else, it's duplicated in too many places for comfort and should be part of the container's data instead.

@@ -899,6 +948,14 @@ $(project.GENERATED_WARNING_HEADER:)
#include "$(project.header:)"
#include "$(my.cname:).h"

// TODO: This doesn't really belong in here
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just fuzzy about a) where would be better and b) the best way to make that happen

@@ -169,6 +195,7 @@ function resolve_method (method)

if variadic = 1
if va_start <> "format"
# I think this is where the Zloop constructor breaks
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different issue. Doesn't belong here.

@@ -197,6 +224,8 @@ function resolve_method (method)
jni_native_invocation_c += "$(comma)($(argument.c_type)) (intptr_t) &$(argument.c_name)"
elsif jni_is_class = 1 | type = "anything" | type = "sockish"
jni_native_invocation_c += "$(comma)($(argument.c_type)) (intptr_t) $(argument.c_name)"
elsif argument.callback ?= 1
jni_native_invocation_c += "$(comma) $(argument.c_name)_$(argument.type)"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big gaping hole: need to replace the "args" parameter with a pointer to a jni_cb_struct.
Which means we need to malloc that. And make sure it gets freed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant