GHC FFI Return Type Bug

Julian Seward (Intl Vendor) v-julsew@microsoft.com
Mon, 6 Aug 2001 02:57:47 -0700


Hmm, we're looking at this.  However, I don't really know what
C is or is not supposed to do here.  Given

char fooble ( ... )
{
   return 'z';
}

on an x86, 'z' will be returned at the lowest 8 bits in %eax.
What I don't know is, is the C compiler obliged to clear the
upper 24 bits of %eax, or does that onus fall on the callee?
Also, I don't even know where to look for the specification of
details of the C calling conventions.  Anyone got a clue?

J

| -----Original Message-----
| From: Ashley Yakeley [mailto:ashley@semantic.org]=20
| Sent: Monday, August 06, 2001 1:34 AM
| To: GHC List
| Subject: GHC FFI Return Type Bug
|=20
|=20
| Has anyone else come across this? I've only tried this with=20
| Word8 but I=20
| suspect this is a problem with all return types smaller than=20
| four bytes.
|=20
| I've entered this as GHC bug #448104.=20
| <http://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D4481
| 04&group_id=3D8
| 032&atid=3D108032>
|=20
| Here's the C code:
|=20
| extern "C"
| 	{
| 	unsigned char foo();
| 	}
|=20
| inline void use(const char* s)
| 	{
| 	}
|=20
| unsigned char foo()
| 	{
| 	const char* s =3D "";
| 	use(s);
| 	return 0;
| 	}
|=20
| ...and the Haskell looks something like this:
|=20
|  foreign import foo :: IO Word8
|=20
| do {
|  w8 <- foo;
|  putStrLn (show (w8 :: Word8));
| }
|=20
| ...and the result is this:
| 1074803712
|=20
| Kind of an unusual Word8 value! But note that the low byte of=20
| this value=20
| is zero.
|=20
| My setup:
|=20
| $ ghc -v
| Glasgow Haskell Compiler, Version 5.00, for Haskell 98,=20
| compiled by GHC=20
| version 5.00
| Using package config file: /usr/lib/ghc-5.00/package.conf
| Hsc static flags: -static -fignore-interface-pragmas=20
| -fomit-interface-pragmas -fdo-lambda-eta-expansion -flet-no-escape
|=20
| $ uname -a
| Linux server 2.2.19pre17 #1 Tue Mar 13 22:37:59 EST 2001 i686 unknown
|=20
|=20
| --=20
| Ashley Yakeley, Seattle WA
|=20
|=20
| _______________________________________________
| Glasgow-haskell-users mailing list=20
| Glasgow-haskell-users@haskell.org=20
| http://www.haskell.org/mailman/listinfo/glasgo| w-haskell-users
|=20