SoftGlobalScope.jl icon indicating copy to clipboard operation
SoftGlobalScope.jl copied to clipboard

Unlike `include_string`, `softscope_include_string` doesn't set `jl_filename`

Open NHDaly opened this issue 5 years ago • 1 comments

I haven't yet found anywhere in normal julia code that this matters yet, but include_string() sets the C variable jl_filename during its processing, but softscope_include_string does not.

I'm not sure if it's kosher, but we've been reading this variable for our own error-reporting when parsing user input strings in our internal API in our project (by reading jl_filename() = unsafe_string(unsafe_load(cglobal(:jl_filename, Cstring)))).

This currently doesn't work in IJulia, since jl_filename isn't set.

I would guess this is also used for error reporting somewhere in julia, or it wouldn't be stored, but i haven't seen any such instances yet..

NHDaly avatar May 17 '19 19:05 NHDaly

It's set by include_string() here: https://github.com/JuliaLang/julia/blob/3754ead9dcea86fcd0e6a0a9ce1a9a50175eaef8/src/ast.c#L841

(include_string -> jl_load_file_string -> jl_parse_eval_all)

I think an easy fix would just be to wrap softscope_include_string with the following lines:

    jl_filename_ptr = cglobal(:jl_filename, Cstring)
    prev_file = unsafe_load(jl_filename_ptr)
    unsafe_store!(jl_filename_ptr, Cstring(pointer(filename)))

    # ...

    unsafe_store!(jl_filename_ptr, prev_file)
    return retval

And that fixes our usecase when i've tested locally.

NHDaly avatar May 17 '19 19:05 NHDaly