module Language.R.GC
( automatic
, automaticSome
) where
import Control.Memory.Region
import Control.Monad.R.Class
import Control.Exception
import Foreign.R (SomeSEXP(..))
import qualified Foreign.R as R
import System.Mem.Weak (addFinalizer)
automatic :: MonadR m => R.SEXP s a -> m (R.SEXP G a)
automatic :: SEXP s a -> m (SEXP G a)
automatic s :: SEXP s a
s = IO (SEXP G a) -> m (SEXP G a)
forall (m :: * -> *) a. MonadR m => IO a -> m a
io (IO (SEXP G a) -> m (SEXP G a)) -> IO (SEXP G a) -> m (SEXP G a)
forall a b. (a -> b) -> a -> b
$ IO (SEXP G a) -> IO (SEXP G a)
forall a. IO a -> IO a
mask_ (IO (SEXP G a) -> IO (SEXP G a)) -> IO (SEXP G a) -> IO (SEXP G a)
forall a b. (a -> b) -> a -> b
$ do
SEXP Any a -> IO ()
forall s (a :: SEXPTYPE). SEXP s a -> IO ()
R.preserveObject SEXP Any a
forall r. SEXP r a
s'
SEXP Any a
forall r. SEXP r a
s' SEXP Any a -> IO () -> IO ()
forall key. key -> IO () -> IO ()
`addFinalizer` (SEXP Any a -> IO ()
forall s (a :: SEXPTYPE). SEXP s a -> IO ()
R.releaseObject (SEXP Any a -> SEXP Any a
forall s (a :: SEXPTYPE) r. SEXP s a -> SEXP r a
R.unsafeRelease SEXP Any a
forall r. SEXP r a
s'))
SEXP G a -> IO (SEXP G a)
forall (m :: * -> *) a. Monad m => a -> m a
return SEXP G a
forall r. SEXP r a
s'
where
s' :: SEXP r a
s' = SEXP s a -> SEXP r a
forall s (a :: SEXPTYPE) r. SEXP s a -> SEXP r a
R.unsafeRelease SEXP s a
s
automaticSome :: MonadR m => R.SomeSEXP s -> m (R.SomeSEXP G)
automaticSome :: SomeSEXP s -> m (SomeSEXP G)
automaticSome (SomeSEXP s :: SEXP s a
s) = IO (SomeSEXP G) -> m (SomeSEXP G)
forall (m :: * -> *) a. MonadR m => IO a -> m a
io (IO (SomeSEXP G) -> m (SomeSEXP G))
-> IO (SomeSEXP G) -> m (SomeSEXP G)
forall a b. (a -> b) -> a -> b
$ IO (SomeSEXP G) -> IO (SomeSEXP G)
forall a. IO a -> IO a
mask_ (IO (SomeSEXP G) -> IO (SomeSEXP G))
-> IO (SomeSEXP G) -> IO (SomeSEXP G)
forall a b. (a -> b) -> a -> b
$ do
SEXP Any a -> IO ()
forall s (a :: SEXPTYPE). SEXP s a -> IO ()
R.preserveObject SEXP Any a
forall r. SEXP r a
s'
SEXP Any a
forall r. SEXP r a
s' SEXP Any a -> IO () -> IO ()
forall key. key -> IO () -> IO ()
`addFinalizer` (SEXP Any a -> IO ()
forall s (a :: SEXPTYPE). SEXP s a -> IO ()
R.releaseObject SEXP Any a
forall r. SEXP r a
s')
SomeSEXP G -> IO (SomeSEXP G)
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeSEXP G -> IO (SomeSEXP G)) -> SomeSEXP G -> IO (SomeSEXP G)
forall a b. (a -> b) -> a -> b
$ SEXP G a -> SomeSEXP G
forall s (a :: SEXPTYPE). SEXP s a -> SomeSEXP s
SomeSEXP SEXP G a
forall r. SEXP r a
s'
where
s' :: SEXP r a
s' = SEXP s a -> SEXP r a
forall s (a :: SEXPTYPE) r. SEXP s a -> SEXP r a
R.unsafeRelease SEXP s a
s