haskell / c2hs

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

c2hs-2.28.2 (and master) is not able to parse glibc-2.26 <math.h> #192

Closed trofi closed 6 months ago

trofi commented 7 years ago

The test Issue-83 fails as:

$ c2hs Issue83.chs 
c2hs: C header contains errors:

/usr/include/bits/mathcalls-helper-functions.h:21: (column 40) [ERROR]  >>> Syntax error !
  The symbol `__value' does not fit here.
// /usr/include/bits/mathcalls-helper-functions.h:21

__MATHDECL_1 (int, __fpclassify,, (_Mdouble_ __value))
     __attribute__ ((__const__));

It seems to be related to macro expansion. I'll try to build minimal reproducible example out of glibc headers.

trofi commented 7 years ago

The minimal header contains _Float128:

extern int __fpclassifyf128 (_Float128 __value) __attribute__ ((__nothrow__ , __leaf__))
     __attribute__ ((__const__));

Look similar to #191

tangboyun commented 6 years ago

Same error here.

GCC version: 7.2.0 glibc: 2.26 arch: x86_64 c2hs: latest

Configuring inline-r-0.9.0.1...
Building inline-r-0.9.0.1...
Preprocessing library inline-r-0.9.0.1...
c2hs: C header contains errors:

/usr/include/bits/mathcalls-helper-functions.h:21: (column 40) [ERROR]  >>> Syntax error !
  The symbol `__value' does not fit here.

Build c2hs against lang-c-0.7.0 with following patch can not fix this bug.

--- c2hs/src/C2HS/CHS/Lexer.hs  2017-09-26 14:46:32.883631956 +0800
+++ c2hs-patched/src/C2HS/CHS/Lexer.hs  2017-09-26 14:21:20.337931237 +0800
@@ -712,7 +712,7 @@
                     s, Nothing)

 adjustPosByCLinePragma :: String -> Position -> Position
-adjustPosByCLinePragma str pos = adjustPos fname' row' pos
+adjustPosByCLinePragma str pos = position (posOffset pos) fname' row' 1 (Just pos)
   where
     fname           = posFile pos
     str'            = dropWhite str
lspitzner commented 6 years ago

