packages feed

mathlink 2.0.0.5 → 2.0.0.7

raw patch · 6 files changed

+194/−34 lines, 6 filessetup-changed

Files

Foreign/MathLink/Internal.chs view
@@ -916,15 +916,15 @@ #else {# fun MLGetInteger32Array as getIntArray'        { withLink- `Link'-       , alloca- `Ptr CLong' peek*        , alloca- `Ptr CInt' peek*+       , alloca- `Ptr CInt' peek*        , alloca- `Ptr CString' peek*        , alloca- `Int' peekIntConv*        } -> `()' throwUnless-  #} {# fun MLReleaseInteger32Array as releaseIntArray'        { withLink- `Link'-       , id `Ptr CLong'+       , id `Ptr CInt'        , id `Ptr CInt'        , id `Ptr CString'        , cIntConv `Int'
INSTALL view
@@ -1,11 +1,60 @@-Installation Notes:+Installation Notes+------------------ -First make sure that the mathlink.h header file and the ML32i3 (for 32-bit +1. Make sure that the mathlink.h header file and the ML32i3 (for 32-bit  systems) or ML64i3 (for 64-bit systems) library are in places that can be  found by GHC. -Otherwise, the usual rules apply:+These should reside in a folder called: +SystemFiles/Links/MathLink/DeveloperKit/<your-platform>/CompilerAdditions++in your Mathematica installation.++For my 64-bit Linux platform, I do the following:++> cd /usr/local/include+> sudo ln -s /path/to/CompilerAdditions/mathlink.h mathlink.h+> cd /usr/local/lib+> sudo ln -s /path/to/CompilerAdditions/libML64i3.a libML64i3.a+> sudo ln -s /path/to/CompilerAdditions/libML64i3.so libML64i3.so+> sudo ldconfig++The analogous process, I would think, should work on all Unix-alikes.++Any Mac or Windows (or Sparc, or...) users out there, send me a blurb+about what you did to get things right, and I'll include it here.+++2. Follow the usual rules for installation:+ > runhaskell Setup.lhs configure > runhaskell Setup.lhs build > [sudo] runhaskell Setup.lhs install+++Troubleshooting+---------------++If you get compile or link errors (that can't be explained by not +having yet gotten step 1 above correct), take a look in Setup.lhs and+doublecheck that the definition for 'bits' and 'extraLibs' is appropriate+for your platform. As of the 2.0.0.7 installation, at least, these have+only been verified on Linux platforms, so if you are on another platform,+definitely take a look here.++If you did need to make some tweaks for your platform, let me know what it+took, so that I can incorporate it into the setup.++If I get a decent user base, I might even go through the effort of +having the installation guess where the CompilerAdditions directory is to+eliminate having to do the first part manually. So ping me if you use this +library at all. That way I can gauge if/when it might be worth the effort +to do this.+++Thank You...+------------++...to Eugene Kirpichov for helping me track down some bugs and +insufficiencies in the distributions of the earliest 2.0 releases.
Setup.lhs view
@@ -5,48 +5,56 @@ import Distribution.System import System.IO import System.Directory+import Data.List -buildInfoFileName = "mathlink.buildinfo"-archHeaderFileName = "cbits/arch.h"+-- Make sure that 'bits' and 'extraLibs' below is correctly defined+-- for your platform. See Distribution.System for the definitions of+-- the relevant architecture/OS enumerations. -fileNames = [ buildInfoFileName-            , archHeaderFileName-            ]+-- string representing the word size of your platform+bits = case buildPlatform of+         Platform X86_64 _ -> "64"+         Platform IA64   _ -> "64"+         Platform PPC64  _ -> "64"+         _                 -> "32" -bits = if is64bit then 64 else 32-  where Platform arch _ = buildPlatform-        is64bit = case arch of-                    X86_64 -> True-                    IA64   -> True-                    PPC64  -> True-                    _      -> False+-- list of extra libraries against which you need to link+extraLibs = intercalate ", " libs+  where libs = case buildPlatform of+                 Platform _    Linux   -> ["rt"] +                 -- If this setting for windows isn't right, let me know.+                 -- I haven't tried it, bu just guessed what it should be +                 -- from the definition of the mcc script.+                 Platform I386 Windows -> ["Gdi32"]++                 -- For now, nothing extra is specified for other platforms.+                 -- If you are on another platform and you needed to +                 -- link against extra libraries, let me know what they+                 -- are.+                 _                     -> []+++buildInfoFileName = "mathlink.buildinfo"+archHeaderFileName = "cbits/arch.h"+ buildInfoFile = "\-\Extra-Libraries: ML" ++ show bits ++ "i3, rt\n"+\Extra-Libraries: ML" ++ bits ++ "i3, " ++ extraLibs ++ "\n"  archHeaderFile = "\ \#ifndef __ARCH_H__\n\ \#define __ARCH_H__\n\ \\n\-\#define IS_" ++ show bits ++ "_BIT\n\+\#define IS_" ++ bits ++ "_BIT\n\ \\n\ \#endif\n" -removeIfExists fn = do-  bl <- doesFileExist fn -  if bl then removeFile fn else return ()- makeFiles _ _ _ _ = do   writeFile buildInfoFileName buildInfoFile   writeFile archHeaderFileName archHeaderFile -removeFiles _ _ _ _ = mapM_ removeIfExists fileNames--mathLinkHooks = autoconfUserHooks {-                  postConf = makeFiles-                , postClean = removeFiles-                }--main = defaultMainWithHooks mathLinkHooks+main = defaultMainWithHooks autoconfUserHooks {+         postConf = makeFiles+       }  \end{code}
+ example/README view
@@ -0,0 +1,76 @@+A script for a Mathematica session using the example package:+++1. Install the mathlink library.+++2. cd into the example/ directory and build the executable:++   > ghc --make Test.hs+++3. Start Mathematica and install the package, e.g.:++   lnk = Install["~/hs/mathlink/example/Test"]++   Out[_]:= LinkObject["/home/twadleigh/hs/mathlink/example/Test", 5, 5]+++4. Show the public symbols in the newly added package:++   ?Test`*++   You should see something like:++   Test`*+   Ackermann        AddFour+++5. Call the Ackermann function:++   Ackermann[4,1]++   Out[_]:= 65553+++6. The marshaling can handle arbitrarily sized integers:++   Ackermann[4,2]++   Out[_]:= 2003529930406846464979072351...++   Marshaling of unbounded integers is accomplished via strings.+++7. The function calls should respond immediately to an abort request.+   Start a computation running by entering:++   Ackermann[4,3]++   then press Alt+. to attempt to abort. You should immediately get:++   Out[_]:= $Aborted.+++8. Exceptions uncaught in the execution of the Haskell function are+   caught by library code, and a message is sent to Mathematica. +   E.g., run:++   Ackermann[4,3]++   again, but this time wait a little bit. You should eventually see:++   MathLink::exn : Exception caught: stack overflow+   Out[_]:= $Failed++   Of course, the stack overflow problem can generally be mitigaged+   by passing appropriate flags to the GHC runtime. One way to make +   doing this work nicely with Mathematica is to write a script that +   passes the desired RTS flags along with those given on the command +   line. See the test.sh script in this directory for an example.+  +9. Uninstall the package:++   Uninstall[lnk]++   Out[_]:= "/home/twadleigh/hs/mathlink/example/Main" 
+ example/test.sh view
@@ -0,0 +1,20 @@+#! /usr/bin/env sh+# +#  To use this example script (on Unix-alikes):+#+#+# 1. Make sure this script is executable:+#+#    > chmod +x test.hs+# +#+# 2. Build the executable:+#+#    > ghc --make Test.hs+#+#+# 3. Install the package via this script, e.g.:+#+#    Install["~/hs/mathlink/example/test.sh"]+#+./Test -$@ +RTS -K512M -RTS 2> test.err
mathlink.cabal view
@@ -1,5 +1,5 @@ Name:                 mathlink-Version:              2.0.0.5+Version:              2.0.0.7 Cabal-Version:        >= 1.6 Build-Type:           Custom License:              BSD3@@ -14,8 +14,15 @@ Synopsis:             Write Mathematica packages in Haskell Tested-With:          GHC >= 6.10.1 Category:             Foreign-Extra-Source-Files:   INSTALL, cbits/ml.h example/Test.hs+Extra-Source-Files:   INSTALL+                      cbits/ml.h +                      example/README+                      example/Test.hs+                      example/test.sh+Extra-Tmp-Files:      cbits/arch.h+                      mathlink.buildinfo + Description: { Makes it easy to write /Mathematica/ packages in Haskell. Just write some functions and provide a package specification in a simple DSL that @@ -83,7 +90,7 @@   Includes:           ml.h mathlink.h   C-Sources:          cbits/ml.c -  Build-Tools:        c2hs+  Build-Tools:        c2hs >= 0.16   Ghc-Options:        -fexcess-precision -funbox-strict-fields -Wall  Source-Repository     head