Skip to content

Instantly share code, notes, and snippets.

@timholy
Created June 14, 2013 14:46
Show Gist options
  • Save timholy/5782437 to your computer and use it in GitHub Desktop.
Save timholy/5782437 to your computer and use it in GitHub Desktop.
Test spawn and sprofile
function new_jl_spawn(cmd::Ptr{Uint8}, argv::Ptr{Ptr{Uint8}}, loop::Ptr{Void}, pp::Base.Process,
in, out, err)
proc = Base.c_malloc(int(ccall(:jl_sizeof_uv_process_t,Csize_t,())))
@show proc
error = ccall(:jl_spawn, Int32,
(Ptr{Uint8}, Ptr{Ptr{Uint8}}, Ptr{Void}, Ptr{Void}, Any, Int32,
Ptr{Void}, Int32, Ptr{Void}, Int32, Ptr{Void},
Int32),
cmd, argv, loop, proc, pp, Base.uvtype(in),
Base.uvhandle(in), Base.uvtype(out), Base.uvhandle(out), Base.uvtype(err), Base.uvhandle(err),
pp.cmd.detach)
@show error
if error != 0
c_free(proc)
throw(UVError("spawn"))
end
println("About to associate")
associate_julia_struct(proc,pp)
println("Done associate")
return proc
end
function newspawn(pc::Base.ProcessChainOrNot,cmd::Cmd,stdios::Base.StdIOSet,exitcb::Base.Callback,closecb::Base.Callback)
loop = Base.eventloop()
@show loop
close_in,close_out,close_err = false,false,false
pp = Base.Process(cmd,C_NULL,stdios[1],stdios[2],stdios[3]);
@show pp
in,out,err=stdios
if(isa(stdios[1],Base.NamedPipe)&&stdios[1].handle==C_NULL)
in = box(Ptr{Void},Intrinsics.jl_alloca(unbox(Int32,_sizeof_uv_pipe)))
#in = c_malloc(_sizeof_uv_pipe)
@show in
link_pipe(in,false,stdios[1],true)
println("Done 1")
close_in = true
end
if(isa(stdios[2],Base.NamedPipe)&&stdios[2].handle==C_NULL)
out = box(Ptr{Void},Intrinsics.jl_alloca(unbox(Int32,_sizeof_uv_pipe)))
@show out
#out = c_malloc(_sizeof_uv_pipe)
link_pipe(stdios[2],false,out,true)
println("Done 2")
close_out = true
end
if(isa(stdios[3],Base.NamedPipe)&&stdios[3].handle==C_NULL)
err = box(Ptr{Void},Intrinsics.jl_alloca(unbox(Int32,_sizeof_uv_pipe)))
#err = c_malloc(_sizof_uv_pipe)
@show err
link_pipe(stdios[3],false,err,true)
println("Done 3")
close_err = true
end
ptrs = Base._jl_pre_exec(cmd.exec)
@show ptrs
pp.exitcb = exitcb
pp.closecb = closecb
pp.handle = new_jl_spawn(ptrs[1], convert(Ptr{Ptr{Uint8}}, ptrs), loop, pp,
in,out,err)
@show pp
if pc != false
push!(pc.processes, pp)
end
if(close_in)
close_pipe_sync(in)
#c_free(in)
end
if(close_out)
close_pipe_sync(out)
#c_free(out)
end
if(close_err)
close_pipe_sync(err)
#c_free(err)
end
pp
end
newspawn(cmds::Base.AbstractCmd,args...) = newspawn(false,cmds,Base.spawn_opts_swallow(args...)...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment