Skip to content

Commit

Permalink
Restore JL_NOTSAFEPOINT in jl_stderr_obj (#56407)
Browse files Browse the repository at this point in the history
This is not a function we're really using, but it's used in the
embedding examples, so I'm sure somebody would complain if I deleted it
or made it a safepoint, so let's just give the same best-effort result
as before.
  • Loading branch information
Keno authored Nov 2, 2024
1 parent 10a1d6f commit 9d1cedb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,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 @@ -360,6 +360,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 @@ -567,7 +567,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

0 comments on commit 9d1cedb

Please sign in to comment.