From c7cb673130cbfe54a991edcd695f497b4d9c738a Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Wed, 17 Jul 2019 11:35:13 +0200 Subject: [PATCH] Use reinterpret with correct byte ordering for bits types in jl_static_show_x_ (partially fixes #28808) --- contrib/generate_precompile.jl | 1 - src/rtutils.c | 32 ++++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/contrib/generate_precompile.jl b/contrib/generate_precompile.jl index c1f5b16363f2a9..0b60d3a2a71f66 100644 --- a/contrib/generate_precompile.jl +++ b/contrib/generate_precompile.jl @@ -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) diff --git a/src/rtutils.c b/src/rtutils.c index 184356ad7cfa73..e50cc1a6b1a584 100644 --- a/src/rtutils.c +++ b/src/rtutils.c @@ -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; @@ -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, "