Skip to content

Commit e27cc5b

Browse files
committed
Move Ref initializiation to seperate file
1 parent 274f09f commit e27cc5b

File tree

5 files changed

+89
-88
lines changed

5 files changed

+89
-88
lines changed

src/MATLAB.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type MEngineError <: Exception
3838
message::String
3939
end
4040

41+
include("init.jl") # initialize Refs
4142
include("mxbase.jl")
4243
include("mxarray.jl")
4344
include("matfile.jl")
@@ -49,9 +50,9 @@ function __init__()
4950

5051
# load libraries
5152

52-
libmx[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmx"), Libdl.RTLD_GLOBAL)
53-
libmat[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmat"), Libdl.RTLD_GLOBAL)
54-
libeng[] = Libdl.dlopen(joinpath(matlab_lib_path, "libeng"), Libdl.RTLD_GLOBAL)
53+
_libmx[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmx"), Libdl.RTLD_GLOBAL)
54+
_libmat[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmat"), Libdl.RTLD_GLOBAL)
55+
_libeng[] = Libdl.dlopen(joinpath(matlab_lib_path, "libeng"), Libdl.RTLD_GLOBAL)
5556

5657

5758
# load functions to access mxArray

src/init.jl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# libraries
2+
3+
const _libeng = Ref{Ptr{Void}}()
4+
const _libmx = Ref{Ptr{Void}}()
5+
const _libmat = Ref{Ptr{Void}}()
6+
7+
# functions to access mxArray
8+
9+
const _mx_free = Ref{Ptr{Void}}()
10+
11+
const _mx_get_classid = Ref{Ptr{Void}}()
12+
const _mx_get_m = Ref{Ptr{Void}}()
13+
const _mx_get_n = Ref{Ptr{Void}}()
14+
const _mx_get_nelems = Ref{Ptr{Void}}()
15+
const _mx_get_ndims = Ref{Ptr{Void}}()
16+
const _mx_get_elemsize = Ref{Ptr{Void}}()
17+
const _mx_get_data = Ref{Ptr{Void}}()
18+
const _mx_get_dims = Ref{Ptr{Void}}()
19+
const _mx_get_nfields = Ref{Ptr{Void}}()
20+
const _mx_get_pr = Ref{Ptr{Void}}()
21+
const _mx_get_pi = Ref{Ptr{Void}}()
22+
const _mx_get_ir = Ref{Ptr{Void}}()
23+
const _mx_get_jc = Ref{Ptr{Void}}()
24+
25+
const _mx_is_double = Ref{Ptr{Void}}()
26+
const _mx_is_single = Ref{Ptr{Void}}()
27+
const _mx_is_int64 = Ref{Ptr{Void}}()
28+
const _mx_is_uint64 = Ref{Ptr{Void}}()
29+
const _mx_is_int32 = Ref{Ptr{Void}}()
30+
const _mx_is_uint32 = Ref{Ptr{Void}}()
31+
const _mx_is_int16 = Ref{Ptr{Void}}()
32+
const _mx_is_uint16 = Ref{Ptr{Void}}()
33+
const _mx_is_int8 = Ref{Ptr{Void}}()
34+
const _mx_is_uint8 = Ref{Ptr{Void}}()
35+
const _mx_is_char = Ref{Ptr{Void}}()
36+
37+
const _mx_is_numeric = Ref{Ptr{Void}}()
38+
const _mx_is_logical = Ref{Ptr{Void}}()
39+
const _mx_is_complex = Ref{Ptr{Void}}()
40+
const _mx_is_sparse = Ref{Ptr{Void}}()
41+
const _mx_is_empty = Ref{Ptr{Void}}()
42+
const _mx_is_struct = Ref{Ptr{Void}}()
43+
const _mx_is_cell = Ref{Ptr{Void}}()
44+
45+
# functions to create & delete MATLAB arrays
46+
47+
const _mx_create_numeric_mat = Ref{Ptr{Void}}()
48+
const _mx_create_numeric_arr = Ref{Ptr{Void}}()
49+
50+
const _mx_create_double_scalar = Ref{Ptr{Void}}()
51+
const _mx_create_logical_scalar = Ref{Ptr{Void}}()
52+
53+
const _mx_create_sparse = Ref{Ptr{Void}}()
54+
const _mx_create_sparse_logical = Ref{Ptr{Void}}()
55+
56+
const _mx_create_string = Ref{Ptr{Void}}()
57+
const _mx_create_char_array = Ref{Ptr{Void}}()
58+
59+
const _mx_create_cell_array = Ref{Ptr{Void}}()
60+
61+
const _mx_create_struct_matrix = Ref{Ptr{Void}}()
62+
const _mx_create_struct_array = Ref{Ptr{Void}}()
63+
64+
const _mx_get_cell = Ref{Ptr{Void}}()
65+
const _mx_set_cell = Ref{Ptr{Void}}()
66+
67+
const _mx_get_field = Ref{Ptr{Void}}()
68+
const _mx_set_field = Ref{Ptr{Void}}()
69+
const _mx_get_field_bynum = Ref{Ptr{Void}}()
70+
const _mx_get_fieldname = Ref{Ptr{Void}}()
71+
72+
const _mx_get_string = Ref{Ptr{Void}}(0)
73+
74+
# load I/O mat functions
75+
76+
const _mat_open = Ref{Ptr{Void}}()
77+
const _mat_close = Ref{Ptr{Void}}()
78+
const _mat_get_variable = Ref{Ptr{Void}}()
79+
const _mat_put_variable = Ref{Ptr{Void}}()
80+
const _mat_get_dir = Ref{Ptr{Void}}()

src/matfile.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# I/O with mat files
2-
3-
const _mat_open = Ref{Ptr{Void}}(0)
4-
const _mat_close = Ref{Ptr{Void}}(0)
5-
const _mat_get_variable = Ref{Ptr{Void}}(0)
6-
const _mat_put_variable = Ref{Ptr{Void}}(0)
7-
const _mat_get_dir = Ref{Ptr{Void}}(0)
8-
91
# mat file open & close
102

113
type MatFile

src/mxarray.jl

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -134,44 +134,6 @@ end
134134
#
135135
###########################################################
136136

137-
# initialize some useful functions
138-
139-
const _mx_free = Ref{Ptr{Void}}(0)
140-
141-
const _mx_get_classid = Ref{Ptr{Void}}(0)
142-
const _mx_get_m = Ref{Ptr{Void}}(0)
143-
const _mx_get_n = Ref{Ptr{Void}}(0)
144-
const _mx_get_nelems = Ref{Ptr{Void}}(0)
145-
const _mx_get_ndims = Ref{Ptr{Void}}(0)
146-
const _mx_get_elemsize = Ref{Ptr{Void}}(0)
147-
const _mx_get_data = Ref{Ptr{Void}}(0)
148-
const _mx_get_dims = Ref{Ptr{Void}}(0)
149-
const _mx_get_nfields = Ref{Ptr{Void}}(0)
150-
const _mx_get_pr = Ref{Ptr{Void}}(0)
151-
const _mx_get_pi = Ref{Ptr{Void}}(0)
152-
const _mx_get_ir = Ref{Ptr{Void}}(0)
153-
const _mx_get_jc = Ref{Ptr{Void}}(0)
154-
155-
const _mx_is_double = Ref{Ptr{Void}}(0)
156-
const _mx_is_single = Ref{Ptr{Void}}(0)
157-
const _mx_is_int64 = Ref{Ptr{Void}}(0)
158-
const _mx_is_uint64 = Ref{Ptr{Void}}(0)
159-
const _mx_is_int32 = Ref{Ptr{Void}}(0)
160-
const _mx_is_uint32 = Ref{Ptr{Void}}(0)
161-
const _mx_is_int16 = Ref{Ptr{Void}}(0)
162-
const _mx_is_uint16 = Ref{Ptr{Void}}(0)
163-
const _mx_is_int8 = Ref{Ptr{Void}}(0)
164-
const _mx_is_uint8 = Ref{Ptr{Void}}(0)
165-
const _mx_is_char = Ref{Ptr{Void}}(0)
166-
167-
const _mx_is_numeric = Ref{Ptr{Void}}(0)
168-
const _mx_is_logical = Ref{Ptr{Void}}(0)
169-
const _mx_is_complex = Ref{Ptr{Void}}(0)
170-
const _mx_is_sparse = Ref{Ptr{Void}}(0)
171-
const _mx_is_empty = Ref{Ptr{Void}}(0)
172-
const _mx_is_struct = Ref{Ptr{Void}}(0)
173-
const _mx_is_cell = Ref{Ptr{Void}}(0)
174-
175137
macro mxget_attr(fun, ret, mx)
176138
:(ccall($(esc(fun)), $(esc(ret)), (Ptr{Void},), $(esc(mx))))
177139
end
@@ -246,40 +208,12 @@ function size(mx::MxArray, d::Integer)
246208
end
247209

248210

249-
250211
###########################################################
251212
#
252213
# functions to create & delete MATLAB arrays
253214
#
254215
###########################################################
255216

256-
# initialize some useful functions
257-
258-
const _mx_create_numeric_mat = Ref{Ptr{Void}}(0)
259-
const _mx_create_numeric_arr = Ref{Ptr{Void}}(0)
260-
261-
const _mx_create_double_scalar = Ref{Ptr{Void}}(0)
262-
const _mx_create_logical_scalar = Ref{Ptr{Void}}(0)
263-
264-
const _mx_create_sparse = Ref{Ptr{Void}}(0)
265-
const _mx_create_sparse_logical = Ref{Ptr{Void}}(0)
266-
267-
const _mx_create_string = Ref{Ptr{Void}}(0)
268-
const _mx_create_char_array = Ref{Ptr{Void}}(0)
269-
270-
const _mx_create_cell_array = Ref{Ptr{Void}}(0)
271-
272-
const _mx_create_struct_matrix = Ref{Ptr{Void}}(0)
273-
const _mx_create_struct_array = Ref{Ptr{Void}}(0)
274-
275-
const _mx_get_cell = Ref{Ptr{Void}}(0)
276-
const _mx_set_cell = Ref{Ptr{Void}}(0)
277-
278-
const _mx_get_field = Ref{Ptr{Void}}(0)
279-
const _mx_set_field = Ref{Ptr{Void}}(0)
280-
const _mx_get_field_bynum = Ref{Ptr{Void}}(0)
281-
const _mx_get_fieldname = Ref{Ptr{Void}}(0)
282-
283217

284218
function _dims_to_mwSize(dims::Tuple{Vararg{Int}})
285219
ndim = length(dims)
@@ -407,7 +341,7 @@ end
407341

408342
function mxarray(s::String)
409343
utf16string = transcode(UInt16, s)
410-
pm = ccall(_mx_create_char_array, Ptr{Void}, (mwSize, Ptr{mwSize},), 2,
344+
pm = ccall(_mx_create_char_array[], Ptr{Void}, (mwSize, Ptr{mwSize},), 2,
411345
_dims_to_mwSize((1, length(utf16string))))
412346
mx = MxArray(pm)
413347
ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), data_ptr(mx), utf16string,
@@ -551,8 +485,6 @@ mxarray(d) = mxstruct(d)
551485
#
552486
###########################################################
553487

554-
const _mx_get_string = Ref{Ptr{Void}}(0)
555-
556488
# use deep-copy from MATLAB variable to Julia array
557489
# in practice, MATLAB variable often has shorter life-cycle
558490

src/mxbase.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ end
6161

6262
default_startcmd, matlab_lib_path = get_paths()
6363

64-
# initialize libraries
64+
# helper library access function
6565

66-
const libeng = Ref{Ptr{Void}}(0)
67-
const libmx = Ref{Ptr{Void}}(0)
68-
const libmat = Ref{Ptr{Void}}(0)
69-
70-
engfunc(fun::Symbol) = Libdl.dlsym(libeng[], fun)
71-
mxfunc(fun::Symbol) = Libdl.dlsym(libmx[], fun)
72-
matfunc(fun::Symbol) = Libdl.dlsym(libmat[], fun)
66+
engfunc(fun::Symbol) = Libdl.dlsym(_libeng[], fun)
67+
mxfunc(fun::Symbol) = Libdl.dlsym(_libmx[], fun)
68+
matfunc(fun::Symbol) = Libdl.dlsym(_libmat[], fun)

0 commit comments

Comments
 (0)