MissingPy 0.10.3 → 0.10.4
raw patch · 5 files changed
+72/−8 lines, 5 filessetup-changednew-uploader
Files
- MissingPy.cabal +4/−2
- Python/ForeignImports.hsc +21/−0
- Python/Interpreter.hs +24/−1
- Python/Types.hs +11/−0
- Setup.hs +12/−5
MissingPy.cabal view
@@ -1,7 +1,7 @@ Name: MissingPy-Version: 0.10.3+Version: 0.10.4 License: MIT-Maintainer: Simon Hengel <simon.hengel@wiktory.org>+Maintainer: Matt Brown <matt@softmechanics.net> Author: John Goerzen license-file: COPYRIGHT extra-source-files: COPYING, genexceptions.hs, README, INSTALL,@@ -9,6 +9,8 @@ Stability: Alpha Copyright: Copyright (c) 2005-2008 John Goerzen Synopsis: Haskell interface to Python+Homepage: http://github.com/softmechanics/missingpy+Bug-reports: http://github.com/softmechanics/missingpy/issues Description: MissingPy is two things: . A Haskell binding for many C and Python libraries for tasks such as
Python/ForeignImports.hsc view
@@ -60,9 +60,17 @@ foreign import ccall unsafe "glue.h PyRun_String" cpyRun_String :: CString -> CInt -> Ptr CPyObject -> Ptr CPyObject -> IO (Ptr CPyObject) +#ifdef PYTHON_PRE_2_5 foreign import ccall unsafe "glue.h PyImport_ImportModuleEx" cpyImport_ImportModuleEx :: CString -> Ptr CPyObject -> Ptr CPyObject -> Ptr CPyObject -> IO (Ptr CPyObject)+#else+foreign import ccall unsafe "glue.h PyImport_ImportModuleLevel"+ cpyImport_ImportModuleLevel :: CString -> Ptr CPyObject -> Ptr CPyObject -> Ptr CPyObject -> CInt -> IO (Ptr CPyObject) +cpyImport_ImportModuleEx :: CString -> Ptr CPyObject -> Ptr CPyObject -> Ptr CPyObject -> IO (Ptr CPyObject)+cpyImport_ImportModuleEx n g l f = cpyImport_ImportModuleLevel n g l f (fromIntegral (-1))+#endif+ foreign import ccall unsafe "glue.h PyDict_SetItemString" pyDict_SetItemString :: Ptr CPyObject -> CString -> Ptr CPyObject -> IO CInt @@ -192,3 +200,16 @@ foreign import ccall unsafe "glue.h hspy_none" cNone :: IO (Ptr CPyObject)+++foreign import ccall unsafe "glue.h PyEval_InitThreads"+ cpy_InitThreads :: IO ()++#ifndef PYTHON_PRE_2_3+foreign import ccall unsafe "glue.h PyGILState_Ensure"+ cpy_GILEnsure :: IO (Ptr CPyGILState)++foreign import ccall unsafe "glue.h PyGILState_Release"+ cpy_GILRelease :: Ptr CPyGILState -> IO ()+#endif+
Python/Interpreter.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverlappingInstances#-}+{-# LANGUAGE CPP, OverlappingInstances #-} {- arch-tag: Python interpreter module Copyright (C) 2005 John Goerzen <jgoerzen@complete.org>@@ -50,6 +50,13 @@ pyImport_ImportModule, pyImport_AddModule, pyModule_GetDict,+ -- * Threads+ py_initializeThreaded,+#ifndef PYTHON_PRE_2_3 + cpy_GILEnsure,+ cpy_GILRelease,+ withGIL,+#endif ) where @@ -79,12 +86,17 @@ import Python.ForeignImports ( cpy_initialize+ , cpy_InitThreads , cpyRun_String , cpyRun_SimpleString , cpyImport_ImportModuleEx , sf2c , pyImport_GetModuleDict , pyDict_SetItemString+#ifndef PYTHON_PRE_2_3 + , cpy_GILEnsure+ , cpy_GILRelease+#endif ) import Foreign.C (withCString)@@ -96,6 +108,17 @@ py_initialize = do cpy_initialize pyImport "traceback" +py_initializeThreaded :: IO ()+py_initializeThreaded = do cpy_InitThreads+ py_initialize+ +#ifndef PYTHON_PRE_2_3+withGIL :: IO a -> IO a +withGIL act = do st <- cpy_GILEnsure+ r <- act+ cpy_GILRelease st+ return r+#endif pyRun_SimpleString :: String -> IO () pyRun_SimpleString x = withCString x (\cs ->
Python/Types.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {- arch-tag: Python types Copyright (C) 2005 John Goerzen <jgoerzen@complete.org> @@ -40,6 +41,10 @@ CPyObject, PyException(..), StartFrom(..)+#ifndef PYTHON_PRE_2_3 + ,PyGILState(..)+ ,CPyGILState+#endif ) where @@ -56,6 +61,12 @@ -- | The type of Python objects. newtype PyObject = PyObject (ForeignPtr CPyObject) deriving (Eq, Show)++#ifndef PYTHON_PRE_2_3+type CPyGILState = ()+newtype PyGILState = PyGILState (ForeignPtr CPyGILState)+ deriving (Eq, Show)+#endif -- | The type of Python exceptions. data PyException = PyException {excType :: PyObject, -- ^ Exception type
Setup.hs view
@@ -19,18 +19,25 @@ mb_bi <- pyConfigBuildInfo Verbosity.normal lbi writeHookedBuildInfo "MissingPy.buildinfo" (mb_bi,[]) +pyVersionDefines = [((<2.5), "PYTHON_PRE_2_5"),+ ((<2.3), "PYTHON_PRE_2_3")]++definesFor v = map (\(_,d) -> "-D" ++ d) $ filter (\(f,_) -> f v) pyVersionDefines+ -- Populate BuildInfo using python tool. pyConfigBuildInfo verbosity lbi = do- (pyConfigProg, _) <- requireProgram verbosity pyConfigProgram--- (orLaterVersion $ Version [2] []) (withPrograms lbi)- (AnyVersion) (withPrograms lbi)+ (pyConfigProg, _) <- requireProgram verbosity pyConfigProgram (withPrograms lbi) let python = rawSystemProgramStdout verbosity pyConfigProg libDir <- python ["-c", "from distutils.sysconfig import *; print get_python_lib()"] incDir <- python ["-c", "from distutils.sysconfig import *; print get_python_inc()"] confLibDir <- python ["-c", "from distutils.sysconfig import *; print get_config_var('LIBDIR')"]- libName <- python ["-c", "import sys; print \"python%d.%d\" % (sys.version_info[0], sys.version_info[1])"]+ pyVersionStr <- python ["-c", "import sys; sys.stdout.write(\"%d.%d\" % (sys.version_info[0], sys.version_info[1]))"]+ let libName = "python" ++ pyVersionStr+ pyVersion = read pyVersionStr+ return $ Just emptyBuildInfo { extraLibDirs = lines confLibDir ++ lines libDir, includeDirs = lines incDir ++ ["glue"],- extraLibs = lines libName+ extraLibs = lines libName,+ cppOptions = definesFor pyVersion }