haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
199 stars 50 forks source link

C2HS generates `Ptr (Ptr STH)` type. #220

Closed Magicloud closed 5 years ago

Magicloud commented 5 years ago

Similar type definitions.

{#pointer *surface_t as Surface foreign finalizer surface_destroy newtype#}
outSurface :: Ptr Surface -> IO Surface
outSurface = liftM Surface . newForeignPtr_

{#pointer *font_options_t as FontOptions foreign finalizer font_options_destroy newtype#}
outFontOptions :: Ptr FontOptions -> IO FontOptions
outFontOptions = liftM FontOptions . newForeignPtr_

Similar functions.

{#fun pattern_get_surface as ^ { `Pattern', `Surface' outSurface* } -> `Status'#}

{#fun scaled_font_get_font_options as ^ { `ScaledFont', `FontOptions' outFontOptions* } -> `()'#}

Different bindings.

foreign import ccall safe "Graphics/Cairo/Drawing/Patterns.chs.h cairo_pattern_get_surface"
  patternGetSurface'_ :: ((C2HSImp.Ptr (Pattern)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (Surface))) ->   (IO C2HSImp.CInt))) -- WRONG

foreign import ccall safe "Graphics/Cairo/Fonts/ScaledFont.chs.h                                 cairo_scaled_font_get_font_options"
  scaledFontGetFontOptions'_ :: ((C2HSImp.Ptr (ScaledFont)) -> ((C2HSImp.Ptr (FontOptions)) ->   (IO ())))
Magicloud commented 5 years ago

I see. Missed the ** in .h.