Allow equality between arrays of vu8 and u8
authorAndy Wingo <wingo@pobox.com>
Sat, 16 Nov 2019 08:45:41 +0000 (09:45 +0100)
committerAndy Wingo <wingo@pobox.com>
Sat, 16 Nov 2019 13:34:53 +0000 (14:34 +0100)
* libguile/array-map.c (scm_array_equal_p): Treat vu8 and u8 arrays as
  equivalent.

libguile/array-map.c

index a76d8fc1667f76453cd4048aec4f7ee654857b12..6460a2483da65399b54842d6c54922e0e77d2426 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 1996,1998,2000-2001,2004-2006,2008-2015,2018
+/* Copyright 1996,1998,2000-2001,2004-2006,2008-2015,2018-2019
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -614,8 +614,20 @@ scm_array_equal_p (SCM x, SCM y)
   scm_array_get_handle (x, &hx);
   scm_array_get_handle (y, &hy);
 
-  res = scm_from_bool (hx.ndims == hy.ndims
-                       && hx.element_type == hy.element_type);
+  scm_t_array_element_type t1 = hx.element_type;
+  scm_t_array_element_type t2 = hy.element_type;
+
+  /* R6RS and Guile mostly use #vu8(...) as the literal syntax for
+     bytevectors, but R7RS uses #u8.  To allow R7RS users to re-use the
+     various routines implemented on bytevectors which return vu8-tagged
+     values and to also be able to do (equal? #u8(1 2 3) (bytevector 1 2
+     3)), we allow equality comparisons between vu8 and u8.  */
+  if (t1 == SCM_ARRAY_ELEMENT_TYPE_VU8)
+    t1 = SCM_ARRAY_ELEMENT_TYPE_U8;
+  if (t2 == SCM_ARRAY_ELEMENT_TYPE_VU8)
+    t2 = SCM_ARRAY_ELEMENT_TYPE_U8;
+
+  res = scm_from_bool (hx.ndims == hy.ndims && t1 == t2);
 
   if (scm_is_true (res))
     res = scm_from_bool (array_compare (&hx, &hy, 0, 0, 0));