Skip to content

Commit

Permalink
Fixes for compatibility with v0.7.0-alpha.0 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Barton authored and musm committed Jun 13, 2018
1 parent 27936dd commit 5dfde10
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 181 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.6
Compat 0.33.0
Compat 0.62.0
2 changes: 2 additions & 0 deletions src/MATLAB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module MATLAB

using Compat
using Compat.Sys: islinux, iswindows, isapple
using Compat.Libdl
using Compat.SparseArrays

import Base: eltype, close, size, copy, ndims, unsafe_convert

Expand Down
42 changes: 21 additions & 21 deletions src/engine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const default_startcmd = matlab_startcmd() * " -nosplash"
const default_output_buffer_size = 64 * 1024

mutable struct MSession
ptr::Ptr{Void}
ptr::Ptr{Cvoid}
buffer::Vector{UInt8}
bufptr::Ptr{UInt8}

function MSession(bufsize::Integer = default_output_buffer_size)
ep = ccall(eng_open[], Ptr{Void}, (Ptr{UInt8},), default_startcmd)
ep = ccall(eng_open[], Ptr{Cvoid}, (Ptr{UInt8},), default_startcmd)
if ep == C_NULL
Base.warn_once("Confirm MATLAB is installed and discoverable.")
if iswindows()
Expand All @@ -28,26 +28,26 @@ mutable struct MSession
end
if iswindows()
# hide the MATLAB command window on Windows and change to current directory
ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0)
ccall(eng_eval_string[], Cint, (Ptr{Void}, Ptr{UInt8}),
ccall(eng_set_visible[], Cint, (Ptr{Cvoid}, Cint), ep, 0)
ccall(eng_eval_string[], Cint, (Ptr{Cvoid}, Ptr{UInt8}),
ep, "try cd('$(escape_string(pwd()))'); end")
end
buf = Vector{UInt8}(bufsize)
buf = Vector{UInt8}(undef, bufsize)
if bufsize > 0
bufptr = pointer(buf)
ccall(eng_output_buffer[], Cint, (Ptr{Void}, Ptr{UInt8}, Cint),
ccall(eng_output_buffer[], Cint, (Ptr{Cvoid}, Ptr{UInt8}, Cint),
ep, bufptr, bufsize)
else
bufptr = convert(Ptr{UInt8}, C_NULL)
end

self = new(ep, buf, bufptr)
finalizer(self, release)
@compat finalizer(release, self)
return self
end
end

function unsafe_convert(::Type{Ptr{Void}}, m::MSession)
function unsafe_convert(::Type{Ptr{Cvoid}}, m::MSession)
ptr = m.ptr
ptr == C_NULL && throw(UndefRefError())
return ptr
Expand All @@ -56,15 +56,15 @@ end
function release(session::MSession)
ptr = session.ptr
if ptr != C_NULL
ccall(eng_close[], Cint, (Ptr{Void},), ptr)
ccall(eng_close[], Cint, (Ptr{Cvoid},), ptr)
end
session.ptr = C_NULL
return nothing
end

function close(session::MSession)
# close a MATLAB Engine session
ret = ccall(eng_close[], Cint, (Ptr{Void},), session)
ret = ccall(eng_close[], Cint, (Ptr{Cvoid},), session)
ret != 0 && throw(MEngineError("failed to close MATLAB engine session (err = $ret)"))
session.ptr = C_NULL
return nothing
Expand Down Expand Up @@ -103,20 +103,20 @@ end

if iswindows()
function show_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
ret = ccall(eng_set_visible[], Cint, (Ptr{Cvoid}, Cint), m, 1)
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
return nothing
end

function hide_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
ret = ccall(eng_set_visible[], Cint, (Ptr{Cvoid}, Cint), m, 0)
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
return nothing
end

function get_msession_visiblity(m::MSession = get_default_msession())
vis = Ref{Cint}(true)
ccall(eng_get_visible[], Int, (Ptr{Void}, Ptr{Cint}), m, vis)
ccall(eng_get_visible[], Int, (Ptr{Cvoid}, Ptr{Cint}), m, vis)
return vis[] == 1 ? true : false
end
end
Expand All @@ -129,7 +129,7 @@ end

function eval_string(session::MSession, stmt::String)
# evaluate a MATLAB statement in a given MATLAB session
ret = ccall(eng_eval_string[], Cint, (Ptr{Void}, Ptr{UInt8}), session, stmt)
ret = ccall(eng_eval_string[], Cint, (Ptr{Cvoid}, Ptr{UInt8}), session, stmt)
ret != 0 && throw(MEngineError("invalid engine session (err = $ret)"))

bufptr = session.bufptr
Expand All @@ -147,7 +147,7 @@ eval_string(stmt::String) = eval_string(get_default_msession(), stmt)

function put_variable(session::MSession, name::Symbol, v::MxArray)
# put a variable into a MATLAB engine session
ret = ccall(eng_put_variable[], Cint, (Ptr{Void}, Ptr{UInt8}, Ptr{Void}), session, string(name), v)
ret = ccall(eng_put_variable[], Cint, (Ptr{Cvoid}, Ptr{UInt8}, Ptr{Cvoid}), session, string(name), v)
ret != 0 && throw(MEngineError("failed to put variable $(name) into MATLAB session (err = $ret)"))
return nothing
end
Expand All @@ -158,7 +158,7 @@ put_variable(name::Symbol, v) = put_variable(get_default_msession(), name, v)


function get_mvariable(session::MSession, name::Symbol)
pv = ccall(eng_get_variable[], Ptr{Void}, (Ptr{Void}, Ptr{UInt8}), session, string(name))
pv = ccall(eng_get_variable[], Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{UInt8}), session, string(name))
pv == C_NULL && throw(MEngineError("failed to get variable $(name) from MATLAB session"))
return MxArray(pv)
end
Expand All @@ -181,7 +181,7 @@ function _mput_multi(vs::Symbol...)
v = vs[1]
:( MATLAB.put_variable($(Meta.quot(v)), $(v)) )
else
stmts = Vector{Expr}(nv)
stmts = Vector{Expr}(undef, nv)
for i = 1 : nv
v = vs[i]
stmts[i] = :( MATLAB.put_variable($(Meta.quot(v)), $(v)) )
Expand Down Expand Up @@ -214,7 +214,7 @@ function _mget_multi(vs::Union{Symbol, Expr}...)
if nv == 1
make_getvar_statement(vs[1])
else
stmts = Vector{Expr}(nv)
stmts = Vector{Expr}(undef, nv)
for i = 1:nv
stmts[i] = make_getvar_statement(vs[i])
end
Expand All @@ -241,8 +241,8 @@ function mxcall(session::MSession, mfun::Symbol, nout::Integer, in_args...)

# generate temporary variable names

in_arg_names = Vector{String}(nin)
out_arg_names = Vector{String}(nout)
in_arg_names = Vector{String}(undef, nin)
out_arg_names = Vector{String}(undef, nout)

for i = 1:nin
in_arg_names[i] = _gen_marg_name(mfun, "in", i)
Expand Down Expand Up @@ -290,7 +290,7 @@ function mxcall(session::MSession, mfun::Symbol, nout::Integer, in_args...)
ret = if nout == 1
jvalue(get_mvariable(session, Symbol(out_arg_names[1])))
elseif nout >= 2
results = Vector{Any}(nout)
results = Vector{Any}(undef, nout)
for i = 1:nout
results[i] = jvalue(get_mvariable(session, Symbol(out_arg_names[i])))
end
Expand Down
142 changes: 71 additions & 71 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
# libraries

const libeng = Ref{Ptr{Void}}()
const libmx = Ref{Ptr{Void}}()
const libmat = Ref{Ptr{Void}}()
const libeng = Ref{Ptr{Cvoid}}()
const libmx = Ref{Ptr{Cvoid}}()
const libmat = Ref{Ptr{Cvoid}}()

# matlab engine functions

const eng_open = Ref{Ptr{Void}}()
const eng_close = Ref{Ptr{Void}}()
const eng_set_visible = Ref{Ptr{Void}}()
const eng_get_visible = Ref{Ptr{Void}}()
const eng_output_buffer = Ref{Ptr{Void}}()
const eng_eval_string = Ref{Ptr{Void}}()
const eng_put_variable = Ref{Ptr{Void}}()
const eng_get_variable = Ref{Ptr{Void}}()
const eng_open = Ref{Ptr{Cvoid}}()
const eng_close = Ref{Ptr{Cvoid}}()
const eng_set_visible = Ref{Ptr{Cvoid}}()
const eng_get_visible = Ref{Ptr{Cvoid}}()
const eng_output_buffer = Ref{Ptr{Cvoid}}()
const eng_eval_string = Ref{Ptr{Cvoid}}()
const eng_put_variable = Ref{Ptr{Cvoid}}()
const eng_get_variable = Ref{Ptr{Cvoid}}()

# mxarray functions

const mx_destroy_array = Ref{Ptr{Void}}()
const mx_duplicate_array = Ref{Ptr{Void}}()
const mx_destroy_array = Ref{Ptr{Cvoid}}()
const mx_duplicate_array = Ref{Ptr{Cvoid}}()

# functions to access mxarray

const mx_free = Ref{Ptr{Void}}()

const mx_get_classid = Ref{Ptr{Void}}()
const mx_get_m = Ref{Ptr{Void}}()
const mx_get_n = Ref{Ptr{Void}}()
const mx_get_nelems = Ref{Ptr{Void}}()
const mx_get_ndims = Ref{Ptr{Void}}()
const mx_get_elemsize = Ref{Ptr{Void}}()
const mx_get_data = Ref{Ptr{Void}}()
const mx_get_dims = Ref{Ptr{Void}}()
const mx_get_nfields = Ref{Ptr{Void}}()
const mx_get_pr = Ref{Ptr{Void}}()
const mx_get_pi = Ref{Ptr{Void}}()
const mx_get_ir = Ref{Ptr{Void}}()
const mx_get_jc = Ref{Ptr{Void}}()

const mx_is_double = Ref{Ptr{Void}}()
const mx_is_single = Ref{Ptr{Void}}()
const mx_is_int64 = Ref{Ptr{Void}}()
const mx_is_uint64 = Ref{Ptr{Void}}()
const mx_is_int32 = Ref{Ptr{Void}}()
const mx_is_uint32 = Ref{Ptr{Void}}()
const mx_is_int16 = Ref{Ptr{Void}}()
const mx_is_uint16 = Ref{Ptr{Void}}()
const mx_is_int8 = Ref{Ptr{Void}}()
const mx_is_uint8 = Ref{Ptr{Void}}()
const mx_is_char = Ref{Ptr{Void}}()

const mx_is_numeric = Ref{Ptr{Void}}()
const mx_is_logical = Ref{Ptr{Void}}()
const mx_is_complex = Ref{Ptr{Void}}()
const mx_is_sparse = Ref{Ptr{Void}}()
const mx_is_empty = Ref{Ptr{Void}}()
const mx_is_struct = Ref{Ptr{Void}}()
const mx_is_cell = Ref{Ptr{Void}}()
const mx_free = Ref{Ptr{Cvoid}}()

const mx_get_classid = Ref{Ptr{Cvoid}}()
const mx_get_m = Ref{Ptr{Cvoid}}()
const mx_get_n = Ref{Ptr{Cvoid}}()
const mx_get_nelems = Ref{Ptr{Cvoid}}()
const mx_get_ndims = Ref{Ptr{Cvoid}}()
const mx_get_elemsize = Ref{Ptr{Cvoid}}()
const mx_get_data = Ref{Ptr{Cvoid}}()
const mx_get_dims = Ref{Ptr{Cvoid}}()
const mx_get_nfields = Ref{Ptr{Cvoid}}()
const mx_get_pr = Ref{Ptr{Cvoid}}()
const mx_get_pi = Ref{Ptr{Cvoid}}()
const mx_get_ir = Ref{Ptr{Cvoid}}()
const mx_get_jc = Ref{Ptr{Cvoid}}()

const mx_is_double = Ref{Ptr{Cvoid}}()
const mx_is_single = Ref{Ptr{Cvoid}}()
const mx_is_int64 = Ref{Ptr{Cvoid}}()
const mx_is_uint64 = Ref{Ptr{Cvoid}}()
const mx_is_int32 = Ref{Ptr{Cvoid}}()
const mx_is_uint32 = Ref{Ptr{Cvoid}}()
const mx_is_int16 = Ref{Ptr{Cvoid}}()
const mx_is_uint16 = Ref{Ptr{Cvoid}}()
const mx_is_int8 = Ref{Ptr{Cvoid}}()
const mx_is_uint8 = Ref{Ptr{Cvoid}}()
const mx_is_char = Ref{Ptr{Cvoid}}()

const mx_is_numeric = Ref{Ptr{Cvoid}}()
const mx_is_logical = Ref{Ptr{Cvoid}}()
const mx_is_complex = Ref{Ptr{Cvoid}}()
const mx_is_sparse = Ref{Ptr{Cvoid}}()
const mx_is_empty = Ref{Ptr{Cvoid}}()
const mx_is_struct = Ref{Ptr{Cvoid}}()
const mx_is_cell = Ref{Ptr{Cvoid}}()

# functions to create & delete MATLAB arrays

const mx_create_numeric_matrix = Ref{Ptr{Void}}()
const mx_create_numeric_array = Ref{Ptr{Void}}()
const mx_create_numeric_matrix = Ref{Ptr{Cvoid}}()
const mx_create_numeric_array = Ref{Ptr{Cvoid}}()

const mx_create_double_scalar = Ref{Ptr{Void}}()
const mx_create_logical_scalar = Ref{Ptr{Void}}()
const mx_create_double_scalar = Ref{Ptr{Cvoid}}()
const mx_create_logical_scalar = Ref{Ptr{Cvoid}}()

const mx_create_sparse = Ref{Ptr{Void}}()
const mx_create_sparse_logical = Ref{Ptr{Void}}()
const mx_create_sparse = Ref{Ptr{Cvoid}}()
const mx_create_sparse_logical = Ref{Ptr{Cvoid}}()

const mx_create_string = Ref{Ptr{Void}}()
const mx_create_char_array = Ref{Ptr{Void}}()
const mx_create_string = Ref{Ptr{Cvoid}}()
const mx_create_char_array = Ref{Ptr{Cvoid}}()

const mx_create_cell_array = Ref{Ptr{Void}}()
const mx_create_cell_array = Ref{Ptr{Cvoid}}()

const mx_create_struct_matrix = Ref{Ptr{Void}}()
const mx_create_struct_array = Ref{Ptr{Void}}()
const mx_create_struct_matrix = Ref{Ptr{Cvoid}}()
const mx_create_struct_array = Ref{Ptr{Cvoid}}()

const mx_get_cell = Ref{Ptr{Void}}()
const mx_set_cell = Ref{Ptr{Void}}()
const mx_get_cell = Ref{Ptr{Cvoid}}()
const mx_set_cell = Ref{Ptr{Cvoid}}()

const mx_get_field = Ref{Ptr{Void}}()
const mx_set_field = Ref{Ptr{Void}}()
const mx_get_field_bynum = Ref{Ptr{Void}}()
const mx_get_fieldname = Ref{Ptr{Void}}()
const mx_get_field = Ref{Ptr{Cvoid}}()
const mx_set_field = Ref{Ptr{Cvoid}}()
const mx_get_field_bynum = Ref{Ptr{Cvoid}}()
const mx_get_fieldname = Ref{Ptr{Cvoid}}()

const mx_get_string = Ref{Ptr{Void}}()
const mx_get_string = Ref{Ptr{Cvoid}}()

# load I/O mat functions

const mat_open = Ref{Ptr{Void}}()
const mat_close = Ref{Ptr{Void}}()
const mat_get_variable = Ref{Ptr{Void}}()
const mat_put_variable = Ref{Ptr{Void}}()
const mat_get_dir = Ref{Ptr{Void}}()
const mat_open = Ref{Ptr{Cvoid}}()
const mat_close = Ref{Ptr{Cvoid}}()
const mat_get_variable = Ref{Ptr{Cvoid}}()
const mat_put_variable = Ref{Ptr{Cvoid}}()
const mat_get_dir = Ref{Ptr{Cvoid}}()
Loading

0 comments on commit 5dfde10

Please sign in to comment.