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

julia: added a new way to load GAPTypes #3669

Conversation

sebasguts
Copy link
Member

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.

@coveralls
Copy link

coveralls commented Sep 19, 2019

Coverage Status

Coverage decreased (-0.0008%) to 84.442% when pulling 41f78e6 on sebasguts:sebasguts/add_jl_gaptypes_fallback_loader into fcd1f51 on gap-system:master.

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"));
Copy link
Member

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?

Copy link
Member

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;
Copy link
Member

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

@fingolfin fingolfin added topic: julia Julia GC integration and related matters backport-to-4.11 topic: kernel labels Sep 20, 2019
@fingolfin
Copy link
Member

Thanks for working on this.

Ideally, we should finish this ASAP and then backport it to 4.11

@sebasguts sebasguts force-pushed the sebasguts/add_jl_gaptypes_fallback_loader branch 2 times, most recently from 91ec9cb to f85b773 Compare September 21, 2019 13:41
@sebasguts
Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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"));
Copy link
Member

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) {
...

Copy link
Member

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.

@fingolfin fingolfin force-pushed the sebasguts/add_jl_gaptypes_fallback_loader branch from f85b773 to 41f78e6 Compare September 24, 2019 11:01
@fingolfin fingolfin requested a review from rbehrends September 24, 2019 11:03
@fingolfin
Copy link
Member

@sebasguts I refactored your code, please have a look. Also, perhaps @rbehrends could review this PR as well?

@fingolfin fingolfin changed the title Added a new way to load GAPTypes julia: added a new way to load GAPTypes Sep 24, 2019
@rbehrends
Copy link
Contributor

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).

@sebasguts
Copy link
Member Author

I think this should be merged. However, since this is my PR, I cannot approve it.

@fingolfin fingolfin merged commit 361cd4c into gap-system:master Sep 24, 2019
@fingolfin
Copy link
Member

fingolfin commented Oct 4, 2019

Backported to stable-4.11 in commits 1d383b7 and 5a72f72

@fingolfin fingolfin added the release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes label Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-4.11-DONE release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: julia Julia GC integration and related matters topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants