jwiegley / c2hsc

Utility for creating .hsc files from C API header files
BSD 3-Clause "New" or "Revised" License
27 stars 15 forks source link

pointer typedef generates incorrect type #24

Open claudeha opened 9 years ago

claudeha commented 9 years ago

typedef int * bug; becomes type C'bug = CInt instead of type C'bug = Ptr CInt:

$ c2hsc --version

c2hsc v0.6.4, (C) John Wiegley 2012

$ cat bug.h

typedef int * bug;

$ c2hsc --prefix "Pointer" bug.h

Wrote Bug.hsc

$ cat Bug.hsc

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
#include <bindings.dsl.h>
#include "bug.h"
module Pointer.Bug where
import Foreign.Ptr
#strict_import

{- typedef int * bug; -}
#synonym_t bug , CInt

$ hsc2hs Bug.hsc

$ cat Bug.hs

{-# LINE 1 "Bug.hsc" #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# LINE 2 "Bug.hsc" #-}

{-# LINE 3 "Bug.hsc" #-}

{-# LINE 4 "Bug.hsc" #-}
module Pointer.Bug where
import Foreign.Ptr
import Foreign.Ptr (Ptr,FunPtr,plusPtr)
import Foreign.Ptr (wordPtrToPtr,castPtrToFunPtr)
import Foreign.Storable
import Foreign.C.Types
import Foreign.C.String (CString,CStringLen,CWString,CWStringLen)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Array (peekArray,pokeArray)
import Data.Int
import Data.Word

{-# LINE 7 "Bug.hsc" #-}

{- typedef int * bug; -}
type C'bug = CInt

{-# LINE 10 "Bug.hsc" #-}
flip111 commented 5 years ago

This works at the time of writing

C

typedef const PCRE2_UCHAR8  *PCRE2_SPTR8;

HSC

#globalvar PCRE2_SPTR8 , Ptr CUChar

not sure if it's because it's const or this bug is just fixed now