GNU bug report logs -
#13342
Clang, the FFI, and 8-bit signed integers
Previous Next
Reported by: Peter Teeson <pteeson <at> me.com>
Date: Wed, 2 Jan 2013 23:06:02 UTC
Severity: normal
Tags: notabug
Merged with 13386
Done: ludo <at> gnu.org (Ludovic Courtès)
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Hi Ludo:
MacOS 10.7.5 Intel Dual CPU quad cores
Many thanks for your reply. A nice demo but, no disrespect, maybe not really the issue.
Looking at the generated code from each compiler was going to be my next step after
taking a look at the stack and regs to see what got passed/pushed/popped in the call to test_sum.
Which is why I posted about how can I debug/step through the interpreter.
I still don't understand how to do that even though I read through the manual.
My experiment in building guile with both compilers indicate they both produce the same error.
bad return from expression `(f-sum -1 2000 -30000 40000000000)': expected 39999971999; got 39999972255
I am still of the opinion that it's an interpreter issue and not a compiler one.
I ask for help in confirming my understanding of this scheme code from the file
/test-suite/standalone/test-ffi
;;
;; Multiple int args of differing types
;;
(define f-sum
(pointer->procedure int64 (dynamic-func "test_ffi_sum" lib)
(list int8 int16 int32 int64)))
(test (f-sum -1 2000 -30000 40000000000) ;; This calls the c function f-sum
(+ -1 2000 -30000 40000000000)) ;; This executes the scheme interpreter to do the sum
Is my understanding correct??????
If so please explain to me how the interpreter knows that the -1 in this expression is an int8?
My suspicion is that it thinks it's an int16 and that's why we see the difference!!
I don't know how to pass an int8 of -1 to the interpreter in REPL mode.
Otherwise I'd try that.
============= from Terminal REPL session =============
Gandalf:guile-2.0.7 pteeson$ guile
GNU Guile 2.0.7
<snipped comments>
scheme@(guile-user)> (+ -1 2000 -30000 40000000000)
$1 = 39999971999
scheme@(guile-user)> ,q
which matches the fail message value.
bad return from expression `(f-sum -1 2000 -30000 40000000000)': expected 39999971999; got 39999972255
================= from http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html ===========
Limits of exact-width integer types
Minimum values of exact-width signed integer types:
{INTN_MIN}
Exactly -(2 N-1)
Maximum values of exact-width signed integer types:
{INTN_MAX}
Exactly 2N-1 -1
==========================================
[Message part 2 (text/html, inline)]
This bug report was last modified 12 years and 110 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.