{-# LANGUAGE CApiFFI #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} module Example where import qualified Data.Proxy import qualified Foreign as F import qualified Foreign.C as FC import qualified GHC.Int import qualified GHC.Ptr as Ptr import qualified GHC.Records import qualified HsBindgen.Runtime.HasCField import qualified HsBindgen.Runtime.Internal.FunPtr import qualified HsBindgen.Runtime.Internal.HasFFIType import qualified HsBindgen.Runtime.Marshal import qualified Prelude as P import HsBindgen.Runtime.Internal.TypeEquality (TyEq) import Prelude (Eq, IO, Ord, Show) {-| Auxiliary type used by 'MyFunctionPointer' __C declaration:__ @MyFunctionPointer@ __defined at:__ @binding-specs\/fun_arg\/macro\/function_pointer.h 4:15@ __exported by:__ @binding-specs\/fun_arg\/macro\/function_pointer.h@ -} newtype MyFunctionPointer_Aux = MyFunctionPointer_Aux { unwrapMyFunctionPointer_Aux :: FC.CInt -> IO FC.CInt } deriving newtype (HsBindgen.Runtime.Internal.HasFFIType.HasFFIType) foreign import ccall safe "wrapper" hs_bindgen_47dfd04698dd2e6f_base :: (GHC.Int.Int32 -> IO GHC.Int.Int32) -> IO (Ptr.FunPtr (GHC.Int.Int32 -> IO GHC.Int.Int32)) -- __unique:__ @toMyFunctionPointer_Aux@ hs_bindgen_47dfd04698dd2e6f :: MyFunctionPointer_Aux -> IO (Ptr.FunPtr MyFunctionPointer_Aux) hs_bindgen_47dfd04698dd2e6f = \fun0 -> P.fmap HsBindgen.Runtime.Internal.HasFFIType.castFunPtrFromFFIType (hs_bindgen_47dfd04698dd2e6f_base (HsBindgen.Runtime.Internal.HasFFIType.toFFIType fun0)) foreign import ccall safe "dynamic" hs_bindgen_5738272f94a589e2_base :: Ptr.FunPtr (GHC.Int.Int32 -> IO GHC.Int.Int32) -> GHC.Int.Int32 -> IO GHC.Int.Int32 -- __unique:__ @fromMyFunctionPointer_Aux@ hs_bindgen_5738272f94a589e2 :: Ptr.FunPtr MyFunctionPointer_Aux -> MyFunctionPointer_Aux hs_bindgen_5738272f94a589e2 = \funPtr0 -> HsBindgen.Runtime.Internal.HasFFIType.fromFFIType (hs_bindgen_5738272f94a589e2_base (HsBindgen.Runtime.Internal.HasFFIType.castFunPtrToFFIType funPtr0)) instance HsBindgen.Runtime.Internal.FunPtr.ToFunPtr MyFunctionPointer_Aux where toFunPtr = hs_bindgen_47dfd04698dd2e6f instance HsBindgen.Runtime.Internal.FunPtr.FromFunPtr MyFunctionPointer_Aux where fromFunPtr = hs_bindgen_5738272f94a589e2 instance ( TyEq ty ((HsBindgen.Runtime.HasCField.CFieldType MyFunctionPointer_Aux) "unwrapMyFunctionPointer_Aux") ) => GHC.Records.HasField "unwrapMyFunctionPointer_Aux" (Ptr.Ptr MyFunctionPointer_Aux) (Ptr.Ptr ty) where getField = HsBindgen.Runtime.HasCField.fromPtr (Data.Proxy.Proxy @"unwrapMyFunctionPointer_Aux") instance HsBindgen.Runtime.HasCField.HasCField MyFunctionPointer_Aux "unwrapMyFunctionPointer_Aux" where type CFieldType MyFunctionPointer_Aux "unwrapMyFunctionPointer_Aux" = FC.CInt -> IO FC.CInt offset# = \_ -> \_ -> 0 {-| __C declaration:__ @MyFunctionPointer@ __defined at:__ @binding-specs\/fun_arg\/macro\/function_pointer.h 4:15@ __exported by:__ @binding-specs\/fun_arg\/macro\/function_pointer.h@ -} newtype MyFunctionPointer = MyFunctionPointer { unwrapMyFunctionPointer :: Ptr.FunPtr MyFunctionPointer_Aux } deriving stock (Eq, Ord, Show) deriving newtype ( HsBindgen.Runtime.Marshal.StaticSize , HsBindgen.Runtime.Marshal.ReadRaw , HsBindgen.Runtime.Marshal.WriteRaw , F.Storable , HsBindgen.Runtime.Internal.HasFFIType.HasFFIType ) instance ( TyEq ty ((HsBindgen.Runtime.HasCField.CFieldType MyFunctionPointer) "unwrapMyFunctionPointer") ) => GHC.Records.HasField "unwrapMyFunctionPointer" (Ptr.Ptr MyFunctionPointer) (Ptr.Ptr ty) where getField = HsBindgen.Runtime.HasCField.fromPtr (Data.Proxy.Proxy @"unwrapMyFunctionPointer") instance HsBindgen.Runtime.HasCField.HasCField MyFunctionPointer "unwrapMyFunctionPointer" where type CFieldType MyFunctionPointer "unwrapMyFunctionPointer" = Ptr.FunPtr MyFunctionPointer_Aux offset# = \_ -> \_ -> 0 {-| __C declaration:__ @A@ __defined at:__ @binding-specs\/fun_arg\/macro\/function_pointer.h 7:9@ __exported by:__ @binding-specs\/fun_arg\/macro\/function_pointer.h@ -} newtype A = A { unwrapA :: MyFunctionPointer } deriving stock (Eq, Ord, Show) deriving newtype ( HsBindgen.Runtime.Marshal.StaticSize , HsBindgen.Runtime.Marshal.ReadRaw , HsBindgen.Runtime.Marshal.WriteRaw , F.Storable , HsBindgen.Runtime.Internal.HasFFIType.HasFFIType ) instance ( TyEq ty ((HsBindgen.Runtime.HasCField.CFieldType A) "unwrapA") ) => GHC.Records.HasField "unwrapA" (Ptr.Ptr A) (Ptr.Ptr ty) where getField = HsBindgen.Runtime.HasCField.fromPtr (Data.Proxy.Proxy @"unwrapA") instance HsBindgen.Runtime.HasCField.HasCField A "unwrapA" where type CFieldType A "unwrapA" = MyFunctionPointer offset# = \_ -> \_ -> 0 {-| __C declaration:__ @B@ __defined at:__ @binding-specs\/fun_arg\/macro\/function_pointer.h 8:9@ __exported by:__ @binding-specs\/fun_arg\/macro\/function_pointer.h@ -} newtype B = B { unwrapB :: A } deriving stock (Eq, Ord, Show) deriving newtype ( HsBindgen.Runtime.Marshal.StaticSize , HsBindgen.Runtime.Marshal.ReadRaw , HsBindgen.Runtime.Marshal.WriteRaw , F.Storable , HsBindgen.Runtime.Internal.HasFFIType.HasFFIType ) instance ( TyEq ty ((HsBindgen.Runtime.HasCField.CFieldType B) "unwrapB") ) => GHC.Records.HasField "unwrapB" (Ptr.Ptr B) (Ptr.Ptr ty) where getField = HsBindgen.Runtime.HasCField.fromPtr (Data.Proxy.Proxy @"unwrapB") instance HsBindgen.Runtime.HasCField.HasCField B "unwrapB" where type CFieldType B "unwrapB" = A offset# = \_ -> \_ -> 0