Skip to content

Commit

Permalink
Use reinterpret with correct byte ordering for bits types in jl_stati…
Browse files Browse the repository at this point in the history
…c_show_x_ (partially fixes JuliaLang#28808)
  • Loading branch information
Till Ehrengruber committed Jul 17, 2019
1 parent 5ec1937 commit 8f3af42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 0 additions & 1 deletion contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ function generate_precompile_statements()
include_time = @elapsed for statement in sort(collect(statements))
# println(statement)
# Work around #28808
occursin("Char(0x", statement) && continue
statement == "precompile(Tuple{typeof(Base.show), Base.IOContext{Base.TTY}, Type{Vararg{Any, N} where N}})" && continue
try
Base.include_string(PrecompileStagingArea, statement)
Expand Down
32 changes: 18 additions & 14 deletions src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,22 +978,26 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
else if (jl_datatype_type && jl_is_datatype(vt)) {
int istuple = jl_is_tuple_type(vt), isnamedtuple = jl_is_namedtuple_type(vt);
size_t tlen = jl_datatype_nfields(vt);
if (isnamedtuple) {
if (tlen == 0)
n += jl_printf(out, "NamedTuple");
}
else if (!istuple) {
n += jl_static_show_x(out, (jl_value_t*)vt, depth);
}
n += jl_printf(out, "(");
size_t nb = jl_datatype_size(vt);
if (nb > 0 && tlen == 0) {
uint32_t a = 0x00010203;
uint8_t *endian_bom = (uint8_t*) &a;
uint8_t *data = (uint8_t*)v;
n += jl_printf(out, "0x");
for(int i = nb - 1; i >= 0; --i)
n += jl_printf(out, "%02" PRIx8, data[i]);
}
else {
n += jl_printf(out, "reinterpret(");
n += jl_static_show_x(out, (jl_value_t*)vt, depth);
n += jl_printf(out, ", 0x");
for(int i = 0; i < 4; i++)
n += jl_printf(out, "%02" PRIx8, data[endian_bom[i]]);
n += jl_printf(out, ")");
} else {
if (isnamedtuple) {
if (tlen == 0)
n += jl_printf(out, "NamedTuple");
}
else if (!istuple) {
n += jl_static_show_x(out, (jl_value_t*)vt, depth);
}
n += jl_printf(out, "(");
size_t i = 0;
if (vt == jl_typemap_entry_type)
i = 1;
Expand Down Expand Up @@ -1024,8 +1028,8 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
n += jl_printf(out, ", next=↩︎\n ");
n += jl_static_show_x(out, jl_fieldref_noalloc(v, 0), depth);
}
n += jl_printf(out, ")");
}
n += jl_printf(out, ")");
}
else {
n += jl_printf(out, "<?#%p::", (void*)v);
Expand Down

0 comments on commit 8f3af42

Please sign in to comment.