Subject: bug#10681: GNU Guile 2.0.5 released

From: Mark H Weaver <[email-masked]>
Date: Tue, 31 Jan 2012 20:42:55 -0500

Hans Aberg <[email-masked]> writes:
> With gcc-4.7.0 (from SVN), the test-ffi test now passes (libffi from
> GIT)

Excellent!  I guess that this was a libffi bug.

> but I get three other failures.
>
> The compiler that is normally used on the system, is llvm-gcc-4.2, and
> its compile is still running.

Please let us know the results of 'make check' when compiling with
llvm-gcc-4.2.  I'm especially curious to hear whether the bytevector
tests fail with that compiler as well.

> Running bytevectors.test
> FAIL: bytevectors.test: 2.3 Operations on Bytes and Octets: bytevector-sint-ref [small] (eval)
> FAIL: bytevectors.test: 2.3 Operations on Bytes and Octets: bytevector-sint-ref [small] (compile)

In the directory where you built using GCC-4.7.0 (SVN), can you please
apply the following 'patch for bytevectors.test' and then, from the
guile-2.0.5 directory, run:

  ./check-guile bytevectors.test

and show us the output?

This is a shot in the dark, but I've also attached a patch that _might_
fix the bytevector problem.  After applying it, it should be sufficient
to simply run "make" again, and it shouldn't take long.  Let us know!

     Thanks,
       Mark

diff --git a/test-suite/tests/bytevectors.test b/test-suite/tests/bytevectors.test
index 3007434..b652935 100644
--- a/test-suite/tests/bytevectors.test
+++ b/test-suite/tests/bytevectors.test
@@ -114,10 +114,14 @@
               #xfffffffffffffffffffffffffffffffd)))
 
   (pass-if "bytevector-sint-ref [small]"
-    (let ((b (u8-list->bytevector '(#xff #xf0 #xff))))
-      (equal? (bytevector-sint-ref b 0 (endianness big) 2)
-              (bytevector-sint-ref b 1 (endianness little) 2)
-              -16)))
+    (let* ((b (u8-list->bytevector '(#xff #xf0 #xff)))
+           (be-result (bytevector-sint-ref b 0 (endianness big) 2))
+           (le-result (bytevector-sint-ref b 1 (endianness little) 2)))
+      (or (equal? be-result le-result -16)
+          (begin (format (current-error-port)
+                         "bytevector-sint-ref [small] failure: ~S ~S~%"
+                         be-result le-result)
+                 #f))))
 
   (pass-if "bytevector-sint-ref [large]"
     (let ((b (make-bytevector 50)))
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index fff5355..8574a36 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -103,7 +103,7 @@
                                                                 \
     memcpy (&c_result, &c_bv[c_index], (_len) / 8);             \
     if (!scm_is_eq (endianness, scm_i_native_endianness))       \
-      c_result = INT_SWAP (_len) (c_result);                    \
+      c_result = (INT_TYPE (_len, _sign)) INT_SWAP (_len) ((INT_TYPE (_len, unsigned)) c_result); \
                                                                 \
     result = SCM_I_MAKINUM (c_result);                          \
   }                                                             \
@@ -143,7 +143,7 @@
 								\
     c_value_short = (INT_TYPE (_len, _sign)) c_value;		\
     if (!scm_is_eq (endianness, scm_i_native_endianness))       \
-      c_value_short = INT_SWAP (_len) (c_value_short);		\
+      c_value_short = (INT_TYPE (_len, _sign)) INT_SWAP (_len) ((INT_TYPE (_len, unsigned)) c_value_short);  \
 								\
     memcpy (&c_bv[c_index], &c_value_short, (_len) / 8);	\
   }								\
@@ -918,7 +918,7 @@ bytevector_large_set (char *c_bv, size_t c_size, int signed_p,
 	    INT_TYPE (16, _sign)  c_value16;				\
 	    memcpy (&c_value16, c_bv, 2);				\
 	    if (swap)							\
-	      value = (INT_TYPE (16, _sign)) bswap_16 (c_value16);	\
+	      value = (INT_TYPE (16, _sign)) bswap_16 ((scm_t_uint16) c_value16); \
 	    else							\
 	      value = c_value16;					\
 	  }								\
@@ -981,7 +981,7 @@ bytevector_unsigned_ref (const char *c_bv, size_t c_size, SCM endianness)
 	      swap = !scm_is_eq (endianness, scm_i_native_endianness);	\
 									\
 	      if (swap)							\
-		c_value16 = (INT_TYPE (16, _sign)) bswap_16 (c_value);	\
+		c_value16 = (INT_TYPE (16, _sign)) bswap_16 ((scm_t_uint16) c_value); \
 	      else							\
 		c_value16 = c_value;					\
 									\