{-# LINE 1 "lib/CPython/Internal.chs" #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Internal
(
module Foreign
, module Foreign.C
, cToBool
, cFromBool
, peekText
, peekTextW
, peekMaybeTextW
, withText
, withTextW
, withMaybeTextW
, mapWith
, unsafePerformIO
, SomeObject (..)
, Type (..)
, Dictionary (..)
, List (..)
, Tuple (..)
, Object (..)
, Concrete (..)
, withObject
, peekObject
, peekStaticObject
, stealObject
, incref
, decref
, callObjectRaw
, unsafeCast
, Exception (..)
, exceptionIf
, checkStatusCode
, checkBoolReturn
, checkIntReturn
, Mapping (..)
, SomeMapping (..)
, unsafeCastToMapping
, Sequence (..)
, SomeSequence (..)
, unsafeCastToSequence
, Iterator (..)
, SomeIterator (..)
, unsafeCastToIterator
) where
import qualified Foreign.Ptr as C2HSImp
import qualified Control.Exception as E
import qualified Data.Text as T
import Data.Typeable (Typeable)
import Foreign hiding (newForeignPtr, newForeignPtr_)
import Foreign.C
import Foreign.Concurrent(newForeignPtr)
import System.IO.Unsafe (unsafePerformIO)
cToBool :: CInt -> Bool
cToBool :: CInt -> Bool
cToBool = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0)
cFromBool :: Bool -> CInt
cFromBool :: Bool -> CInt
cFromBool Bool
x = if Bool
x then CInt
1 else CInt
0
peekText :: CString -> IO T.Text
peekText :: CString -> IO Text
peekText = (String -> Text) -> IO String -> IO Text
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack (IO String -> IO Text)
-> (CString -> IO String) -> CString -> IO Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> IO String
peekCString
peekTextW :: CWString -> IO T.Text
peekTextW :: CWString -> IO Text
peekTextW = (String -> Text) -> IO String -> IO Text
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack (IO String -> IO Text)
-> (CWString -> IO String) -> CWString -> IO Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CWString -> IO String
peekCWString
peekMaybeTextW :: CWString -> IO (Maybe T.Text)
peekMaybeTextW :: CWString -> IO (Maybe Text)
peekMaybeTextW = (CWString -> IO Text) -> CWString -> IO (Maybe Text)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek CWString -> IO Text
peekTextW
withText :: T.Text -> (CString -> IO a) -> IO a
withText :: forall a. Text -> (CString -> IO a) -> IO a
withText = String -> (CString -> IO a) -> IO a
forall a. String -> (CString -> IO a) -> IO a
withCString (String -> (CString -> IO a) -> IO a)
-> (Text -> String) -> Text -> (CString -> IO a) -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
withTextW :: T.Text -> (CWString -> IO a) -> IO a
withTextW :: forall a. Text -> (CWString -> IO a) -> IO a
withTextW = String -> (CWString -> IO a) -> IO a
forall a. String -> (CWString -> IO a) -> IO a
withCWString (String -> (CWString -> IO a) -> IO a)
-> (Text -> String) -> Text -> (CWString -> IO a) -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
withMaybeTextW :: Maybe T.Text -> (CWString -> IO a) -> IO a
withMaybeTextW :: forall a. Maybe Text -> (CWString -> IO a) -> IO a
withMaybeTextW = (Text -> (CWString -> IO a) -> IO a)
-> Maybe Text -> (CWString -> IO a) -> IO a
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Text -> (CWString -> IO a) -> IO a
forall a. Text -> (CWString -> IO a) -> IO a
withTextW
mapWith :: (a -> (b -> IO c) -> IO c) -> [a] -> ([b] -> IO c) -> IO c
mapWith :: forall a b c.
(a -> (b -> IO c) -> IO c) -> [a] -> ([b] -> IO c) -> IO c
mapWith a -> (b -> IO c) -> IO c
with' = [b] -> [a] -> ([b] -> IO c) -> IO c
step [] where
step :: [b] -> [a] -> ([b] -> IO c) -> IO c
step [b]
acc [] [b] -> IO c
io = [b] -> IO c
io [b]
acc
step [b]
acc (a
x:[a]
xs) [b] -> IO c
io = a -> (b -> IO c) -> IO c
with' a
x ((b -> IO c) -> IO c) -> (b -> IO c) -> IO c
forall a b. (a -> b) -> a -> b
$ \b
y -> [b] -> [a] -> ([b] -> IO c) -> IO c
step ([b]
acc [b] -> [b] -> [b]
forall a. [a] -> [a] -> [a]
++ [b
y]) [a]
xs [b] -> IO c
io
data SomeObject = forall a. (Object a) => SomeObject (ForeignPtr a)
class Object a where
toObject :: a -> SomeObject
fromForeignPtr :: ForeignPtr a -> a
class Object a => Concrete a where
concreteType :: a -> Type
instance Object SomeObject where
toObject :: SomeObject -> SomeObject
toObject = SomeObject -> SomeObject
forall a. a -> a
id
fromForeignPtr :: ForeignPtr SomeObject -> SomeObject
fromForeignPtr = ForeignPtr SomeObject -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject
newtype Type = Type (ForeignPtr Type)
instance Object Type where
toObject :: Type -> SomeObject
toObject (Type ForeignPtr Type
x) = ForeignPtr Type -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Type
x
fromForeignPtr :: ForeignPtr Type -> Type
fromForeignPtr = ForeignPtr Type -> Type
Type
newtype Dictionary = Dictionary (ForeignPtr Dictionary)
instance Object Dictionary where
toObject :: Dictionary -> SomeObject
toObject (Dictionary ForeignPtr Dictionary
x) = ForeignPtr Dictionary -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Dictionary
x
fromForeignPtr :: ForeignPtr Dictionary -> Dictionary
fromForeignPtr = ForeignPtr Dictionary -> Dictionary
Dictionary
newtype List = List (ForeignPtr List)
instance Object List where
toObject :: List -> SomeObject
toObject (List ForeignPtr List
x) = ForeignPtr List -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr List
x
fromForeignPtr :: ForeignPtr List -> List
fromForeignPtr = ForeignPtr List -> List
List
newtype Tuple = Tuple (ForeignPtr Tuple)
instance Object Tuple where
toObject :: Tuple -> SomeObject
toObject (Tuple ForeignPtr Tuple
x) = ForeignPtr Tuple -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Tuple
x
fromForeignPtr :: ForeignPtr Tuple -> Tuple
fromForeignPtr = ForeignPtr Tuple -> Tuple
Tuple
withObject :: Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject :: forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject obj
obj Ptr a -> IO b
io = case obj -> SomeObject
forall a. Object a => a -> SomeObject
toObject obj
obj of
SomeObject ForeignPtr a
ptr -> ForeignPtr a -> (Ptr a -> IO b) -> IO b
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
ptr (Ptr a -> IO b
io (Ptr a -> IO b) -> (Ptr a -> Ptr a) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> Ptr a
forall a b. Ptr a -> Ptr b
castPtr)
peekObject :: Object obj => Ptr a -> IO obj
peekObject :: forall obj a. Object obj => Ptr a -> IO obj
peekObject Ptr a
ptr = IO (Ptr a) -> (Ptr a -> IO ()) -> (Ptr a -> IO obj) -> IO obj
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracketOnError IO (Ptr a)
incPtr Ptr a -> IO ()
forall a. Ptr a -> IO ()
decref Ptr a -> IO obj
forall {b} {p}. Object b => p -> IO b
mkObj where
incPtr :: IO (Ptr a)
incPtr = Ptr a -> IO ()
forall a. Ptr a -> IO ()
incref Ptr a
ptr IO () -> IO (Ptr a) -> IO (Ptr a)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr a -> IO (Ptr a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr a
ptr
mkObj :: p -> IO b
mkObj p
_ = ForeignPtr b -> b
forall a. Object a => ForeignPtr a -> a
fromForeignPtr (ForeignPtr b -> b) -> IO (ForeignPtr b) -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr b -> IO () -> IO (ForeignPtr b)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
newForeignPtr (Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr Ptr a
ptr) (Ptr a -> IO ()
forall a. Ptr a -> IO ()
decref Ptr a
ptr)
peekStaticObject :: Object obj => Ptr a -> IO obj
peekStaticObject :: forall obj a. Object obj => Ptr a -> IO obj
peekStaticObject Ptr a
ptr = ForeignPtr obj -> obj
forall a. Object a => ForeignPtr a -> a
fromForeignPtr (ForeignPtr obj -> obj) -> IO (ForeignPtr obj) -> IO obj
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr obj -> IO (ForeignPtr obj)
forall {a}. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ (Ptr a -> Ptr obj
forall a b. Ptr a -> Ptr b
castPtr Ptr a
ptr)
where
newForeignPtr_ :: Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Ptr a
p = Ptr a -> IO () -> IO (ForeignPtr a)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
newForeignPtr Ptr a
p (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
unsafeStealObject :: Object obj => Ptr a -> IO obj
unsafeStealObject :: forall obj a. Object obj => Ptr a -> IO obj
unsafeStealObject Ptr a
ptr = ForeignPtr obj -> obj
forall a. Object a => ForeignPtr a -> a
fromForeignPtr (ForeignPtr obj -> obj) -> IO (ForeignPtr obj) -> IO obj
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr obj -> IO () -> IO (ForeignPtr obj)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
newForeignPtr (Ptr a -> Ptr obj
forall a b. Ptr a -> Ptr b
castPtr Ptr a
ptr) (Ptr a -> IO ()
forall a. Ptr a -> IO ()
decref Ptr a
ptr)
stealObject :: Object obj => Ptr a -> IO obj
stealObject :: forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr a
ptr = Bool -> IO ()
exceptionIf (Ptr a
ptr Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr) IO () -> IO obj -> IO obj
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr a -> IO obj
forall obj a. Object obj => Ptr a -> IO obj
unsafeStealObject Ptr a
ptr
incref :: (Ptr a) -> IO ((()))
incref :: forall a. Ptr a -> IO ()
incref Ptr a
a1 =
let {a1' :: Ptr b
a1' = Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr Ptr a
a1} in
Ptr () -> IO ()
incref'_ Ptr ()
forall a. Ptr a
a1' IO () -> (() -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \()
res ->
let {res' :: ()
res' = () -> ()
forall a. a -> a
id ()
res} in
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (()
res')
{-# LINE 175 "lib/CPython/Internal.chs" #-}
decref :: (Ptr a) -> IO ((()))
decref a1 =
let {a1' = castPtr a1} in
decref'_ a1' >>= \res ->
let {res' = id res} in
return (res')
{-# LINE 179 "lib/CPython/Internal.chs" #-}
callObjectRaw :: (Object self, Object args) => (self) -> (args) -> IO ((SomeObject))
callObjectRaw a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
callObjectRaw'_ a1' a2' >>= \res ->
stealObject res >>= \res' ->
return (res')
{-# LINE 185 "lib/CPython/Internal.chs" #-}
unsafeCast :: (Object a, Object b) => a -> b
unsafeCast a = case toObject a of
SomeObject ptr -> fromForeignPtr (castForeignPtr ptr)
data Exception = Exception
{ Exception -> SomeObject
exceptionType :: SomeObject
, Exception -> SomeObject
exceptionValue :: SomeObject
, Exception -> Maybe SomeObject
exceptionTraceback :: Maybe SomeObject
}
deriving (Typeable)
instance Show Exception where
show :: Exception -> String
show Exception
_ = String
"<CPython exception>"
instance E.Exception Exception
exceptionIf :: Bool -> IO ()
exceptionIf :: Bool -> IO ()
exceptionIf Bool
False = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
exceptionIf Bool
True =
(Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr ()) -> IO ()) -> IO ())
-> (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
pType ->
(Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr ()) -> IO ()) -> IO ())
-> (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
pValue ->
(Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr ()) -> IO ()) -> IO ())
-> (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
pTrace -> do
Ptr (Ptr ()) -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO ()
pyErrFetch Ptr (Ptr ())
pType Ptr (Ptr ())
pValue Ptr (Ptr ())
pTrace
Ptr (Ptr ()) -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO ()
pyErrNormalizeException Ptr (Ptr ())
pType Ptr (Ptr ())
pValue Ptr (Ptr ())
pTrace
SomeObject
eType <- Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
unsafeStealObject (Ptr () -> IO SomeObject) -> IO (Ptr ()) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
pType
SomeObject
eValue <- Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
unsafeStealObject (Ptr () -> IO SomeObject) -> IO (Ptr ()) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
pValue
Maybe SomeObject
eTrace <- (Ptr () -> IO SomeObject) -> Ptr () -> IO (Maybe SomeObject)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
unsafeStealObject (Ptr () -> IO (Maybe SomeObject))
-> IO (Ptr ()) -> IO (Maybe SomeObject)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
pTrace
Exception -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO (Exception -> IO ()) -> Exception -> IO ()
forall a b. (a -> b) -> a -> b
$ SomeObject -> SomeObject -> Maybe SomeObject -> Exception
Exception SomeObject
eType SomeObject
eValue Maybe SomeObject
eTrace
checkStatusCode :: CInt -> IO ()
checkStatusCode :: CInt -> IO ()
checkStatusCode = Bool -> IO ()
exceptionIf (Bool -> IO ()) -> (CInt -> Bool) -> CInt -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== -CInt
1)
checkBoolReturn :: CInt -> IO Bool
checkBoolReturn :: CInt -> IO Bool
checkBoolReturn CInt
x = do
Bool -> IO ()
exceptionIf (Bool -> IO ()) -> Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ CInt
x CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== -CInt
1
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CInt
x CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0
checkIntReturn :: Integral a => a -> IO Integer
checkIntReturn :: forall a. Integral a => a -> IO Integer
checkIntReturn a
x = do
Bool -> IO ()
exceptionIf (Bool -> IO ()) -> Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -a
1
Integer -> IO Integer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> IO Integer) -> Integer -> IO Integer
forall a b. (a -> b) -> a -> b
$ a -> Integer
forall a. Integral a => a -> Integer
toInteger a
x
data SomeMapping = forall a. (Mapping a) => SomeMapping (ForeignPtr a)
class Object a => Mapping a where
toMapping :: a -> SomeMapping
instance Object SomeMapping where
toObject :: SomeMapping -> SomeObject
toObject (SomeMapping ForeignPtr a
x) = ForeignPtr a -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr a
x
fromForeignPtr :: ForeignPtr SomeMapping -> SomeMapping
fromForeignPtr = ForeignPtr SomeMapping -> SomeMapping
forall a. Mapping a => ForeignPtr a -> SomeMapping
SomeMapping
instance Mapping SomeMapping where
toMapping :: SomeMapping -> SomeMapping
toMapping = SomeMapping -> SomeMapping
forall a. a -> a
id
unsafeCastToMapping :: Object a => a -> SomeMapping
unsafeCastToMapping :: forall a. Object a => a -> SomeMapping
unsafeCastToMapping a
x = case a -> SomeObject
forall a. Object a => a -> SomeObject
toObject a
x of
SomeObject ForeignPtr a
ptr -> let
ptr' :: ForeignPtr SomeMapping
ptr' = ForeignPtr a -> ForeignPtr SomeMapping
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr a
ptr :: ForeignPtr SomeMapping
in ForeignPtr SomeMapping -> SomeMapping
forall a. Mapping a => ForeignPtr a -> SomeMapping
SomeMapping ForeignPtr SomeMapping
ptr'
data SomeSequence = forall a. (Sequence a) => SomeSequence (ForeignPtr a)
class Object a => Sequence a where
toSequence :: a -> SomeSequence
instance Object SomeSequence where
toObject :: SomeSequence -> SomeObject
toObject (SomeSequence ForeignPtr a
x) = ForeignPtr a -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr a
x
fromForeignPtr :: ForeignPtr SomeSequence -> SomeSequence
fromForeignPtr = ForeignPtr SomeSequence -> SomeSequence
forall a. Sequence a => ForeignPtr a -> SomeSequence
SomeSequence
instance Sequence SomeSequence where
toSequence :: SomeSequence -> SomeSequence
toSequence = SomeSequence -> SomeSequence
forall a. a -> a
id
unsafeCastToSequence :: Object a => a -> SomeSequence
unsafeCastToSequence :: forall a. Object a => a -> SomeSequence
unsafeCastToSequence a
x = case a -> SomeObject
forall a. Object a => a -> SomeObject
toObject a
x of
SomeObject ForeignPtr a
ptr -> let
ptr' :: ForeignPtr SomeSequence
ptr' = ForeignPtr a -> ForeignPtr SomeSequence
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr a
ptr :: ForeignPtr SomeSequence
in ForeignPtr SomeSequence -> SomeSequence
forall a. Sequence a => ForeignPtr a -> SomeSequence
SomeSequence ForeignPtr SomeSequence
ptr'
data SomeIterator = forall a. (Iterator a) => SomeIterator (ForeignPtr a)
class Object a => Iterator a where
toIterator :: a -> SomeIterator
instance Object SomeIterator where
toObject :: SomeIterator -> SomeObject
toObject (SomeIterator ForeignPtr a
x) = ForeignPtr a -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr a
x
fromForeignPtr :: ForeignPtr SomeIterator -> SomeIterator
fromForeignPtr = ForeignPtr SomeIterator -> SomeIterator
forall a. Iterator a => ForeignPtr a -> SomeIterator
SomeIterator
instance Iterator SomeIterator where
toIterator :: SomeIterator -> SomeIterator
toIterator = SomeIterator -> SomeIterator
forall a. a -> a
id
unsafeCastToIterator :: Object a => a -> SomeIterator
unsafeCastToIterator :: forall a. Object a => a -> SomeIterator
unsafeCastToIterator a
x = case a -> SomeObject
forall a. Object a => a -> SomeObject
toObject a
x of
SomeObject ForeignPtr a
ptr -> let
ptr' :: ForeignPtr SomeIterator
ptr' = ForeignPtr a -> ForeignPtr SomeIterator
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr a
ptr :: ForeignPtr SomeIterator
in ForeignPtr SomeIterator -> SomeIterator
forall a. Iterator a => ForeignPtr a -> SomeIterator
SomeIterator ForeignPtr SomeIterator
ptr'
foreign import ccall safe "CPython/Internal.chs.h hscpython_Py_INCREF"
incref'_ :: ((C2HSImp.Ptr ()) -> (IO ()))
foreign import ccall safe "CPython/Internal.chs.h hscpython_Py_DECREF"
decref'_ :: ((C2HSImp.Ptr ()) -> (IO ()))
foreign import ccall safe "CPython/Internal.chs.h PyObject_CallObject"
callObjectRaw'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))
foreign import ccall safe "CPython/Internal.chs.h PyErr_Fetch"
pyErrFetch :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))
foreign import ccall safe "CPython/Internal.chs.h PyErr_NormalizeException"
pyErrNormalizeException :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))