c2hsc icon indicating copy to clipboard operation
c2hsc copied to clipboard

pointer typedef generates incorrect type

Open claudeha opened this issue 9 years ago • 1 comments

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" #-}

claudeha avatar Jun 03 '15 19:06 claudeha

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

flip111 avatar Dec 26 '18 16:12 flip111