Skip to content
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
6 changes: 3 additions & 3 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
end
if lasterr !== nothing
lasterr = scrub_repl_backtrace(lasterr)
istrivialerror(lasterr) || ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :err, lasterr)
istrivialerror(lasterr) || setglobal!(Main, :err, lasterr)
invokelatest(display_error, errio, lasterr)
errcount = 0
lasterr = nothing
else
ast = Meta.lower(Main, ast)
value = Core.eval(Main, ast)
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :ans, value)
setglobal!(Main, :ans, value)
if !(value === nothing) && show_value
if have_color
print(answer_color())
Expand All @@ -151,7 +151,7 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
end
errcount += 1
lasterr = scrub_repl_backtrace(current_exceptions())
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :err, lasterr)
setglobal!(Main, :err, lasterr)
if errcount > 2
@error "It is likely that something important is broken, and Julia will not be able to continue normally" errcount
break
Expand Down
3 changes: 2 additions & 1 deletion doc/src/manual/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ As an alternative for very simple cases, it is possible to just create a global
per pointer using

```c
jl_set_global(jl_main_module, jl_symbol("var"), var);
jl_binding_t *bp = jl_get_binding_wr(jl_main_module, jl_symbol("var"), 1);
jl_checked_assignment(bp, val);
```

### Updating fields of GC-managed objects
Expand Down
1 change: 1 addition & 0 deletions src/builtin_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ DECLARE_BUILTIN(typeof);
DECLARE_BUILTIN(_typevar);
DECLARE_BUILTIN(donotdelete);
DECLARE_BUILTIN(getglobal);
DECLARE_BUILTIN(setglobal);

JL_CALLABLE(jl_f_invoke_kwsorter);
#ifdef DEFINE_BUILTIN_GLOBALS
Expand Down
6 changes: 3 additions & 3 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ JL_CALLABLE(jl_f_setglobal)
if (order == jl_memory_order_notatomic)
jl_atomic_error("setglobal!: module binding cannot be written non-atomically");
// is seq_cst already, no fence needed
jl_binding_t *b = jl_get_binding_wr((jl_module_t*)args[0], (jl_sym_t*)args[1], 1);
jl_binding_t *b = jl_get_binding_wr_or_error((jl_module_t*)args[0], (jl_sym_t*)args[1]);
jl_checked_assignment(b, args[2]);
return args[2];
}
Expand All @@ -1218,7 +1218,7 @@ JL_CALLABLE(jl_f_get_binding_type)
jl_value_t *ty = jl_binding_type(mod, sym);
if (ty == (jl_value_t*)jl_nothing) {
jl_binding_t *b = jl_get_binding_wr(mod, sym, 0);
if (b) {
if (b && b->owner == mod) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, good catch!

jl_value_t *old_ty = NULL;
jl_atomic_cmpswap_relaxed(&b->ty, &old_ty, (jl_value_t*)jl_any_type);
return jl_atomic_load_relaxed(&b->ty);
Expand Down Expand Up @@ -1920,7 +1920,7 @@ void jl_init_primitives(void) JL_GC_DISABLED

// module bindings
jl_builtin_getglobal = add_builtin_func("getglobal", jl_f_getglobal);
add_builtin_func("setglobal!", jl_f_setglobal);
jl_builtin_setglobal = add_builtin_func("setglobal!", jl_f_setglobal);
add_builtin_func("get_binding_type", jl_f_get_binding_type);
add_builtin_func("set_binding_type!", jl_f_set_binding_type);

Expand Down
15 changes: 6 additions & 9 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,22 @@ static Value *maybe_bitcast(jl_codectx_t &ctx, Value *V, Type *to) {
return V;
}

static Value *julia_binding_gv(jl_codectx_t &ctx, Value *bv)
static Value *julia_binding_pvalue(jl_codectx_t &ctx, Value *bv)
{
bv = emit_bitcast(ctx, bv, ctx.types().T_pprjlvalue);
Value *offset = ConstantInt::get(getSizeTy(ctx.builder.getContext()), offsetof(jl_binding_t, value) / sizeof(size_t));
return ctx.builder.CreateInBoundsGEP(ctx.types().T_prjlvalue, bv, offset);
}

static Value *julia_binding_gv(jl_codectx_t &ctx, jl_binding_t *b)
{
// emit a literal_pointer_val to the value field of a jl_binding_t
// emit a literal_pointer_val to a jl_binding_t
// binding->value are prefixed with *
Value *bv;
if (imaging_mode)
bv = emit_bitcast(ctx,
tbaa_decorate(ctx.tbaa().tbaa_const,
ctx.builder.CreateAlignedLoad(ctx.types().T_pjlvalue, julia_pgv(ctx, "*", b->name, b->owner, b), Align(sizeof(void*)))),
ctx.types().T_pprjlvalue);
return tbaa_decorate(ctx.tbaa().tbaa_const, ctx.builder.CreateAlignedLoad(ctx.types().T_pjlvalue,
julia_pgv(ctx, "*", b->name, b->owner, b), Align(sizeof(void*))));
else
bv = ConstantExpr::getBitCast(literal_static_pointer_val(b, ctx.types().T_pjlvalue), ctx.types().T_pprjlvalue);
return julia_binding_gv(ctx, bv);
return literal_static_pointer_val(b, ctx.types().T_pjlvalue);
}

// --- mapping between julia and llvm types ---
Expand Down
Loading