summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2019-11-16 09:45:41 +0100
committerAndy Wingo <wingo@pobox.com>2019-11-16 14:34:53 +0100
commitaabea7394a1a809177c94fd0548b69479a1a0629 (patch)
tree600f8ab0cd0865f1b381bb3e1af1ea8d102ad113
parent4b2c512b94bcdcfc2964f3b72da646ac95e11e82 (diff)
downloadguile-aabea7394a1a809177c94fd0548b69479a1a0629.tar.gz
Allow equality between arrays of vu8 and u8
* libguile/array-map.c (scm_array_equal_p): Treat vu8 and u8 arrays as equivalent.
-rw-r--r--libguile/array-map.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/libguile/array-map.c b/libguile/array-map.c
index a76d8fc16..6460a2483 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));