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

Restore JL_NOTSAFEPOINT in jl_stderr_obj #56407

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,7 @@ JL_DLLEXPORT jl_sym_t *jl_tagged_gensym(const char *str, size_t len);
JL_DLLEXPORT jl_sym_t *jl_get_root_symbol(void);
JL_DLLEXPORT jl_value_t *jl_get_binding_value(jl_binding_t *b JL_PROPAGATES_ROOT);
JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_const(jl_binding_t *b JL_PROPAGATES_ROOT);
JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved(jl_binding_t *b JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved_and_const(jl_binding_t *b JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_declare_const_gf(jl_binding_t *b, jl_module_t *mod, jl_sym_t *name);
JL_DLLEXPORT jl_method_t *jl_method_def(jl_svec_t *argdata, jl_methtable_t *mt, jl_code_info_t *f, jl_module_t *module);
Expand Down
22 changes: 22 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,28 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved_and_const(jl_binding_t
return decode_restriction_value(pku);
}

JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved(jl_binding_t *b)
{
// Unlike jl_get_binding_value this doesn't try to allocate new binding partitions if they
// don't already exist, making this JL_NOTSAFEPOINT.
if (!b)
return NULL;
jl_binding_partition_t *bpart = jl_atomic_load_relaxed(&b->partitions);
if (!bpart)
return NULL;
size_t max_world = jl_atomic_load_relaxed(&bpart->max_world);
if (bpart->min_world > jl_current_task->world_age || jl_current_task->world_age > max_world)
return NULL;
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed(&bpart->restriction);
if (jl_bkind_is_some_guard(decode_restriction_kind(pku)))
return NULL;
if (jl_bkind_is_some_import(decode_restriction_kind(pku)))
return NULL;
if (jl_bkind_is_some_constant(decode_restriction_kind(pku)))
return decode_restriction_value(pku);
return jl_atomic_load_relaxed(&b->value);
}

JL_DLLEXPORT jl_value_t *jl_bpart_get_restriction_value(jl_binding_partition_t *bpart)
{
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed(&bpart->restriction);
Expand Down
2 changes: 1 addition & 1 deletion src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ JL_DLLEXPORT jl_value_t *jl_stderr_obj(void) JL_NOTSAFEPOINT
if (jl_base_module == NULL)
return NULL;
jl_binding_t *stderr_obj = jl_get_module_binding(jl_base_module, jl_symbol("stderr"), 0);
return stderr_obj ? jl_get_binding_value(stderr_obj) : NULL;
return stderr_obj ? jl_get_binding_value_if_resolved(stderr_obj) : NULL;
}

// toys for debugging ---------------------------------------------------------
Expand Down