JuliaIO / JuliaIO/ObjectFile.jl

Some `display` methods require the IOStream to be still open

Open
#34 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
17
Forks
12
PR merge metrics
No merged PRs in 30d

Description

From https://github.com/JuliaBinaryWrappers/RDKit_jll.jl/releases/download/RDKit-v2022.9.1%2B0/RDKit.v2022.9.1.x86_64-w64-mingw32-cxx11.tar.gz

julia> using ObjectFile

julia> readmeta("./librdkitcffi.dll") do oh
           [s for s in Symbols(oh) if contains(symbol_name(s), r"get_(|q)mol")]
       end
3-element Vector{COFFSymbolRef{COFFHandle{IOStream}}}:
Error showing value of type Vector{COFFSymbolRef{COFFHandle{IOStream}}}:
ERROR: SystemError: seek: Bad file descriptor
Stacktrace:
  [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
    @ Base ./error.jl:176
  [2] #systemerror#80
    @ ./error.jl:175 [inlined]
  [3] systemerror
    @ ./error.jl:175 [inlined]
  [4] seek(s::IOStream, n::UInt64)
    @ Base ./iostream.jl:129
  [5] seek(oh::COFFHandle{IOStream}, pos::UInt64)
    @ ObjectFile ~/.julia/packages/ObjectFile/lbue6/src/Abstract/ObjectHandle.jl:183
  [6] strtab_lookup(strtab::COFFStrTab{COFFHandle{IOStream}}, index::UInt64)
    @ ObjectFile.COFF ~/.julia/packages/ObjectFile/lbue6/src/COFF/COFFStrTab.jl:18
  [7] symbol_name
    @ ~/.julia/packages/ObjectFile/lbue6/src/COFF/COFFSymbol.jl:125 [inlined]
  [8] show(io::IOContext{IOBuffer}, sym::COFFSymbolRef{COFFHandle{IOStream}})
    @ ObjectFile ~/.julia/packages/ObjectFile/lbue6/src/Abstract/Symbol.jl:233
  [9] sprint(f::Function, args::COFFSymbolRef{COFFHandle{IOStream}}; context::IOContext{Base.TTY}, sizehint::Int64)
    @ Base ./strings/io.jl:112
 [10] alignment(io::IOContext{Base.TTY}, x::COFFSymbolRef{COFFHandle{IOStream}})
    @ Base ./show.jl:2735
 [11] alignment(io::IOContext{Base.TTY}, X::AbstractVecOrMat, rows::Vector{Int64}, cols::Vector{Int64}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64, ncols::Int64)
    @ Base ./arrayshow.jl:69
 [12] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
    @ Base ./arrayshow.jl:207
 [13] print_matrix(io::IOContext{Base.TTY}, X::Vector{COFFSymbolRef{COFFHandle{IOStream}}}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64) (repeats 2 times)
    @ Base ./arrayshow.jl:171
 [14] print_array
    @ ./arrayshow.jl:358 [inlined]
 [15] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::Vector{COFFSymbolRef{COFFHandle{IOStream}}})
    @ Base ./arrayshow.jl:399
 [16] (::REPL.var"#43#44"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:267
 [17] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:521
 [18] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:260
 [19] display(d::REPL.REPLDisplay, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:272
 [20] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [21] #invokelatest#2
    @ ./essentials.jl:729 [inlined]
 [22] invokelatest
    @ ./essentials.jl:726 [inlined]
 [23] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:296
 [24] (::REPL.var"#45#46"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:278
 [25] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:521
 [26] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:276
 [27] (::REPL.var"#do_respond#66"{Bool, Bool, REPL.var"#77#87"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:857
 [28] #invokelatest#2
    @ ./essentials.jl:729 [inlined]
 [29] invokelatest
    @ ./essentials.jl:726 [inlined]
 [30] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2510
 [31] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/REPL/src/REPL.jl:1248
 [32] (::REPL.var"#49#54"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:484

This makes it hard to use the readmeta method with the function as first argument (which can be used with the do-block syntax), instead

julia> using ObjectFile

julia> io = open("./librdkitcffi.dll", "r")
IOStream(<file ./librdkitcffi.dll>)

julia> oh = readmeta(io)
COFF Handle (64-bit)

julia> [s for s in Symbols(oh) if contains(symbol_name(s), r"get_(|q)mol")]
3-element Vector{COFFSymbolRef{COFFHandle{IOStream}}}:
 COFF Symbol
       Name: get_mol
      Value: 33824
    Defined: Yes
     Strong: Yes
   Locality: Global
 COFF Symbol
       Name: get_qmol
      Value: 35600
    Defined: Yes
     Strong: Yes
   Locality: Global
 COFF Symbol
       Name: get_molblock
      Value: 52240
    Defined: Yes
     Strong: Yes
   Locality: Global

julia> close(io)

works, but it requires more manual steps.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the readmeta do-block reproduction and compare it with the manual IOStream example. Read ObjectHandle.jl around seek and the display paths for symbol_name and COFFSymbolRef shown in the stack trace. Done means displaying the symbols from the do-block no longer raises Bad file descriptor, while the manual form continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.