guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/04: Allow equality between arrays of vu8 and u8


From: Andy Wingo
Subject: [Guile-commits] 01/04: Allow equality between arrays of vu8 and u8
Date: Sat, 16 Nov 2019 08:35:14 -0500 (EST)

wingo pushed a commit to branch wip-r7rs
in repository guile.

commit aabea7394a1a809177c94fd0548b69479a1a0629
Author: Andy Wingo <address@hidden>
Date:   Sat Nov 16 09:45:41 2019 +0100

    Allow equality between arrays of vu8 and u8
    
    * libguile/array-map.c (scm_array_equal_p): Treat vu8 and u8 arrays as
      equivalent.
---
 libguile/array-map.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libguile/array-map.c b/libguile/array-map.c
index a76d8fc..6460a24 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -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));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]