module CPython.Types.Cell
( Cell
, cellType
, new
, get
, set
) where
import CPython.Internal hiding (new)
newtype Cell = Cell (ForeignPtr Cell)
instance Object Cell where
toObject (Cell x) = SomeObject x
fromForeignPtr = Cell
instance Concrete Cell where
concreteType _ = cellType
cellType :: Type
cellType =
unsafePerformIO $
let {res = cellType'_} in
peekStaticObject res >>= \res' ->
return (res')
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 obj =
withObject cell $ \cellPtr ->
maybeWith withObject obj $ \objPtr ->
pyCellSet cellPtr objPtr
>>= checkStatusCode
foreign import ccall unsafe "CPython/Types/Cell.chs.h hscpython_PyCell_Type"
cellType'_ :: (Ptr ())
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_New"
pyCellNew :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_Get"
pyCellGet :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Cell.chs.h PyCell_Set"
pyCellSet :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))