Subject: bug#10015: Guile-2.0.3: test-ffi fails

From: Andy Wingo <[email-masked]>
Date: Fri, 18 Nov 2011 07:38:23 +0100

On Thu 17 Nov 2011 15:32, Hans Aberg <[email-masked]> writes:

> On 16 Nov 2011, at 20:30, Andy Wingo wrote:
>
>>> With guile-2.0.3, OS X 10.7.2, Xcode 4.2,
>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1, 'make check' fails on
>>> test-ffi. Here, libffi-3.0.9 is used; libffi-3.0.10 does not compile
>>> with the same setup.
>> 
>> How does it fail? 
>
> bad return from expression `(f-sum -1 2000 -30000 40000000000)': expected 39999971999; got 39999972255

Interesting.  This is off by 256.  It seems that the -1 is being
interpreted as an unsigned int8, not a signed int8.  But the bit
patterns are correct.  I think this is either a configuration bug in
Guile, or an llvm bug.

Transcript:

    wingo@badger:~/src/guile$ meta/gdb-uninstalled-guile
    GNU gdb (GDB) 7.3-debian
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    Reading symbols from /home/wingo/src/guile/libguile/.libs/lt-guile...done.
    (gdb) r
    Starting program: /home/wingo/src/guile/libguile/.libs/lt-guile 
    [Thread debugging using libthread_db enabled]
    [New Thread 0x7ffff554b700 (LWP 19411)]
    GNU Guile 2.0.3
    Copyright (C) 1995-2011 Free Software Foundation, Inc.

    Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
    This program is free software, and you are welcome to redistribute it
    under certain conditions; type `,show c' for details.

    Enter `,help' for help.
    scheme@(guile-user)> (dynamic-link "./test-suite/standalone/libtest-ffi")
    $1 = #<dynamic-object "./test-suite/standalone/libtest-ffi">
    scheme@(guile-user)> (dynamic-pointer "test_ffi_sum" $1)
    $2 = #<pointer 0x7ffff49cdf20>
    scheme@(guile-user)> (use-modules (system foreign))
    scheme@(guile-user)> (define f-sum (pointer->procedure int64 $2 (list int8 int16 int32 int64)))
    scheme@(guile-user)> (f-sum -1 2000 -30000 40000000000)
    $3 = 39999971999
    scheme@(guile-user)> 
    Program received signal SIGINT, Interrupt.
    0x00007ffff739417d in read () at ../sysdeps/unix/syscall-template.S:82
    82	../sysdeps/unix/syscall-template.S: No such file or directory.
    	in ../sysdeps/unix/syscall-template.S
    (gdb) b test_ffi_sum
    Breakpoint 1 at 0x7ffff49cdf20: file test-ffi-lib.c, line 193.
    (gdb) c
    Continuing.
    (f-sum -1 2000 -30000 40000000000)

    Breakpoint 1, test_ffi_sum (a=-1 '\377', b=2000, c=-30000, d=40000000000) at test-ffi-lib.c:193
    193	  return d + c + b + a;
    (gdb) 

You can see at this breakpoint that we would get the incorrect result
*only* if the type of `a' were actually unsigned char rather than signed
char.  Can you give the output of `grep scm_t_int8 libguile/scmconfig.h'
?

Thanks,

Andy
-- 
http://wingolog.org/