From c64e5c9e7eecd45031dadb34312e518a209817ed Mon Sep 17 00:00:00 2001 From: Taylor McDonnell Date: Mon, 15 Jul 2019 12:09:23 -0700 Subject: [PATCH] add dependencies, add empty test file, fix eval scope, turn on i/o redirection --- .gitignore | 1 + Project.toml | 2 ++ src/Mex.jl | 38 +++++++++++++++++++------------------- test/runtests.jl | 0 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 test/runtests.jl diff --git a/.gitignore b/.gitignore index 8ecf801..6d5ded5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pathdef.m *jldict.mat *DS_Store Manifest.toml +deps/build.log diff --git a/Project.toml b/Project.toml index 17f8801..4b657d2 100644 --- a/Project.toml +++ b/Project.toml @@ -4,4 +4,6 @@ authors = ["Taylor McDonnell "] version = "0.1.0" [deps] +Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" MATLAB = "10e44e05-a98a-55b3-a45b-ba969058deb6" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" diff --git a/src/Mex.jl b/src/Mex.jl index 42b51d6..6dbf0aa 100644 --- a/src/Mex.jl +++ b/src/Mex.jl @@ -183,17 +183,17 @@ function jl_mex(plhs::Vector{Ptr{Cvoid}}, prhs::Vector{Ptr{Cvoid}}) # TODO: manually turn stdout and stderr redirection on/off? - # # get stdout and stderr before changing them - # stdout = Base.stdout - # stderr = Base.stderr - # - # # redirect stdout and stderr to matlab terminal - # mexstdout_rd, mexstdout_wr = redirect_stdout() - # mexerrout_rd, mexerrout_wr = redirect_stderr() - # - # # start printing stdout and stderr to matlab console - # t1 = @async readloop(mexstdout_rd, 1) - # t2 = @async readloop(mexstderr_rd, 2) + # get stdout and stderr before changing them + stdout = Base.stdout + stderr = Base.stderr + + # redirect stdout and stderr to matlab terminal + mexstdout_rd, mexstdout_wr = redirect_stdout() + mexerrout_rd, mexerrout_wr = redirect_stderr() + + # start printing stdout and stderr to matlab console + t1 = @async readloop(mexstdout_rd, 1) + t2 = @async readloop(mexstderr_rd, 2) jl_mex_call_depth[] += 1 try @@ -208,13 +208,13 @@ function jl_mex(plhs::Vector{Ptr{Cvoid}}, prhs::Vector{Ptr{Cvoid}}) jl_mex_call_depth[] -= 1 end - # # stop printing stdout and stderr to matlab console - # @async Base.throwto(t1, InterruptException()) - # @async Base.throwto(t2, InterruptException()) - # - # # restore stdout and stderr - # redirect_stdout(stdout) - # redirect_stderr(stderr) + # stop printing stdout and stderr to matlab console + @async Base.throwto(t1, InterruptException()) + @async Base.throwto(t2, InterruptException()) + + # restore stdout and stderr + redirect_stdout(stdout) + redirect_stderr(stderr) # TODO: when called from the MATLAB engine, Julia will overwrite the last line # of terminal output. fix this. @@ -255,7 +255,7 @@ function jl_mex_inner(plhs::Vector{Ptr{Cvoid}}, prhs::Vector{Ptr{Cvoid}}) try # extract function and arguments (function in first slot, arguments in remaining slots) - fun = eval(Meta.parse(MATLAB.jvalue(MATLAB.MxArray(prhs[1], false)))) + fun = Core.eval(Main, Meta.parse(MATLAB.jvalue(MATLAB.MxArray(prhs[1], false)))) args = MATLAB.MxArray.(prhs[2:end], false) # call Julia function diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..e69de29