From c4aca3b9da9e7777f84efcd304990ad78b883f07 Mon Sep 17 00:00:00 2001 From: Daniel Llorens Date: Thu, 6 Feb 2014 11:17:47 +0100 Subject: [PATCH] Don't use generalized-vector functions in uniform.c * libguile/uniform.c (scm_is_uniform_vector): Replace scm_is_generalized_vector and scm_generalized_vector_get_handle by scm_is_array and manual rank check. (scm_c_uniform_vector_length): Use scm_c_array_length. (scm_c_uniform_vector_ref): Use scm_c_array_ref_1. (scm_c_uniform_vector_set): Use scm_c_array_set_1_x. (scm_uniform_vector_writable_elements): Use scm_array_get_handle, and assert that the rank is 1. * test-suite/test/arrays.test: Rename the uniform-vector-ref block to uniform-vector. Exercise uniform-vector-length and shared arrays remaining uniform. Modifications by Andy Wingo . --- libguile/uniform.c | 27 ++++++++++++++------------- test-suite/tests/arrays.test | 24 ++++++++++++++++++++---- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/libguile/uniform.c b/libguile/uniform.c index f8cd2d37b..e81f5046a 100644 --- a/libguile/uniform.c +++ b/libguile/uniform.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010, 2013 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010, 2013, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -87,10 +87,11 @@ scm_is_uniform_vector (SCM obj) scm_t_array_handle h; int ret = 0; - if (scm_is_generalized_vector (obj)) + if (scm_is_array (obj)) { - scm_generalized_vector_get_handle (obj, &h); - ret = SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h.element_type); + scm_array_get_handle (obj, &h); + ret = (scm_array_handle_rank (&h) == 1 + && SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h.element_type)); scm_array_handle_release (&h); } return ret; @@ -102,8 +103,7 @@ scm_c_uniform_vector_length (SCM uvec) if (!scm_is_uniform_vector (uvec)) scm_wrong_type_arg_msg ("uniform-vector-length", 1, uvec, "uniform vector"); - - return scm_c_generalized_vector_length (uvec); + return scm_c_array_length (uvec); } SCM_DEFINE (scm_uniform_vector_p, "uniform-vector?", 1, 0, 0, @@ -169,11 +169,11 @@ SCM_DEFINE (scm_uniform_vector_element_size, "uniform-vector-element-size", 1, 0 #undef FUNC_NAME SCM -scm_c_uniform_vector_ref (SCM v, size_t idx) +scm_c_uniform_vector_ref (SCM v, size_t pos) { if (!scm_is_uniform_vector (v)) scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); - return scm_c_generalized_vector_ref (v, idx); + return scm_c_array_ref_1 (v, pos); } SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0, @@ -187,11 +187,11 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0, #undef FUNC_NAME void -scm_c_uniform_vector_set_x (SCM v, size_t idx, SCM val) +scm_c_uniform_vector_set_x (SCM v, size_t pos, SCM val) { if (!scm_is_uniform_vector (v)) scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); - scm_c_generalized_vector_set_x (v, idx, val); + scm_c_array_set_1_x (v, val, pos); } SCM_DEFINE (scm_uniform_vector_set_x, "uniform-vector-set!", 3, 0, 0, @@ -225,13 +225,14 @@ scm_uniform_vector_elements (SCM uvec, } void * -scm_uniform_vector_writable_elements (SCM uvec, +scm_uniform_vector_writable_elements (SCM uvec, scm_t_array_handle *h, size_t *lenp, ssize_t *incp) { void *ret; - scm_generalized_vector_get_handle (uvec, h); - /* FIXME nonlocal exit */ + scm_array_get_handle (uvec, h); + if (scm_array_handle_rank (h) != 1) + scm_wrong_type_arg_msg (0, SCM_ARG1, uvec, "uniform vector"); ret = scm_array_handle_uniform_writable_elements (h); if (lenp) { diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test index 0b3d57ca2..9d8637122 100644 --- a/test-suite/tests/arrays.test +++ b/test-suite/tests/arrays.test @@ -574,12 +574,12 @@ (eqv? 8 (array-ref s2 2)))))) ;;; -;;; uniform-vector-ref +;;; uniform-vector ;;; -(with-test-prefix "uniform-vector-ref" +(with-test-prefix "uniform-vector" - (with-test-prefix "byte" + (with-test-prefix "uniform-vector-ref byte" (let ((a (make-s8vector 1))) @@ -594,7 +594,23 @@ (pass-if "-128" (begin (array-set! a -128 0) - (= -128 (uniform-vector-ref a 0))))))) + (= -128 (uniform-vector-ref a 0)))))) + + (with-test-prefix "shared with rank 1 remain uniform vectors" + + (let ((a #f64(1 2 3 4))) + + (pass-if "change offset" + (let ((b (make-shared-array a (lambda (i) (list (+ i 1))) 3))) + (and (uniform-vector? b) + (= 3 (uniform-vector-length b)) + (array-equal? b #f64(2 3 4))))) + + (pass-if "change stride" + (let ((c (make-shared-array a (lambda (i) (list (* i 2))) 2))) + (and (uniform-vector? c) + (= 2 (uniform-vector-length c)) + (array-equal? c #f64(1 3)))))))) ;;; ;;; syntax