Skip to content

Commit df124ac

Browse files
committed
added test suite for runtime and engine
fixed runtime support for matlab 7.6 darcs-hash:20080707210847-56c21-5e5c71053831ccf74c8be7aca894e2f9548a8292
1 parent 536fe0c commit df124ac

File tree

11 files changed

+78
-10
lines changed

11 files changed

+78
-10
lines changed

Foreign/Matlab/Runtime.hsc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import Foreign.Matlab.Util
3030
import Foreign.Matlab.Internal
3131
import Foreign.Matlab.Types
3232

33-
#include <mclmcr.h>
33+
#include "hsc_sym.h"
34+
#include "libhsmatlab.h"
3435

3536
initialized :: MVar Integer
3637
initialized = unsafePerformIO (newMVar 0)
@@ -89,9 +90,9 @@ openMLibrary mlname opt = do
8990
file = (if isPrefixOf "lib" base then id else ("lib" ++)) ((if isSuffixOf dllExtension base || isInfixOf (dllExtension++[extSeparator]) base then id else (<.> dllExtension)) base)
9091
dl <- dlopen (path </> file) [RTLD_NOW]
9192
let ml = MLibrary name dl
92-
inia <- mkInitApp =.< dlsym dl "mclInitializeApplication"
93+
inia <- mkInitApp =.< dlsym dl #SYM mclInitializeApplication
9394
initializeApp inia opt
94-
--initialize
95+
--initialize opt
9596
inif <- mkInitFun =.< dlsym dl ("lib" ++ name ++ "Initialize")
9697
r <- inif
9798
if boolC r
@@ -103,7 +104,7 @@ closeMLibrary :: MLibrary -> IO ()
103104
closeMLibrary (MLibrary name dl) = do
104105
fini <- mkFiniFun =.< dlsym dl ("lib" ++ name ++ "Terminate")
105106
fini
106-
fina <- mkTermApp =.< dlsym dl "mclTerminateApplication"
107+
fina <- mkTermApp =.< dlsym dl #SYM mclTerminateApplication
107108
terminateApp fina
108109
--terminate
109110
dlclose dl

Setup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ programs = [
1313
simpleProgram "matlab",
1414
Program "mcr" (\_ -> return Nothing) (\_ _ -> return Nothing)
1515
]
16-
runtime desc = maybe False (elem "Matlab.Runtime" . exposedModules) $ library desc
16+
runtime desc = maybe False (elem "Foreign.Matlab.Runtime" . exposedModules) $ library desc
1717
postconf args flags desc build = do
1818
confExists <- doesFileExist "configure"
1919
unless confExists $ rawSystemPathExit verb "autoconf" []

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ env -i $MATLAB_BIN -e > $matlab_env 2>&AS_MESSAGE_LOG_FD
4141
matlab_envres=$?
4242
cat $matlab_env >&AS_MESSAGE_LOG_FD
4343
44+
AC_DEFUN([MATLAB_GETENV], [`. $matlab_env && echo "${$1}"`])
45+
4446
unset MATLAB
4547
AS_IF([test $matlab_envres -gt 0],
4648
[AC_MSG_RESULT([failed])
4749
AC_MSG_FAILURE([$MATLAB_BIN -e failed])],
4850
[! (. $matlab_env > /dev/null 2>&1 && test -n "$MATLAB")],
4951
[AC_MSG_RESULT([invalid])
5052
AC_MSG_FAILURE([$MATLAB_BIN -e output invalid])],
51-
[AC_MSG_RESULT([ok])])
52-
53-
AC_DEFUN([MATLAB_GETENV], [`. $matlab_env && echo "${$1}"`])
53+
[AC_MSG_RESULT([MATLAB_GETENV([MATLAB])])])
5454
5555
MATLAB_DIR=MATLAB_GETENV([MATLAB])
5656
MATLAB_ARCH=MATLAB_GETENV([ARCH])

matlab.buildinfo.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
include-dirs: @MATLAB_DIR@/extern/include
1+
include-dirs: @srcdir@/src @MATLAB_DIR@/extern/include
22
extra-lib-dirs: @MATLAB_LIB_PATH@
33
ld-options: "-Wl,-rpath,@MATLAB_LIB_DIR@" "-Wl,--disable-new-dtags"

src/Makefile.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ MCCFLAGS=@MCCFLAGS@
33

44
libhsmatlab.so: hsmatlab.m hsmatlab.c
55
$(MCC) $(MCCFLAGS) -W lib:$(basename $@) -c hsmatlab.m
6+
[ -f $@ ] && mv $@ $@.post
67
cat hsmatlab.c >> $(basename $@).c
78
$(MCC) $(MCCFLAGS) -W none -T link:lib $(basename $@).c
9+
[ -f $@.post ] && cat $(basename $@).ctf >> $@
810

911
clean:
10-
rm -rf libhsmatlab* mccExcludedFiles.log readme.txt
12+
rm -rf libhsmatlab_mcr
13+
rm -f libhsmatlab* mccExcludedFiles.log readme.txt

src/hsc_sym.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define hsc_SYM2(X) hsc_const_str(#X)
2+
#define hsc_SYM(X) hsc_SYM2(X)

test/Makefile.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MCC=@MATLAB_MCC@
2+
MCCFLAGS=@MCCFLAGS@
3+
4+
TESTS=engine runtime generic
5+
default: $(TESTS)
6+
@echo "All tests should have produced:"
7+
@echo " ready"
8+
@echo " MXClassDouble"
9+
@echo " -1.0"
10+
@for t in $^ ; do echo Running $$t... ; ./$$t ; done
11+
12+
%: %.hs
13+
ghc -I.. --make $@
14+
15+
lib%.so: %.m
16+
$(MCC) $(MCCFLAGS) -W lib:$(basename $@) -T link:lib $^
17+
18+
runtime: libmtest.so
19+
20+
clean:
21+
rm -rf libmtest_mcr
22+
rm -f *.o *.hi $(TESTS) libmtest* mccExcludedFiles.log readme.txt

test/engine.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foreign.Matlab
2+
import Foreign.Matlab.Engine
3+
4+
main = do
5+
eng <- newEngine Nothing
6+
putStrLn "ready"
7+
x <- createMXScalar (pi :: MDouble)
8+
[y] <- engineEvalFun eng "cos" [EvalArray x] 1
9+
mxArrayClass y >>= print
10+
Just y <- castMXArray y
11+
y <- mxScalarGet y
12+
print (y :: MDouble)

test/generic.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foreign.Matlab
2+
import Foreign.Matlab.Runtime.Generic
3+
4+
main = do
5+
ml <- openMLGeneric ["-nojvm", "-nojit"]
6+
putStrLn "ready"
7+
x <- createMXScalar (pi :: MDouble)
8+
[y] <- mlGenericFun ml "cos" [anyMXArray x] 1
9+
mxArrayClass y >>= print
10+
Just y <- castMXArray y
11+
y <- mxScalarGet y
12+
print (y :: MDouble)
13+
closeMLGeneric ml

test/mtest.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function y = mtest(x)
2+
y = cos(x);

0 commit comments

Comments
 (0)