bug#13342: [PARTIALLY SOLVED] bug#13342: Errors trying to build Guile 2.0.7

2013-01-08 Thread Peter Teeson
Hi Ludo:
I think the reason that we get this error is that the "a" argument is declared 
to be only 8 bits wide
but is passed in as -1 which is correctly represented as 0x

However an 8-bit representation is 0xFF which is only 255.

Here is how I tracked it down:
(0) Took the printf's from my test program and placed them in 

scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
  scm_t_int32 c, scm_t_int64 d);
scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
  scm_t_int32 c, scm_t_int64 d)
{
scm_t_int64 sum;
printf("scm_t_int64 d %" "ll" "d" " %#llX \n", d,d);
printf("scm_t_int32 c %" "d" " %#X \n", c,c);
printf("scm_t_int16 b %" "hd" " %#X \n", b,b);
printf("scm_t_int8 a %" "hh" "d" " %#X \n", a,a);
sum = d + c + b + a;
printf("scm_t_int64 sum %" "ll" "d" " %#llX \n", sum,sum);

a = -1; //  NOTE:re-assign of a
printf("scm_t_int16 a %" "hd" " %#X \n", a,a);

return d + c + b + a;
}

(1) Did make and make check with the following result

scm_t_int64 d 400 0X9502F9000 
scm_t_int32 c -3 0X8AD0 
scm_t_int16 b 2000 0X7D0 
scm_t_int8 a -1 0XFF 
scm_t_int64 sum 3972255 0X9502F239F 
scm_t_int16 a -1 0X 
PASS: test-ffi


(2) Observe that the test passed. 
So I think my original suspicion seems to have been confirmed.

I do not know where to go from here but await your further instructions.

respect

Peter


bug#13386: Fwd: bug#13342: Errors trying to build Guile 2.0.7

2013-01-08 Thread Peter Teeson


Begin forwarded message:

> From: Peter Teeson 
> Subject: Re: bug#13342: Errors trying to build Guile 2.0.7
> Date: 7 January, 2013 8:21:59 PM EST
> To: Ludovic Courtès 
> 
> Hi Ludo:
> 
> On 2013-01-04, at 12:23 PM, Ludovic Courtès wrote:
> bad return from expression `(f-sum -1 2000 -3 400)': expected 
> 3971999; got 3972255
> FAIL: test-ffi
 
 This is a known issue when building Guile with LLVM/Clang:
 
 http://bugs.gnu.org/10015
 http://bugs.gnu.org/10681
 
 It would be great if you could investigate.
> 
> Here is the result of my investigation - do you agree?
> My hypothesis is that the scheme interpreter is not calculating the sum 
> correctly based on the following:
> 
> (0) First observe this
> "In Apple's version of GCC, both cc and gcc are actually symbolic links to 
> the llvm-gcc compiler.  Similarly, c++ and g++ are links to llvm-g++."
> 
> (1) Also we note that 3972255 - 3971999 = 256!
> 
> (2) This program
> //
> //  main.c
> //  testffi
> //
> //  Created by Peter Teeson on 13-01-07.
> //  Copyright (c) 2013 PHT Software. All rights reserved.
> //
> 
> #include 
> #include 
> 
> int64_t test_ffi_sum (int8_t a, int16_t b,
>   int32_t c, int64_t d);
> int64_t test_ffi_sum (int8_t a, int16_t b,
>   int32_t c, int64_t d)
> {
> printf("int64 d %" PRId64 " %#llX \n", d,d);
> printf("int32 c %" PRId32 " %#X \n", c,c);
> printf("int16 b %" PRId16 " %#X \n", b,b);
> printf("int08 a %" PRId8 " %#X \n", a,a);
> 
> int64_t sum = d + c + b + a;
> printf("int64 sum %" PRId64 " %#llX \n", sum,sum);
> 
> return sum;
> }
> int main(int argc, const char * argv[])
> {
> test_ffi_sum(-1, 2000, -3, 400);
> return 0;
> }
> 
> (3) produces this output
> 
> int64 d 400 0X9502F9000 
> int32 c -3 0X8AD0 
> int16 b 2000 0X7D0 
> int08 a -1 0X 
> int64 sum 3971999 0X9502F229F 
> 
> (4) This function in  /guile-2.0.7/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 -3 400)
>   (+ -1 2000 -3 400))
> 
> might be the culprit and I am guessing that it is this expression
> 
> (+ -1 2000 -3 400) 
> 
> which the scheme interpreter is calculating incorrectly. Probably related to 
> -1;
> 
> Since I am not familiar with the scheme/guile language I can't go any further 
> than this without help.
> Let me know if I can do more.
> 
> respect…..
> 
> Peter



bug#13342: Errors trying to build Guile 2.0.7 [PARTIALLY SOLVED]

2013-01-08 Thread Peter Teeson
Hi Ludo:

I believe my conjecture that -1 was correct based on the following:

(0) I took the printf statements from my test program and placed them in 
test-ffi-sum:

scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
  scm_t_int32 c, scm_t_int64 d);
scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
  scm_t_int32 c, scm_t_int64 d)
{
scm_t_int64 sum;
printf("scm_t_int64 d %" "ll" "d" " %#llX \n", d,d);
printf("scm_t_int32 c %" "d" " %#X \n", c,c);
printf("scm_t_int16 b %" "hd" " %#X \n", b,b);
printf("scm_t_int8 a %" "hh" "d" " %#X \n", a,a);

sum = d + c + b + a;
printf("scm_t_int64 sum %" "ll" "d" " %#llX \n", sum,sum);

a = -1; // NOTE re-assinging of a!
printf("scm_t_int16 a %" "hd" " %#X \n", a,a);

return d + c + b + a;
}

(1) Ran make 

Making all in standalone
make  all-am
  CC   libtest_ffi_la-test-ffi-lib.lo
  CCLD libtest-ffi.la

and then make check

scm_t_int64 d 400 0X9502F9000 
scm_t_int32 c -3 0X8AD0 
scm_t_int16 b 2000 0X7D0 
scm_t_int8 a -1 0XFF 
scm_t_int64 sum 3972255 0X9502F239F 
scm_t_int16 a -1 0X 
PASS: test-ffi

(2) Since scm_t_int8 is only 8 bits wide it's maximum value is 0xFF <=> 255
Reassigning "a" to be -1 allowed it to pass the test.

(3) Therefore I conclude that this is why the test fails (correctly IMHO).
You can only get a litre of milk into a litre jar!

(4) Where do we go from here?

respect

Peter