环境
AC 枚举类型由 c2hs 渲染到 Haskell 中,并带有Storable
正确编译的实例 ( TypesC2Hs.chs
)。我将这个不合格的导入到我为inline-c
上下文 ( Internal.hs
) 分配的模块中。.hs
由 c2hs 生成的模块和Internal.hs
由 导入的模块,InlineC.hs
另一个inline-c
模块包含包装 C 调用的准引号。
TypesC2Hs.hs -------------
| |
V V
Internal.hs -------> InlineC.hs
问题
InlineC.hs
抱怨这种类型无法编组:“外部声明中不可接受的参数类型:'DMBoundaryType' 不能在外部调用中编组检查声明时:”
到底是怎么回事?这是第一次inline-c
给我这种错误的类型。
我应该注意,不需要直接取消引用的其他类型,例如newtype DM = DM (Ptr DM) deriving Storable
,可以使用上述方法正常工作。
提前致谢
类型C2Hs.chs
{# enum DMBoundaryType as DMBoundaryType {underscoreToCase} deriving (Eq, Show) #}
instance Storable DMBoundaryType where
sizeOf _ = {# sizeof DMBoundaryType #}
alignment _ = {# alignof DMBoundaryType #}
peek = peek
poke = poke
内部.hs
{-# LANGUAGE QuasiQuotes, TemplateHaskell ,GeneralizedNewtypeDeriving, StandaloneDeriving ,DeriveDataTypeable, DataKinds, OverloadedStrings #-}
module Internal where
import TypesC2Hs
import qualified Language.C.Inline as C
import qualified Language.C.Types as CT
import Language.C.Inline.Context
import qualified Language.Haskell.TH as TH
import Data.Monoid ((<>), mempty)
import qualified Data.Map as Map
ctx :: Context
ctx = baseCtx <> funCtx <> vecCtx <> bsCtx <> pctx where
pctx = mempty {ctxTypesTable = typesTable}
typesTable :: Map.Map CT.TypeSpecifier TH.TypeQ
typesTable = Map.fromList
[ (CT.TypeName "DMBoundaryType", [t| DMBoundaryType |]) ]
内联C.hs
dmdaCreate1d0' cc bx m dof s =
withPtr ( \ dm -> [C.exp|int{DMDACreate1d($(int c),
$(DMBoundaryType bx),
$(PetscInt m),
$(PetscInt dof),
$(PetscInt s),
NULL,
$(DM* dm))}|] )
where c = unComm cc