-
Notifications
You must be signed in to change notification settings - Fork 162
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
julia: added a new way to load GAPTypes #3669
julia: added a new way to load GAPTypes #3669
Conversation
src/julia_gc.c
Outdated
Panic("Could not read global GAPTypes variable from Julia"); | ||
else { | ||
gaptypes_module = (jl_module_t *)jl_get_global( | ||
jl_main_module, jl_symbol("__GapObj_MODULE_VAR")); |
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.
So, how about we instead get the GAP.jl module, from the already existing global var __JULIAGAPMODULE
. Then, if it exists, it will also have the GAPTypes module as a member, and from that we can get GapObj, no?
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.
Probably also wouldn't hurt to verify we are really getting a module, via jl_is_module
src/julia_gc.c
Outdated
gaptypes_module = (jl_module_t *)jl_get_global( | ||
jl_main_module, jl_symbol("__GapObj_MODULE_VAR")); | ||
if (jl_exception_occurred()) { | ||
go_to_gaptypes_fallback = 1; |
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.
Have you tested this? is there really an exception here. From the quick glance at the Julia code, my impression was that jl_get_global
returns NULL if the binding does not exist. Also, jl_exception_occurred
w/o an explicit exception handler only works for a very, very small set of APIs explicitly designated for this purpose, and I am pretty sure jl_get_global
is not one of them
Thanks for working on this. Ideally, we should finish this ASAP and then backport it to 4.11 |
91ec9cb
to
f85b773
Compare
I think I addressed your comments, and added a lot of checks. I will close the corresponding GAP.jl now. |
src/julia_gc.c
Outdated
jl_eval_string("import GAPTypes"); | ||
if (jl_exception_occurred()) { | ||
Panic("could not import GAPTypes module into Julia"); | ||
UInt gapjl_already_loaded = 1; |
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.
UInt gapjl_already_loaded = 1; | |
UInt gapjl_already_loaded = 0; |
src/julia_gc.c
Outdated
gapjl_module = (jl_module_t *)gapjl_value; | ||
} | ||
else { | ||
gapjl_already_loaded = 0; |
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.
gapjl_already_loaded = 0; |
src/julia_gc.c
Outdated
// Check if we can get the GAP.jl module | ||
if (jl_boundp(jl_main_module, jl_symbol("__JULIAGAPMODULE"))) { | ||
jl_value_t * gapjl_value = | ||
jl_get_global(jl_main_module, jl_symbol("__JULIAGAPMODULE")); |
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.
I am still surprised that the jl_boundp
check is needed. Here is the code for it:
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var)
{
jl_binding_t *b = jl_get_binding(m, var);
return b && (b->value != NULL);
}
... and here is the code for jl_get_global
:
JL_DLLEXPORT jl_value_t *jl_get_global(jl_module_t *m, jl_sym_t *var)
{
jl_binding_t *b = jl_get_binding(m, var);
if (b == NULL) return NULL;
if (b->deprecated) jl_binding_deprecation_warning(m, b);
return b->value;
}
Based on that, I would assume that jl_get_global
returns an error, and does not produce an exception. This is further supported by how the Julia kernel itself uses it, e.g. to quote form Julia's init.c
:
...
jl_value_t *f = jl_get_global(jl_base_module, jl_symbol("_atexit"));
if (f != NULL) {
...
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.
Actually, I just verified it (by running the code): it returns NULL, and does not return an exception.
I will update this PR with an alternative implementation for further discussion.
by getting module and object from a variable
f85b773
to
41f78e6
Compare
@sebasguts I refactored your code, please have a look. Also, perhaps @rbehrends could review this PR as well? |
I have looked at the PR and the companion PR for GAP.jl. They look sensible to me, but I can't claim that I fully understand all of the module import logic (yet). |
I think this should be merged. However, since this is my PR, I cannot approve it. |
by getting module and object from a variable
Description
This fixes the bug here together with a patch for GAP.jl submitted here
Does not need to appear in release notes.