-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace GAP's
ExecuteProcess
by Julia code
This is a step towards getting rid of the GAP SIGCHLD handler
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
BindGlobal("_ORIG_ExecuteProcess", ExecuteProcess); | ||
MakeReadWriteGlobal("ExecuteProcess"); | ||
ExecuteProcess := Julia.GAP.GAP_ExecuteProcess; | ||
MakeReadOnlyGlobal("ExecuteProcess"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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) | ||
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}) | ||
# TODO: the GAP kernel function `ExecuteProcess` also handles so-called | ||
# "window mode" but this function currently does not | ||
|
||
if fin < 0 | ||
fin = Base.devnull | ||
else | ||
fin = ccall((:SyBufFileno, libgap), Int, (Culong, ), fin) | ||
if fin == -1 | ||
error("fin invalid") | ||
end | ||
fin = RawFD(fin) | ||
end | ||
|
||
if fout < 0 | ||
fout = Base.devnull | ||
else | ||
fout = ccall((:SyBufFileno, libgap), Int, (Culong, ), fout) | ||
if fout == -1 | ||
error("fout invalid") | ||
end | ||
fout = RawFD(fout) | ||
end | ||
|
||
|
||
# TODO: verify `dir` is a valid dir? | ||
cd(dir) do | ||
res = run(pipeline(`$prg $args`, stdin=fin, stdout=fout)) | ||
return res == 255 ? GAP.Globals.Fail : res | ||
end | ||
end |