Skip to content

Commit

Permalink
HACK-WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Apr 14, 2022
1 parent 2589409 commit 1d9026d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/exec.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Replacement for the GAP kernel function ExecuteProcess
const use_orig_ExecuteProcess = Ref{Bool}(false)
function GAP_ExecuteProcess(dir::GapObj, prg::GapObj, in::Int, out::Int, args::GapObj)
if use_orig_ExecuteProcess[]
return GAP.Globals._ORIG_ExecuteProcess(dir, prg, in, out, args)
function GAP_Error(args...)
gapargs = [Obj(x) for x in args]
GAP.Globals.Error(gapargs...)
end

function GAP_ExecuteProcess(dir::Any, prg::Any, in::Any, out::Any, args::Any)
(dir isa GapObj && Wrappers.IsString(dir)) || GAP_Error("ExecuteProcess: <dir> must be a string (not the value '", dir, "')")
(prg isa GapObj && Wrappers.IsString(prg)) || GAP_Error("ExecuteProcess: <prg> must be a string (not the value '", prg, "')")
in isa Int || GAP_Error("ExecuteProcess: <in> must be a small integer (not the value '", in, "')")
out isa Int || GAP_Error("ExecuteProcess: <out> must be a small integer (not the value '", out, "')")
(args isa GapObj && Wrappers.IsList(args)) || GAP_Error("ExecuteProcess: <args> must be a small list (not the value '", args, "')")
all(Wrappers.IsString, args) || GAP_Error("ExecuteProcess: <args> must be a list of strings")

# convert Julia errors to GAP errors
# TODO: we should probably do this in general
try
if use_orig_ExecuteProcess[]
return GAP.Globals._ORIG_ExecuteProcess(dir, prg, in, out, args)
end
return GAP_ExecuteProcess(String(dir), String(prg), in::Int, out::Int, Vector{String}(args))
catch
GAP_Error("a julia exception was raised")
end
return GAP_ExecuteProcess(String(dir), String(prg), in, out, Vector{String}(args))
end

function GAP_ExecuteProcess(dir::String, prg::String, fin::Int, fout::Int, args::Vector{String})
Expand All @@ -30,6 +48,9 @@ function GAP_ExecuteProcess(dir::String, prg::String, fin::Int, fout::Int, args:
fout = RawFD(fout)
end

# TODO: this hangs
# ExecuteProcess("","",0,0,[]);

# TODO: verify `dir` is a valid dir?
cd(dir) do
res = run(pipeline(ignorestatus(`$prg $args`), stdin=fin, stdout=fout))
Expand Down

0 comments on commit 1d9026d

Please sign in to comment.