Opened 9 years ago

Last modified 22 months ago

#3238 new bug

CInt FFI exports do not use C int in _stub.h header file

Reported by: duncan Owned by:
Priority: lowest Milestone:
Component: Compiler (FFI) Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Ideally if I have a FFI export like this:

foreign export ccall foo :: CInt -> CInt

Then the _stub.h file should look like:

#ifdef __cplusplus
extern "C" {
#endif
extern int foo(int a1);
#ifdef __cplusplus
}
#endif

But it actually looks like:

#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt32 foo(HsInt32 a1);
#ifdef __cplusplus
}
#endif

So what am I complaining about? Well, I specified an FFI export mentioning only C types but the header file uses HsInt32. I'd prefer an actual C int. I also do not want to #include "HsFFI.h" because then when using gcc to compile C code that uses this C function I have to know the full path to ghc's include dir so that gcc can find HsFFI.h.

The point here is about exporting C functions and trying to integrate into some bigger build system that will be using gcc not ghc to compile C code and link the system together.

I realise this isn't trivial to fix, because GHC defines things like CInt as newtypes for primitive types of known widths (like Int32). However, perhaps there should be a known mapping, even though within the Haskell world CInt is just a newtype. The set of FFI types is already hard-wired into the compiler (with some rules to allow newtype unwrapping etc) so why not extend that hard-wired knowledge to include the real C type (not just the ABI width). This only needs to be used when generating the export header files. An extra bit in the mapping can indicate if it's a C primitive type or if the export header file has to #include "HsFFI.h".

This ticket is related to #2926 and the solution is almost certainly the same, but the motivation for this problem is slightly different.

Change History (13)

comment:1 Changed 9 years ago by igloo

difficulty: Unknown
Milestone: 6.12 branch

comment:2 Changed 8 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:3 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:4 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:5 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:6 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:7 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:8 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:9 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:10 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:11 Changed 3 years ago by thoughtpolice

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:12 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:13 Changed 22 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.