packages feed

hruby 0.4.0.0 → 0.5.0.0

raw patch · 5 files changed

+4/−186 lines, 5 filessetup-changed

Files

Foreign/Ruby/Bindings.hsc view
@@ -79,15 +79,9 @@  foreign import ccall "ruby_finalize"             ruby_finalize               :: IO () foreign import ccall "ruby_initialization"       ruby_initialization         :: IO ()-#ifdef RUBY21 foreign import ccall "rb_str_new_cstr"           c_rb_str_new2               :: CString -> IO RValue foreign import ccall "rb_ary_new_capa"           rb_ary_new2                 :: CLong -> IO RValue foreign import ccall "rb_ary_new_from_values"    rb_ary_new4                 :: CLong -> Ptr RValue -> IO RValue-#else-foreign import ccall "rb_str_new2"               c_rb_str_new2               :: CString -> IO RValue-foreign import ccall "rb_ary_new2"               rb_ary_new2                 :: CLong -> IO RValue-foreign import ccall "rb_ary_new4"               rb_ary_new4                 :: CLong -> Ptr RValue -> IO RValue-#endif foreign import ccall   safe "rb_load_protect"           c_rb_load_protect           :: RValue -> Int -> Ptr Int -> IO () foreign import ccall   safe "rb_funcall"                c_rb_funcall_0              :: RValue -> RID -> Int -> IO RValue foreign import ccall   safe "rb_funcall"                c_rb_funcall_1              :: RValue -> RID -> Int -> RValue -> IO RValue@@ -95,9 +89,7 @@ foreign import ccall   safe "rb_funcall"                c_rb_funcall_3              :: RValue -> RID -> Int -> RValue -> RValue -> RValue -> IO RValue foreign import ccall   safe "rb_funcall"                c_rb_funcall_4              :: RValue -> RID -> Int -> RValue -> RValue -> RValue -> RValue -> IO RValue foreign import ccall   safe "rb_funcall"                c_rb_funcall_5              :: RValue -> RID -> Int -> RValue -> RValue -> RValue -> RValue -> RValue -> IO RValue-#ifdef RUBY2 foreign import ccall   safe "rb_funcall_with_block"     c_rb_funcall_with_block     :: RValue -> RID -> Int -> Ptr RValue -> RValue -> IO RValue-#endif foreign import ccall unsafe "rb_gv_get"                 c_rb_gv_get                 :: CString -> IO RValue foreign import ccall unsafe "rb_intern"                 c_rb_intern                 :: CString -> IO RID foreign import ccall unsafe "rb_id2name"                rb_id2name                  :: RID -> IO CString@@ -135,17 +127,10 @@ foreign import ccall unsafe "sym2id"             sym2id                      :: RValue -> RID  rbFalse,rbTrue,rbNil,rbUndef :: RValue-#ifdef RUBY2 rbFalse = intPtrToPtr 0x00 rbTrue  = intPtrToPtr 0x14 rbNil   = intPtrToPtr 0x08 rbUndef = intPtrToPtr 0x34-#else-rbFalse = intPtrToPtr 0-rbTrue  = intPtrToPtr 2-rbNil   = intPtrToPtr 4-rbUndef = intPtrToPtr 6-#endif  rtype :: RValue -> IO RType rtype v = rubyType v >>= \x -> case x of
Setup.hs view
@@ -1,133 +1,2 @@-{-# LANGUAGE ScopedTypeVariables #-} import Distribution.Simple-import Distribution.Verbosity-import Distribution.Simple.Configure-import Distribution.Simple.LocalBuildInfo-import Distribution.Simple.Utils-import Distribution.PackageDescription--import System.Environment-import System.Process-import System.Exit--import Control.Applicative-import Control.Exception--import Data.List (partition,stripPrefix,foldl')-import Data.Maybe (mapMaybe)---- --rubyversion=20 --rubylib=ruby-2.0 --rubyinc=/usr/include/ruby-2.0.0 --rubyinc=/usr/include/x86_64-linux-gnu/ruby-2.0.0--- {rbVersion = (2,0,0), rbInstallName = "ruby2.0", rbIncludes = ["/usr/include/ruby-2.0.0","/usr/include/ruby-2.0.0/x86_64-linux-gnu"], rbLib = "/usr/lib", rbLibName = "ruby-2.0"}--type RubyVersion = (Int, Int, Int)-data RubyInfo = RubyInfo { rbVersion     :: RubyVersion-                         , rbInstallName :: String-                         , rbIncludes    :: [String]-                         , rbLib         :: String-                         , rbLibName     :: String-                         } deriving (Eq, Show, Read)--evalRuby :: String            -- expression to evaluate-         -> IO (Maybe String) -- stdout, if successfull-evalRuby exp = do-    let getruby [] = return (ExitFailure 3, "beuh", undefined)-        getruby (x:xs) = readProcessWithExitCode x ["-e", exp] "" `catch` \ (_ :: IOException) -> getruby xs-    (exitCode, out, err) <- getruby [ "ruby.ruby2.4", "ruby2.4", "ruby2.1", "ruby2.0", "ruby2", "ruby1.8", "ruby"]-    return $ if exitCode == ExitSuccess-               then Just out-               else Nothing--getRubyInfo :: IO (Maybe RubyInfo)-getRubyInfo = do-    version     <- fmap (fmap read) (evalRuby "print '('+RUBY_VERSION.gsub('.', ',')+')'")-    case version of-        Nothing -> return Nothing-        Just (1,9,_) -> error $ unlines [ "Ruby 1.9 cannot be integrated with the GHC runtime. Tough luck :("-                                        , "On Ubuntu 14.04, you can try this:"-                                        , "  apt-get install ruby2.0 libruby2.0 ruby2.0-dev"-                                        , "  cabal install hruby -p --configure-option=\"--rubyversion=20 --rubylib=ruby-2.0 --rubyinc=/usr/include/ruby-2.0.0 --rubyinc=/usr/include/x86_64-linux-gnu/ruby-2.0.0\""-                                        ]-        Just v@(1,8,_) -> return $ Just $ RubyInfo v-                                                   "/usr/lib/ruby/1.8"-                                                   ["/usr/lib/ruby/1.8/x86_64-linux","/usr/lib/ruby/1.8/x86_64-linux","/usr/lib64/ruby/1.8/x86_64-linux"]-                                                   "/usr/lib"-                                                   "ruby1.8"-        Just v -> do-            installName <- evalRuby "print RbConfig::CONFIG['RUBY_INSTALL_NAME']"-            headerDir   <- evalRuby "print RbConfig::CONFIG['rubyhdrdir']"-            archDir     <- evalRuby "print RbConfig::CONFIG['rubyarchhdrdir']"-            libDir      <- evalRuby "print RbConfig::CONFIG['libdir']"-            td          <- evalRuby "print RbConfig::CONFIG['topdir']"-            libName     <- evalRuby "print RbConfig::CONFIG['LIBRUBY_SO'].sub(/^lib/,'').sub(/\\.(so|dll|dylib)([.0-9]+)?$/,'')"-            return $ RubyInfo <$> pure v-                              <*> installName-                              <*> sequence [headerDir, archDir, td]-                              <*> libDir-                              <*> libName--defsFor :: RubyInfo -> [String]-defsFor info =-    case rbVersion info of-        (2, 0, _) -> ["-DRUBY2"]-        (2, _, _) -> ["-DRUBY2", "-DRUBY21"]-        (a, b, _) -> ["-DRUBY" ++ show a ++ show b]--cantFindRuby :: String-cantFindRuby = unlines [ "Could not find the ruby library. Ensure that it is present on your system (on Debian/Ubuntu, make sure you installed the ruby1.8-dev package)."-                       , "If you know it to be installed, please install hruby in the following way (example for nix):"-                       , ""-                       , "$ cabal install hruby -p --configure-option=\"--rubyversion=19 --rubylib=ruby --rubyinc=/nix/store/v0w14mdpcy9c0qwvhqa7154qsv53ifqn-ruby-1.9.3-p484/include/ruby-1.9.1 --rubyinc=/nix/store/v0w14mdpcy9c0qwvhqa7154qsv53ifqn-ruby-1.9.3-p484/include/ruby-1.9.1/x86_64-linux' --extra-lib-dirs=$HOME/.nix-profile/lib/\""-                       , ""-                       , " --rubylib : Should be the name of the library passed to the linker (ruby for libruby.so)."-                       , " --rubyinc : There can be several instances of this flag. Should be the path of the various ruby header files."-                       , " --rubyversion : Mandatory for ruby 2.0 and 2.1, should have the values 20 or 21."-                       ]--getBuildInfo :: LocalBuildInfo -> BuildInfo-getBuildInfo l = case library (localPkgDescr l) of-                     Just x -> libBuildInfo x-                     Nothing -> error "Could not find the buildinfo!"--setBuildInfo :: LocalBuildInfo -> BuildInfo -> LocalBuildInfo-setBuildInfo l b = l { localPkgDescr = lpd' }-    where-        lpd = localPkgDescr l-        Just li = library lpd-        li' = li { libBuildInfo = b }-        lpd' = lpd { library = Just li' }--myConfHook :: LocalBuildInfo -> IO LocalBuildInfo-myConfHook h = do-    mrubyInfo <- getRubyInfo-    case mrubyInfo of-        Just info ->-            let buildinfos = getBuildInfo h-                bi = buildinfos { extraLibs    = [rbLibName info]-                                , extraLibDirs = rbLib info : extraLibDirs buildinfos-                                , includeDirs  = includeDirs buildinfos ++ rbIncludes info-                                , ccOptions    = ccOptions buildinfos ++ defsFor info-                                }-                in putStrLn ("Detected ruby: " ++ show info ++ " cc:" ++ show (ccOptions bi)) >> return (setBuildInfo h bi)-        _ -> warn normal cantFindRuby >> return h--parseFlags :: [String] -> LocalBuildInfo -> IO LocalBuildInfo-parseFlags flags h = return $ setBuildInfo h $ foldl' parseFlags' bbi flags-    where-        bbi = getBuildInfo h-        addOptions (Just "20") bi = bi { ccOptions   = "-DRUBY2" : ccOptions bi }-        addOptions (Just "21") bi = bi { ccOptions   = "-DRUBY2" : "-DRUBY21" : ccOptions bi }-        addOptions (Just x) bi = bi { ccOptions = ("-DRUBY" ++ take 2 x) : ccOptions bi }-        addOptions Nothing bi = bi-        parseFlags' bi fl = addOptions (stripPrefix "--rubyversion=" fl) $ case (stripPrefix "--rubylib=" fl, stripPrefix "--rubyinc=" fl) of-                                        (Just l, _)    -> bi { extraLibs   = l : filter (/= "ruby") (extraLibs bi) }-                                        (_, Just l)    -> bi { includeDirs = l : includeDirs bi }-                                        _              -> bi--main :: IO ()-main = do-    args <- getArgs-    let flags = mapMaybe (stripPrefix "--configure-option=") args-    let hook = if null flags-                   then myConfHook-                   else parseFlags (concatMap words flags)-    defaultMainWithHooks $ simpleUserHooks { confHook = \a b -> configure a b >>= hook }+main = defaultMain
cbits/shim.c view
@@ -1,13 +1,10 @@ #include "shim.h"-#ifdef RUBY2 #include <ruby/encoding.h>-#endif  void ruby_initialization(void) { 	RUBY_INIT_STACK; 	ruby_init(); 	ruby_init_loadpath();-#ifdef RUBY2 	VALUE encoding = rb_enc_from_encoding(rb_filesystem_encoding()); 	rb_enc_set_default_internal(encoding); 	rb_enc_set_default_external(encoding);@@ -15,7 +12,6 @@ 	rb_encdb_declare("ASCII-8BIT"); 	rb_encdb_declare("US-ASCII"); 	rb_encdb_declare("UTF-8");-#endif }  VALUE id2sym(ID i) {@@ -43,11 +39,7 @@ }  VALUE newFloat(double d) {-#ifdef RUBY2 	rb_float_new_in_heap(d);-#else-	rb_float_new(d);-#endif }  int rubyType(VALUE obj) {
cbits/shim.h view
@@ -1,7 +1,5 @@ #include <ruby.h>-#ifdef RUBY21 #include <ruby/intern.h>-#endif  void ruby_initialization(void); @@ -22,28 +20,3 @@ double num2dbl(VALUE v); VALUE id2sym(ID i); ID sym2id(VALUE v);--#ifdef RUBY18-#define RUBY_T_NONE   T_NONE-#define RUBY_T_OBJECT T_OBJECT-#define RUBY_T_CLASS  T_CLASS-#define RUBY_T_MODULE T_MODULE-#define RUBY_T_FLOAT  T_FLOAT-#define RUBY_T_STRING T_STRING-#define RUBY_T_REGEXP T_REGEXP-#define RUBY_T_ARRAY  T_ARRAY-#define RUBY_T_HASH   T_HASH-#define RUBY_T_STRUCT T_STRUCT-#define RUBY_T_BIGNUM T_BIGNUM-#define RUBY_T_FILE   T_FILE-#define RUBY_T_DATA   T_DATA-#define RUBY_T_MATCH  T_MATCH-#define RUBY_T_NIL    T_NIL-#define RUBY_T_TRUE   T_TRUE-#define RUBY_T_FALSE  T_FALSE-#define RUBY_T_SYMBOL T_SYMBOL-#define RUBY_T_FIXNUM T_FIXNUM-#define RUBY_T_UNDEF  T_UNDEF-#define RUBY_T_NODE   T_NODE-#define RUBY_T_ICLASS T_ICLASS-#endif
hruby.cabal view
@@ -1,8 +1,8 @@ cabal-version:       >= 1.10 name:                hruby-version:             0.4.0.0+version:             0.5.0.0 synopsis:            Embed a Ruby intepreter in your Haskell program !-description:         This doesn't work with Ruby 1.9. Everything you need should be in Foreign.Ruby.Safe.+description:         This works with Ruby 2.2+. Everything you need should be in Foreign.Ruby.Safe. license:             BSD3 license-file:        LICENSE author:              Simon Marechal@@ -36,8 +36,7 @@   c-sources:            cbits/shim.c   install-includes:     cbits/shim.h   include-dirs:         cbits-  Includes:             ruby.h-  extra-libraries:      ruby+  pkgconfig-depends:    ruby   default-language:     Haskell2010  Test-Suite test-roundtrip