julia icon indicating copy to clipboard operation
julia copied to clipboard

jl_eval_string(code) for some pieces of code no longer works (julia-1.11.0-beta1) - C wrapper (libjulia.so)

Open gvanuxem opened this issue 3 months ago • 3 comments

These two strings can no longer be evaluated whereas it wasn't problematic with Julia-1.10.0:

"display(@doc rand)" 

"Base.Docs.apropos(rand)"

The piece of C code is as simple as:

// Use '_str' instead of '_string' to avoid conflict with Julia
void jl_eval_str(char* code)
{
    jl_eval_string(code);
    if (jl_exception_occurred()) {
        jl_call2(jl_get_function(jl_base_module, "showerror"),
                jl_stderr_obj(),
                jl_exception_occurred());
        jl_printf(jl_stderr_stream(), "\n");
        jl_exception_clear();
        return;
    }
    return;
}

I don't think it's an input/output problem since (in FriCAS here):

(1) -> juliaVPrint(false)

   (1)  true
                                                                Type: Boolean
(2) -> v:=nrand(4)

   (2)
   [0.9322945304336065, 0.9053609845112013, 1.530009625133267,
    -0.2434827159402031]
                                                     Type: JuliaFloat64Vector
(3) -> juliaVPrint(true)

   (3)  false
                                                                Type: Boolean
(4) -> v

4-element Vector{Float64}:
  0.9322945304336065
  0.9053609845112013
  1.530009625133267
 -0.2434827159402031
   (4)  Julia Output
                                                     Type: JuliaFloat64Vector

And all my tests for other purposes work nicely. The errors corresponding to these two evaluated strings:

(1) -> )tr jl_eval_string

   Function traced: jl_eval_string
(1) -> )jlapropos rand
 1<enter jl_eval_string : "Base.Docs.apropos(rand)"
MethodError: no method matching apropos(::typeof(rand))
The function `apropos` exists, but no method is defined for this combination of argument types.
 1>exit  jl_eval_string : NIL
(1) -> )jldoc rand
 1<enter jl_eval_string : "display(@doc rand)"
nothing
 1>exit  jl_eval_string : NIL
(1) ->

And these two commands are parsed /evaluated correctly in the Julia REPL. I may be wrong, and maybe there is an incompatible change since the 1.11.0 series, if so, I did not notice it.

gvanuxem avatar Apr 14 '24 15:04 gvanuxem

I forgot:

julia> versioninfo()
Julia Version 1.11.0-beta1
Commit 08e1fc0abb9 (2024-04-10 08:40 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

gvanuxem avatar Apr 14 '24 15:04 gvanuxem

That's not specific to embedding, you need to load InteractiveUtils and/or REPL first (which is done automatically only in REPL sessions):

% julia +1.10 -e 'Base.Docs.apropos(rand)'
Core.Compiler.adce_pass!
Base.retry
Base.zero
Base.isassigned
Base.elsize
[...]
% julia +1.10 -e 'using InteractiveUtils, REPL; Base.Docs.apropos(rand)'
Core.Compiler.adce_pass!
Base.retry
Base.zero
Base.isassigned
Base.elsize
[...]
% julia +1.11 -e 'Base.Docs.apropos(rand)'
ERROR: MethodError: no method matching apropos(::typeof(rand))
The function `apropos` exists, but no method is defined for this combination of argument types.
Stacktrace:
 [1] top-level scope
   @ none:1
% julia +1.11 -e 'using InteractiveUtils, REPL; Base.Docs.apropos(rand)'
Core.Compiler.adce_pass!
Base.isassigned
Base.summarysize
Base.accumulate!
Base.@timed
Base.elsize
[...]

giordano avatar Apr 14 '24 18:04 giordano

A "hello world" will not help you ;)

What does that mean?

giordano avatar Apr 15 '24 22:04 giordano