{-# LINE 1 "lib/CPython/Types/Cell.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Types.Cell
( Cell
, cellType
, new
, get
, set
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp
import CPython.Internal hiding (new)
newtype Cell = Cell (ForeignPtr Cell)
instance Object Cell where
toObject :: Cell -> SomeObject
toObject (Cell x :: ForeignPtr Cell
x) = ForeignPtr Cell -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Cell
x
fromForeignPtr :: ForeignPtr Cell -> Cell
fromForeignPtr = ForeignPtr Cell -> Cell
Cell
instance Concrete Cell where
concreteType :: Cell -> Type
concreteType _ = Type
cellType
cellType :: (Type)
cellType =
C2HSImp.unsafePerformIO $
cellType'_ >>= \res ->
peekStaticObject res >>= \res' ->
return (res')
{-# LINE 40 "lib/CPython/Types/Cell.chs" #-}
new :: Object obj => Maybe obj -> IO Cell
new obj =
maybeWith withObject obj $ \objPtr ->
pyCellNew objPtr
>>= stealObject
get :: Cell -> IO (Maybe SomeObject)
get cell =
withObject cell $ \cellPtr ->
pyCellGet cellPtr
>>= maybePeek stealObject
set :: Object obj => Cell -> Maybe obj -> IO ()
set :: Cell -> Maybe obj -> IO ()
set cell :: Cell
cell obj :: Maybe obj
obj =
Cell -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Cell
cell ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \cellPtr :: Ptr ()
cellPtr ->
(obj -> (Ptr () -> IO ()) -> IO ())
-> Maybe obj -> (Ptr () -> IO ()) -> IO ()
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith obj -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Maybe obj
obj ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \objPtr :: Ptr ()
objPtr ->
Ptr () -> Ptr () -> IO CInt
pyCellSet Ptr ()
cellPtr Ptr ()
objPtr
IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CInt -> IO ()
checkStatusCode
foreign import ccall unsafe "CPython/Types/Cell.chs.h hscpython_PyCell_Type"
cellType'_ :: (IO (C2HSImp.Ptr ()))
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_New"
pyCellNew :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_Get"
pyCellGet :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_Set"
pyCellSet :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))