bmad-sim / GTPSA.jl

Julia interface to the Generalised Truncated Power Series Algebra (GTPSA) library
https://bmad-sim.github.io/GTPSA.jl/
GNU General Public License v3.0
2 stars 0 forks source link

GTPSA bombs out of Julia on error #110

Closed DavidSagan closed 2 weeks ago

DavidSagan commented 2 weeks ago

Instead of throwing a Julia error the following bombs out of Julia and returns to the Unix command line:

julia> using GTPSA

julia> x = vars()

[82309] signal (11.2): Segmentation fault: 11
in expression starting at REPL[2]:1
unsafe_load at ./pointer.jl:119 [inlined]
unsafe_load at ./pointer.jl:119 [inlined]
numvars at /Users/dcs16/.julia/dev/GTPSA/src/utils.jl:16 [inlined]
vars at /Users/dcs16/.julia/dev/GTPSA/src/ctors.jl:18
vars at /Users/dcs16/.julia/dev/GTPSA/src/ctors.jl:18
unknown function (ip: 0x104ac8093)
... etc.
jl_repl_entrypoint at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-HL2F7YQ3XH.0/build/default-honeycrisp-HL2F7YQ3XH-0/julialang/julia-release-1-dot-10/src/jlapi.c:731
Allocations: 2906 (Pool: 2898; Big: 8); GC: 0
Segmentation fault: 11
MAC:~/.julia/dev/GTPSA> 
mattsignorelli commented 2 weeks ago

This is actually a Julia bug, and is occurring because there is no Descriptor defined. It attempts to use the default Descriptor (which is null) and when "getting" the numvar of that Descriptor it segfaults

Since I don't expect vars to be called often, I could put the check in there (as well as complexvars, params, complexparams). mono, TPS, and ComplexTPS will give a descriptive error from the C code for this because it attempts to create a TPS before getting the number of variables/parameters.

DavidSagan commented 2 weeks ago

Yes a check here would make the package less frustrating to the User.

mattsignorelli commented 2 weeks ago

Fixed in #763f784