Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd c2hs error #5367

Open
mitchellwrosen opened this issue Jun 9, 2018 · 1 comment
Open

Odd c2hs error #5367

mitchellwrosen opened this issue Jun 9, 2018 · 1 comment

Comments

@mitchellwrosen
Copy link

I've put together a repo that reproduces what I thought was a language-c bug, but cabal is behaving oddly as well.

The repo:

https://github.com/mitchellwrosen/language-c-issue-54

To reproduce:

  • Run ./build once:
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
 - foo-0 (lib:foo) (first run)
Configuring foo-0...
Preprocessing library for foo-0..
c2hs: Errors during generation of C wrappers:

./Foo.chs:9: (column 4) [ERROR]  >>> Internal wrapper error!
  Something went wrong generating a bare structure wrapper.
  makeArg:arg=False
  cdecl=CDecl [CTypeSpec (CTypeDef (Ident "WINDOW" 143904934 (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),6) (Name {nameId = 4053}))) (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),6) (Name {nameId = 4054})))] [(Just (CDeclr Nothing [CPtrDeclr [] (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),1) (Name {nameId = 4055}))] Nothing [] (OnlyPos <no file> (<no file>,-1))),Nothing,Nothing)] (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),1) (Name {nameId = 4056}))
  idx=1
  • Run ./build again:

Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
 - foo-0 (lib:foo) (first run)
Preprocessing library for foo-0..
Building library for foo-0..
[1 of 1] Compiling Foo              ( /home/mitchell/junk/dist-newstyle/build/x86_64-linux/ghc-8.4.3/foo-0/build/Foo.hs, /home/mitchell/junk/dist-newstyle/build/x86_64-linux/ghc-8.4.3/foo-0/build/Foo.o )
ignoring (possibly broken) abi-depends field for packages

For some reason, c2hs barfs the first time, then stops complaining. The generated file looks fine to me, even after only one invocation of ./build:

$ cat $(find dist-newstyle -name Foo.hs)

-- GENERATED by C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./Foo.chs" #-}
{-# language ForeignFunctionInterface #-}

module Foo where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp





type Window = C2HSImp.Ptr (())
{-# LINE 7 "./Foo.chs" #-}


keypad :: (Window) -> (Bool) -> IO ((Int))
keypad a1 a2 =
  let {a1' = id a1} in 
  let {a2' = C2HSImp.fromBool a2} in 
  keypad'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 9 "./Foo.chs" #-}


foreign import ccall safe "Foo.chs.h __c2hs_wrapped__keypad"
  keypad'_ :: ((Window) -> (C2HSImp.CInt{-bool-} -> (IO C2HSImp.CInt)))

Sorry for the mess of info, I'm not too sure what's going on here :) Thanks.

@vmchale
Copy link
Contributor

vmchale commented Sep 30, 2019

I've run into a similar issue. After c2hs invocation fails once, cabal tries to use the generated .hs file anyhow, and then fails to find it, viz.

vanessa@vanessa-desktop ~/programming/haskell/done/lzlib 🌸 cabal build
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - lzlib-0.2.0.2 (lib) (first run)
Configuring library for lzlib-0.2.0.2..
Preprocessing library for lzlib-0.2.0.2..
c2hs: C header contains errors:

cbits/lzlib.h:59: (column 23) [ERROR]  >>> Syntax error !
  The symbol `uint8_t' does not fit here.

vanessa@vanessa-desktop ~/programming/haskell/done/lzlib 🌸 cabal build
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - lzlib-0.2.0.2 (lib) (first run)
Preprocessing library for lzlib-0.2.0.2..
Building library for lzlib-0.2.0.2..

<no location info>: error:
    module ‘Codec.Lzip.Raw’ cannot be found locally

There's a branch that can be used to reproduce it: https://github.com/vmchale/lzlib/tree/cabal-bug

@gbaz gbaz added the type: bug label Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants