Skip to content

Commit

Permalink
fix JuliaLang#46918, unstable jl_binding_type behavior (JuliaLang#4…
Browse files Browse the repository at this point in the history
…6994)

Now it will return `nothing` before the binding has been resolved,
and afterward fully look up the binding as declared by the owner.
  • Loading branch information
JeffBezanson committed Oct 12, 2022
1 parent e304cd5 commit 9104c20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ JL_DLLEXPORT jl_value_t *jl_binding_owner(jl_module_t *m, jl_sym_t *var)
JL_DLLEXPORT jl_value_t *jl_binding_type(jl_module_t *m, jl_sym_t *var)
{
JL_LOCK(&m->lock);
jl_binding_t *b = (jl_binding_t*)ptrhash_get(&m->bindings, var);
if (b == HT_NOTFOUND || b->owner == NULL)
b = using_resolve_binding(m, var, NULL, 0);
jl_binding_t *b = _jl_get_module_binding(m, var);
JL_UNLOCK(&m->lock);
if (b == NULL)
if (b == HT_NOTFOUND || b->owner == NULL)
return jl_nothing;
b = jl_get_binding(m, var);
jl_value_t *ty = jl_atomic_load_relaxed(&b->ty);
return ty ? ty : jl_nothing;
}
Expand Down
21 changes: 21 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7845,3 +7845,24 @@ module SpecializeModuleTest
@specialize
end
@test methods(SpecializeModuleTest.f)[1].nospecialize & 0b11 == 0b10

let # https://github.com/JuliaLang/julia/issues/46918
# jl_binding_type shouldn't be unstable
code = quote
res1 = ccall(:jl_binding_type, Any, (Any, Any), Main, :stderr)

stderr

res2 = ccall(:jl_binding_type, Any, (Any, Any), Main, :stderr)

res3 = ccall(:jl_binding_type, Any, (Any, Any), Main, :stderr)

print(stdout, res1, " ", res2, " ", res3)
end |> x->join(x.args, ';')
cmd = `$(Base.julia_cmd()) -e $code` # N.B make sure not to pass this code as `:block`
stdout = IOBuffer()
stderr = IOBuffer()
@test success(pipeline(Cmd(cmd); stdout, stderr))
@test isempty(String(take!(stderr))) # make sure no error has happened
@test String(take!(stdout)) == "nothing IO IO"
end

0 comments on commit 9104c20

Please sign in to comment.