Open zickgraf opened 2 years ago
Thanks, I'll have a look. BTW, it seems to me your are using an older version of GAP.jl (and hence an older GAP). Not that it makes a difference!
The syntax tree code unfortunately is a bit of a hack in parts. In particular, it calls parts of the AST coder despite not really being run in the right context, and usually "gets away" with that. But not here: SyntaxTreeCodeFunc_Internal
just calls CodeFuncExprBegin
and expects it to work. But that then does this:
SET_GAPNAMEID_BODY(body, GetInputFilenameID(GetCurrentInput()));
But at the time this is executed there is no active GAP input stream. So GetCurrentInput()
returns NULL and we get a crash.
One can verify this with the following snippet:
julia> GAP.Globals.INPUT_FILENAME()
GAP: "*defin*"
This value is only returned by FuncINPUT_FILENAME
if the "current input" is set to NULL.
A proper fix requires adjusting the GAP kernel code. E.g. perhaps CodeFuncExprBegin
should not set the if startLine
is set to 0. Or perhaps GetInputFilenameID
should be modified to deal with a NULL argument, and return a placeholder (so essentially move part FuncINPUT_FILENAME
into GetInputFilenameID
). Gotta think a bit about it.
As a workaround, you could try to ensure there is an active GAP input stream during your call. E.g. by using EvalString
, or rather GAP.evalstr
:
julia> to_syntax_tree_and_back(f::String) = GAP.evalstr("SYNTAX_TREE_CODE(SYNTAX_TREE($f))");
julia> to_syntax_tree_and_back("x -> x")
GAP: function( x ) ... end
Thanks a lot for the fast reply and analysis of the problem! Based on your suggestion I have added a workaround to CompilerForCAP
where we originally encountered this issue: https://github.com/homalg-project/CAP_project/pull/919. Since we never call SYNTAX_TREE_CODE
directly, this fixes the problem for us.
And I have updated my GAP.jl, I still have to get used to the Julia workflow :D
Oops, this was closed automatically; but really, while the fix is in the GAP repo, it's not yet in GAP.jl. I'll leave this open until it is.
The input
leads to a segmentation fault:
The segmentation fault does not occur in a GAP prompt:
cc @mohamed-barakat