After some trial and error, I found an ugly workaround: Modify mathcalls-helper-functions.h and replace _Mdouble_ with double (math.h does #define _Mdouble_ double for me).

Not fond of modifying system include files, but better than being forced to downgrade my system..

lspitzner commented 6 years ago

Of course that would be too easy and breaks, because at some point _Mdouble_ gets defined as float, too. Nevermind.

deech commented 6 years ago

I upgraded c2hs to language-c-0.7.0 on a branch on my fork. I also included a failing test case using the minimal example provided. I was able to work around this particular issue by doing c2hs --cppopts=-D_Float128=__float128 c2hs/tests/bugs/issue-192/Issue192.chs. The announcement for glibc 2.26 says that _Float128 and __float128 are identical. Please test out my branch to confirm the fix. This is definitely something that needs to get fixed on the language-c side but hopefully this gets you going.

krakrjak commented 6 years ago

@deech I tried using the following in a test stack.yaml file:

packages:
  - '.'
# Added to fix issue #192 for c2hs on github/haskell/c2hs
  - location:
     git: https://github.com/deech/c2hs.git
     commit: 8b79823c32e234c161baec67fdf7907952ca62b8
    extra-dep: false

extra-deps:
  - language-c-0.7.0
  - c2hs-0.28.2

I have to take a little care that I'm using the correct c2hs (hint stack build c2hs inside the project). I still couldn't get the fix integrated into my stack workflow, but I did verify that using your c2hs binary and setting the definition for _Float128 does let me build the previously failing file with the OP's issue.

deech commented 6 years ago

I also, unfortunately, had issues setting the location by commit hash. I ended up doing:

packages:
- location: .
- location: https://github.com/deech/c2hs/archive/LanguageCUpgrade_Float128Bug.zip

extra-deps:
  - c2hs-0.28.2
  - vector-0.11.0.0
  - primitive-0.6.1.0
  - language-c-0.7.0
  - mtl-2.2.1
krakrjak commented 6 years ago

I got this working, from your (@deech) branch of c2hs do a stack init and try the following snippet

packages:
- .
- location:
    git: https://github.com/krakrjak/language-c.git
    commit: 5c0efb4d5d49bcd065b8c9e41188a41562edf37c
  extra-dep: false

extra-deps: [language-c-0.7.0]

Then stack build and put the resulting c2hs binary on your PATH somewhere. That will at least reduce the amount of --cppopts=-D.... you have to carry around while the dust settles.

deech commented 6 years ago

Once your language-c PR is merged I'll cut another release of c2hs.

mdorman commented 6 years ago

So in an effort to get alsa-mixer buliding again on NixOS, I modified the expressions for language-c_0_7_0 to include (as a patch) https://github.com/krakrjak/language-c/commit/5c0efb4d5d49bcd065b8c9e41188a41562edf37c, and c2hs to include (as a patch) https://github.com/deech/c2hs/commit/8b79823c32e234c161baec67fdf7907952ca62b8

Unfortunately, when the test suite for c2hs is run, I get 5 failures that all seem to be of the general form:

  Issue #25: [Failed]
ERROR: 
Ran commands: 
cd /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25
rm -f /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25/Issue25.hs
rm -f /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25/Issue25.chs.h
rm -f /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25/Issue25.chi
rm -f /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25/issue25_c.o
rm -f /tmp/nix-build-c2hs-0.28.2.drv-0/c2hs-0.28.2/tests/bugs/issue-25/Issue25
c2hs Issue25.chs
which c2hs

Exception: error running: c2hs Issue25.chs
exit status: 1
stderr: c2hs: C header contains errors:

/nix/store/xd2mlzvlgmskbyyb33lz2vdq15k74xpr-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

Where the particular line in question is:

/* The type _Float128 exists only since GCC 7.0.  */
# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
typedef __float128 _Float128;
# endif

Dunno if this is an issue of my environment or what. I'll try to find time to continue to poke at it.

deech commented 6 years ago

Would you mind posting your Nix recipe? I don't run NixOS but I can try replicating with plain Nix.

mdorman commented 6 years ago

Happy to! https://github.com/mdorman/nixpkgs/commit/0a74880df16e585f85166d4a991ac8fd1b08773b is the change I made that pulls in the patches.

And then something like nix-build --no-build-output --attr haskellPackages.alsa-mixer <location of checked-out tree> will demonstrate the problem. Alternatively, you can remove the dontCheck () wrapper around the c2hs expression, and it'll run the test suite, etc.

The branch is https://github.com/mdorman/nixpkgs/tree/haskell-updates, and though it shouldn't matter much, it is based on top of https://github.com/peti/nixpkgs/tree/haskell-updates.

krakrjak commented 6 years ago

That error makes sense... With the language-c update you don't need this typdef any more. It's cruft and the way the fix I did makes them both be __float128 so that typdef is no longer needed once the bump is made to language-c.

krakrjak commented 6 years ago

@deech https://github.com/visq/language-c/pull/41 has been merged.

deech commented 6 years ago

I've just uploaded c2hs 0.28.3. It uses language-c-0.7.1 which has a fix for the _Float128 bug. There's a test case in place but if someone could try it and let me know I'll close the issue.

peti commented 6 years ago

The c2hs-0.28.3 test suite still fails when built in NixOS:

[...]
configuring
configureFlags: --verbose --prefix=/nix/store/z72s6rgg2v2y6y6c6yknd764pq69r5wr-c2hs-0.28.3 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --datadir=/nix/store/8gc2dlcw2lk335gqm9n0x9p1d660xkfj-c2hs-0.28.3-data/share/ghc-8.0.2 --docdir=/nix/store/cbk9xxs88wricw6s6bva24nrmykdha8m-c2hs-0.28.3-doc/share/doc --with-gcc=gcc --package-db=/build/package.conf.d --ghc-option=-optl=-Wl,-rpath=/nix/store/z72s6rgg2v2y6y6c6yknd764pq69r5wr-c2hs-0.28.3/lib/ghc-8.0.2/c2hs-0.28.3 --ghc-option=-j4 --disable-split-objs --disable-library-profiling --disable-profiling --enable-shared --disable-coverage --enable-library-vanilla --enable-executable-dynamic --enable-tests --ghc-option=-split-sections
Configuring c2hs-0.28.3...
Flags chosen: regression=False, base3=True
Dependency HUnit -any: using HUnit-1.5.0.0
Dependency array -any: using array-0.5.1.1
Dependency base >=3 && <5: using base-4.9.1.0
Dependency bytestring -any: using bytestring-0.10.8.1
Dependency containers -any: using containers-0.5.7.1
Dependency directory -any: using directory-1.3.0.0
Dependency dlist -any: using dlist-0.8.0.3
Dependency filepath -any: using filepath-1.4.1.1
Dependency language-c >=0.7.1 && <0.8: using language-c-0.7.1
Dependency pretty -any: using pretty-1.1.3.3
Dependency process -any: using process-1.4.3.0
Dependency shelly >=1.0: using shelly-1.6.8.3
Dependency test-framework -any: using test-framework-0.8.1.1
Dependency test-framework-hunit -any: using test-framework-hunit-0.3.0.2
Dependency text -any: using text-1.2.2.2
Dependency transformers -any: using transformers-0.5.2.0
Using Cabal-1.24.2.0 compiled by ghc-8.0
Using compiler: ghc-8.0.2
Using install prefix: /nix/store/z72s6rgg2v2y6y6c6yknd764pq69r5wr-c2hs-0.28.3
[...]
running tests
Running 2 test suites...
Test suite test-bugs: RUNNING...
** Call hook for `C':
extractCompType: checking for alias
extractCompType: checking for alias
Imported function type: (IO ())
** Call hook for `c':
extractCompType: checking for alias
extractCompType: checking for alias
Imported function type: (IO ())
** Call hook for `C':
extractCompType: checking for alias
extractCompType: checking for alias
Imported function type: (IO ())
c2hs: Prelude.head: empty list
[1 of 1] Compiling Main             ( Issue9.hs, Issue9.o )
Linking Issue9 ...
c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

issue15.c: In function ‘tst_val’:
issue15.c:3:10: warning: multi-character character constant [-Wmultichar]
   return 'drag';
          ^~~~~~
[1 of 1] Compiling Main             ( Issue15.hs, Issue15.o )
Linking Issue15 ...
[1 of 1] Compiling Main             ( Issue16.hs, Issue16.o )
Linking Issue16 ...
[1 of 1] Compiling Main             ( Issue19.hs, Issue19.o )
Linking Issue19 ...
c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

[1 of 1] Compiling Main             ( Issue22.hs, Issue22.o )
Linking Issue22 ...
[1 of 1] Compiling Main             ( Issue23.hs, Issue23.o )
Linking Issue23 ...
c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

[1 of 1] Compiling Main             ( Issue31.hs, Issue31.o )
Linking Issue31 ...
[1 of 1] Compiling Main             ( Issue32.hs, Issue32.o )
Linking Issue32 ...
[1 of 1] Compiling Main             ( Issue36.hs, Issue36.o )
Linking Issue36 ...
[1 of 1] Compiling Main             ( Issue38.hs, Issue38.o )
Linking Issue38 ...
[1 of 1] Compiling Main             ( Issue43.hs, Issue43.o )
Linking Issue43 ...
[1 of 1] Compiling Main             ( Issue44.hs, Issue44.o )
Linking Issue44 ...
[1 of 1] Compiling Main             ( Issue45.hs, Issue45.o )
Linking Issue45 ...
[1 of 1] Compiling Main             ( Issue46.hs, Issue46.o )
Linking Issue46 ...
[1 of 1] Compiling Main             ( Issue47.hs, Issue47.o )
Linking Issue47 ...
[1 of 1] Compiling Main             ( Issue51_nonGNU.hs, Issue51_nonGNU.o )
Linking Issue51_nonGNU ...
[1 of 1] Compiling Main             ( Issue51_GNU.hs, Issue51_GNU.o )
Linking Issue51_GNU ...
[1 of 1] Compiling Main             ( Issue54.hs, Issue54.o )
Linking Issue54 ...
[1 of 1] Compiling Main             ( Issue60.hs, Issue60.o )
Linking Issue60 ...
[1 of 1] Compiling Main             ( Issue62.hs, Issue62.o )
Linking Issue62 ...
[1 of 1] Compiling Main             ( Issue65.hs, Issue65.o )
Linking Issue65 ...
[1 of 1] Compiling Main             ( Issue69.hs, Issue69.o )
Linking Issue69 ...
[1 of 1] Compiling Foo              ( Issue70.hs, Issue70.o )
[1 of 1] Compiling Main             ( Issue73.hs, Issue73.o )
Linking Issue73 ...
[1 of 1] Compiling Main             ( Issue75.hs, Issue75.o )
Linking Issue75 ...
[1 of 1] Compiling Main             ( Issue79.hs, Issue79.o )
Linking Issue79 ...
[1 of 1] Compiling Main             ( Issue80.hs, Issue80.o )
Linking Issue80 ...
[1 of 1] Compiling Main             ( Issue82.hs, Issue82.o )
Linking Issue82 ...
[1 of 1] Compiling Main             ( Issue93.hs, Issue93.o )
Linking Issue93 ...
[1 of 1] Compiling Main             ( Issue95.hs, Issue95.o )
Linking Issue95 ...
[1 of 1] Compiling Main             ( Issue96.hs, Issue96.o )
Linking Issue96 ...
[1 of 1] Compiling Main             ( Issue98.hs, Issue98.o )
Linking Issue98 ...
[1 of 1] Compiling Main             ( Issue107.hs, Issue107.o )
Linking Issue107 ...
[1 of 1] Compiling Main             ( Issue113.hs, Issue113.o )
Linking Issue113 ...
[1 of 1] Compiling Main             ( Issue115.hs, Issue115.o )
Linking Issue115 ...
[1 of 1] Compiling Main             ( Issue116.hs, Issue116.o )
Linking Issue116 ...
[1 of 1] Compiling Main             ( Issue123.hs, Issue123.o )
Linking Issue123 ...
[1 of 1] Compiling Main             ( Issue127.hs, Issue127.o )
Linking Issue127 ...
c2hs__bool_size.c: In function ‘main’:
c2hs__bool_size.c:2:45: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
 int main(int argc, char *argv[]) { printf("%u\n", sizeof(_Bool)); return 0; }
                                             ^
[1 of 1] Compiling Main             ( Issue130.hs, Issue130.o )
Linking Issue130 ...
[1 of 1] Compiling Main             ( Issue133.hs, Issue133.o )
Linking Issue133 ...
[1 of 1] Compiling Main             ( Issue134.hs, Issue134.o )
Linking Issue134 ...
[1 of 1] Compiling Main             ( Issue136.hs, Issue136.o )
Linking Issue136 ...
[1 of 1] Compiling Main             ( Issue140.hs, Issue140.o )
Linking Issue140 ...
c2hs: Errors during expansion of binding hooks:

issue141.h:1: (column 9) [ERROR]  >>> Illegal use of incomplete type!
  Expected a fully defined structure or union tag; instead found incomplete type.

c2hs: Errors during expansion of binding hooks:

issue141.h:1: (column 9) [ERROR]  >>> Illegal use of incomplete type!
  Expected a fully defined structure or union tag; instead found incomplete type.

c2hs: Errors during expansion of binding hooks:

Issue141C.chs:7: (column 17) [ERROR]  >>> Illegal use of incomplete type!
  Expected a fully defined structure or union tag; instead found incomplete type.

c2hs: Errors during expansion of binding hooks:

Issue149.chs:5: (column 3) [ERROR]  >>> Function arity mismatch!
  Parameter marshallers are missing.

[1 of 1] Compiling Issue151         ( Issue151.hs, Issue151.o )
[1 of 1] Compiling Main             ( Issue152.hs, Issue152.o )
Linking Issue152 ...
c2hs: Errors during expansion of binding hooks:

Issue180.chs:8: (column 18) [ERROR]  >>> Function arity mismatch!
  This parameter is in excess of the C arguments.

[1 of 1] Compiling Issue192         ( Issue192.hs, Issue192.o )
[1 of 1] Compiling Main             ( Issue48.hs, Issue48.o )
Linking Issue48 ...
c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

[1 of 1] Compiling Main             ( Issue102.hs, Issue102.o )
Linking Issue102 ...
Bugs:
[1 of 1] Compiling Main             ( Capital.hs, Capital.o )
Linking Capital ...
upper C();
lower c();
upper C();
  call_capital (issue #??): [OK]
  Issue #7: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-7
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.chi
c2hs Issue7.chs
which c2hs

Exception: HUnitFailure (Just (SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "tests/test-bugs.hs", srcLocStartLine = 443, srcLocStartCol = 12, srcLocEndLine = 443, srcLocEndCol = 37})) (Reason "")
PTA:8
AOP:32
(32,64)
64
OK
  Issue #9: [OK]
  Issue #10: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-10
rm -f /build/c2hs-0.28.3/tests/bugs/issue-10/Issue10.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-10/Issue10.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-10/Issue10.chi
rm -f /build/c2hs-0.28.3/tests/bugs/issue-10/issue10_c.o
rm -f /build/c2hs-0.28.3/tests/bugs/issue-10/Issue10
c2hs Issue10.chs
which c2hs

Exception: error running: c2hs Issue10.chs
exit status: 1
stderr: c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

True
  Issue #15: [OK]
  Issue #16: [OK]
Did it!
  Issue #19: [OK]
  Issue #20: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-20
rm -f /build/c2hs-0.28.3/tests/bugs/issue-20/Issue20.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-20/Issue20.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-20/Issue20.chi
rm -f /build/c2hs-0.28.3/tests/bugs/issue-20/issue20_c.o
rm -f /build/c2hs-0.28.3/tests/bugs/issue-20/Issue20
c2hs Issue20.chs
which c2hs

Exception: error running: c2hs Issue20.chs
exit status: 1
stderr: c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

abcdef
2
20
  Issue #22: [OK]
H1
  Issue #23: [OK]
  Issue #25: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-25
rm -f /build/c2hs-0.28.3/tests/bugs/issue-25/Issue25.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-25/Issue25.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-25/Issue25.chi
rm -f /build/c2hs-0.28.3/tests/bugs/issue-25/issue25_c.o
rm -f /build/c2hs-0.28.3/tests/bugs/issue-25/Issue25
c2hs Issue25.chs
which c2hs

Exception: error running: c2hs Issue25.chs
exit status: 1
stderr: c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

  Issue #29: [OK]
[1 of 3] Compiling Issue30Aux2      ( Issue30Aux2.hs, Issue30Aux2.o )
[2 of 3] Compiling Issue30Aux1      ( Issue30Aux1.hs, Issue30Aux1.o )
[3 of 3] Compiling Main             ( Issue30.hs, Issue30.o )
Linking Issue30 ...
3
2
4
  Issue #30: [OK]
Enum OK
Pointer 1: 1 1
Pointer 2: 2
Foreign pointer: 3
Foreign newtype pointer: 4
  Issue #31: [OK]
1234
1
523
  Issue #32: [OK]
  Issue #36: [OK]
Enum OK
  Issue #38: [OK]
Test1A=0
Test1B=1
Test1C=5
Test1D=6
AnonA=8
AnonB=9
AnonC=15
AnonD=16
  Issue #43: [OK]
  Issue #44: [OK]
  Issue #45: [OK]
(1,2.5)
  Issue #46: [OK]
  Issue #47: [OK]
0
1
  Issue #51: [OK]
2
0.2
2
0.2
3
0.3
3
0.3
3
0.3
3
0.3
  Issue #54: [OK]
  Issue #60: [OK]
  Issue #62: [OK]
123
3.14
"hello"
  Issue #65: [OK]
  Issue #69: [OK]
  Issue #70: [OK]
Foreign pointer: 3
Foreign pointer: 3
Foreign newtype pointer: 4
Foreign newtype pointer: 4
Allocated struct3
Allocated struct3
Allocated struct4
Allocated struct4
Freeing struct3
Freeing struct4
  Issue #73: [OK]
  Issue #75: [OK]
A=1
B=2
C=2
D=3
  Issue #79: [OK]
  Issue #80: [OK]
  Issue #82: [OK]
  Issue #93: [OK]
  Issue #95: [OK]
  Issue #96: [OK]
[1 of 2] Compiling Issue97A         ( Issue97A.hs, Issue97A.o )
[2 of 2] Compiling Main             ( Issue97.hs, Issue97.o )
Linking Issue97 ...
42
  Issue #97: [OK]
  Issue #98: [OK]
[1 of 2] Compiling Issue103A        ( Issue103A.hs, Issue103A.o )
[2 of 2] Compiling Main             ( Issue103.hs, Issue103.o )
Linking Issue103 ...
1
2
3
  Issue #103: [OK]
True
  Issue #107: [OK]
  Issue #113: [OK]
[8,43,94]
[7,42,93]
  Issue #115: [OK]
  Issue #116: [OK]
[1 of 1] Compiling Main             ( Issue117.hs, Issue117.o )
Linking Issue117 ...
5
  Issue #117: [OK]
[8,43,94]
[7,42,93]
[2,4,8]
[3,9,27]
  Issue #123: [OK]
True
False
  Issue #127: [OK]
[1 of 1] Compiling Main             ( Issue128.hs, Issue128.o )
Linking Issue128 ...
5
3
True
False
10
False
12
True
7
False
8
True
  Issue #128: [OK]
3
3
  Issue #130: [OK]
[1 of 1] Compiling Main             ( Issue131.hs, Issue131.o )
Linking Issue131 ...
5
3
True
False
  Issue #131: [OK]
  Issue #133: [OK]
  Issue #134: [OK]
  Issue #136: [OK]
123
456
789
  Issue #140: [OK]
  Issue #141: [OK]
  Issue #149: [OK]
  Issue #151: [OK]
  Issue #152: [OK]
[1 of 2] Compiling Types            ( Types.hs, Types.o )
[2 of 2] Compiling Main             ( Issue155.hs, Issue155.o )
Linking Issue155 ...
OK
  Issue #155: [OK]
  Issue #180: [OK]
  Issue #192: [OK]
2
5
  Issue #48: [OK]
  Issue #83: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-83
rm -f /build/c2hs-0.28.3/tests/bugs/issue-83/Issue83.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-83/Issue83.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-83/Issue83.chi
rm -f /build/c2hs-0.28.3/tests/bugs/issue-83/issue83_c.o
rm -f /build/c2hs-0.28.3/tests/bugs/issue-83/Issue83
c2hs Issue83.chs
which c2hs

Exception: error running: c2hs Issue83.chs
exit status: 1
stderr: c2hs: C header contains errors:

/nix/store/0jd5ffyrfkxcggsk4ida0aldfp7d8wpk-glibc-2.26-75-dev/include/bits/floatn.h:73: (column 29) [ERROR]  >>> Syntax error !
  The symbol `;' does not fit here.

Unlocked
TST 1: 1234
TST 2: 13 47
TST 3: testing
  Issue #102: [OK]

         Test Cases   Total
 Passed  59           59
 Failed  5            5
 Total   64           64
Test suite test-bugs: FAIL
Test suite logged to: dist/test/c2hs-0.28.3-test-bugs.log
Test suite test-system: RUNNING...
Test suite test-system: PASS
Test suite logged to: dist/test/c2hs-0.28.3-test-system.log
1 of 2 test suites (1 of 2 test cases) passed.
builder for '/nix/store/m24618jswxlckby3ncpvzwxwzikgpgjy-c2hs-0.28.3.drv' failed with exit code 1
error: build of '/nix/store/m24618jswxlckby3ncpvzwxwzikgpgjy-c2hs-0.28.3.drv' failed
deech commented 6 years ago

I am able to reproduce but I haven't had time to investigate why it's happening. _Float128 parses in this context:

extern int __fpclassifyf128 (_Float128 __value) __attribute__ ((__nothrow__ , __leaf__))
 __attribute__ ((__const__));

but not in this one:

typedef __float128 _Float128;

I'll look at it later on this evening. Sorry for the trouble.

jchia commented 6 years ago

@peti Which version of gcc are you using? Are you using a version older than 7? In such cases, the typedef line is compiled:

# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
typedef __float128 _Float128;
# endif

I think this is problematic for pre-7 gcc and C++ mode. https://github.com/visq/language-c/issues/43

peti commented 6 years ago

@jchia, NixOS compiles this code with GHC 6.4.0.

jchia commented 6 years ago

@peti I suspect that under GCC 7 the problem goes away, as elucidated in https://github.com/visq/language-c/issues/43. Would it be easy for you to try GCC 7 and test my theory?

peti commented 6 years ago

Unfortunately, it's not easy test these builds with GCC 7.x. It can be done, but it's very build intensive and I don't think I'll have a chance to do it. :-(

justinchiu commented 6 years ago

@jchia I got the /usr/include/x86_64-linux-gnu/bits/floatn.h:74: (column 29) [ERROR] >>> Syntax error ! The symbol ; does not fit here. error with gcc 5, but it went away with gcc 7 as you expected.

peti commented 6 years ago

For what it's worth, the test suite still fails in c2hs-2.8.3:

[...]

EDIT: It turned out that this failure is unrelated to this issue, so I moved the (large) build log into a new ticket at https://github.com/haskell/c2hs/issues/204.

jchia commented 6 years ago

@peti I think this issue depends on this language-c issue. If that issue is solved, this issue is solved.

krakrjak commented 6 years ago

@peti yeah, but I think for different reasons. It's hard to pick the signal out of your log posting, but I think you have a failure in test case #7.

Your error log:

 Issue #7: [Failed]
ERROR:
Ran commands:
cd /build/c2hs-0.28.3/tests/bugs/issue-7
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.hs
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.chs.h
rm -f /build/c2hs-0.28.3/tests/bugs/issue-7/Issue7.chi
c2hs Issue7.chs
which c2hs

Exception: HUnitFailure (Just (SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "tests/test-bugs.hs", srcLocStartLine = 443, srcLocStartCol = 12, srcLocEndLine = 443, srcLocEndCol = 37})) (Reason "")

My log:

Linking Capital ...
upper C();
lower c();
upper C();

  call_capital (issue #??): [OK]

  Issue #7: [OK]

We need a different issue for your error as it is seemingly unrelated to this issue. Please correct me if I'm misunderstanding your problem @peti.

peti commented 6 years ago

@krakrjak, oh, good catch. Apparently, I misunderstood the nature of the test suite failure. I opened a new ticket #204 for that issue. Thank you.