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

Constant can be set multiple times with jl_set_const #55921

Closed
Taaitaaiger opened this issue Sep 28, 2024 · 3 comments
Closed

Constant can be set multiple times with jl_set_const #55921

Taaitaaiger opened this issue Sep 28, 2024 · 3 comments
Labels
embedding Embedding Julia using the C API

Comments

@Taaitaaiger
Copy link
Contributor

The following code succeeds on nightly:

#include <julia.h>

JULIA_DEFINE_FAST_TLS

int main(int argc, char *argv[])
{
    jl_init();

    {
        jl_value_t *v1 = NULL;
        jl_value_t *v2 = NULL;
        JL_GC_PUSH2(v1, v2);
        
        jl_sym_t *s = jl_symbol("foo");
        v1 = jl_box_uint8(3);
        v2 = jl_box_uint8(4);

        jl_set_const(jl_main_module, s, v1);
        jl_set_const(jl_main_module, s, v2);

        JL_GC_POP();
    }

    jl_atexit_hook(0);
    return 0;
}

Previously this caused an error:

fatal: error thrown and no exception handler available.
ErrorException("invalid redefinition of constant foo")
ijl_errorf at /cache/build/builder-amdci4-4/julialang/julia-release-1-dot-10/src/rtutils.c:77
ijl_set_const at /cache/build/builder-amdci4-4/julialang/julia-release-1-dot-10/src/module.c:798 [inlined]
ijl_set_const at /cache/build/builder-amdci4-4/julialang/julia-release-1-dot-10/src/module.c:792
main at ./test (unknown line)
unknown function (ip: 0x7163d522a1c9)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_start at ./test (unknown line)

Tested on Linux with commit ff0a1be

@Taaitaaiger
Copy link
Contributor Author

The code can be compiled as in the embedding docs: gcc -o test -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib -Wl,-rpath,$JULIA_DIR/lib test.c -ljulia

@giordano giordano added the embedding Embedding Julia using the C API label Sep 28, 2024
@Keno
Copy link
Member

Keno commented Sep 29, 2024

This part of the code is in flux and constant re-definition (via binding partition) will be allowed in 1.12. The current state of the code is mostly the new code with extra error checks to make Julia behave as it did before.

@Taaitaaiger
Copy link
Contributor Author

Ah okay, then this isn't a bug. From what I can tell I should look at #54654 for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedding Embedding Julia using the C API
Projects
None yet
Development

No branches or pull requests

3 participants