guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 03/27: Require vector argument to scm_vector_elements, s


From: Daniel Llorens
Subject: [Guile-commits] 03/27: Require vector argument to scm_vector_elements, scm_vector_writable_elements
Date: Thu, 20 Feb 2020 03:45:38 -0500 (EST)

lloda pushed a commit to branch wip-vector-cleanup
in repository guile.

commit d7bee970a7b3d663257f0bacf4f3e2cd9e948124
Author: Daniel Llorens <address@hidden>
AuthorDate: Mon Feb 3 13:04:13 2020 +0100

    Require vector argument to scm_vector_elements, scm_vector_writable_elements
    
    * libguile/vectors.c (scm_vector_elements, scm_vector_writable_elements): As
      stated.
    * libguile/sort.c: Fix usage of scm_vector_elements on possibly non-vector
      array.
    * doc/ref/api-data.texi (scm_vector_elements): Remove mention of non-vector
      arrays.
---
 doc/ref/api-data.texi |  5 +----
 libguile/sort.c       | 21 +++++++++++----------
 libguile/vectors.c    | 32 ++++++++++++++++++++------------
 3 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index a6b09c4..750f711 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -6463,10 +6463,7 @@ handle must eventually be released with
 
 The variables pointed to by @var{lenp} and @var{incp} are filled with
 the number of elements of the vector and the increment (number of
-elements) between successive elements, respectively.  Successive
-elements of @var{vec} need not be contiguous in their underlying
-``root vector'' returned here; hence the increment is not necessarily
-equal to 1 and may well be negative too (@pxref{Shared Arrays}).
+elements) between successive elements, respectively.  
 
 The following example shows the typical way to use this function.  It
 creates a list of all elements of @var{vec} (in reverse order).
diff --git a/libguile/sort.c b/libguile/sort.c
index 05ecee5..0827ebe 100644
--- a/libguile/sort.c
+++ b/libguile/sort.c
@@ -562,22 +562,23 @@ SCM_DEFINE (scm_stable_sort_x, "stable-sort!", 2, 0, 0,
     }
   else if (scm_is_array (items) && 1 == scm_c_array_rank (items))
     {
-      scm_t_array_handle temp_handle, vec_handle;
-      SCM temp, *temp_elts, *vec_elts;
-      size_t len;
-      ssize_t inc;
-
-      vec_elts = scm_vector_writable_elements (items, &vec_handle,
-                                              &len, &inc);
+      scm_t_array_handle vec_handle;
+      scm_array_get_handle (items, &vec_handle);
+      
+      SCM *vec_elts = scm_array_handle_writable_elements (&vec_handle);
+      scm_t_array_dim *vec_dim = scm_array_handle_dims (&vec_handle);
+      size_t len = vec_dim->ubnd + 1 - vec_dim->lbnd;
+      ssize_t inc = vec_dim->inc;
+      
       if (len == 0)
         {
           scm_array_handle_release (&vec_handle);
           return items;
         }
 
-      temp = scm_c_make_vector (len, SCM_UNDEFINED);
-      temp_elts = scm_vector_writable_elements (temp, &temp_handle,
-                                               NULL, NULL);
+      SCM temp = scm_c_make_vector (len, SCM_UNDEFINED);
+      scm_t_array_handle temp_handle;
+      SCM *temp_elts = scm_vector_writable_elements (temp, &temp_handle, NULL, 
NULL);
 
       scm_merge_vector_step (vec_elts, temp_elts, less, 0, len-1, inc);
 
diff --git a/libguile/vectors.c b/libguile/vectors.c
index 62a6428..c837d82 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -64,34 +64,42 @@ scm_is_simple_vector (SCM obj)
 const SCM *
 scm_vector_elements (SCM vec, scm_t_array_handle *h,
                     size_t *lenp, ssize_t *incp)
+#define FUNC_NAME "scm_vector_elements"
 {
+  SCM_VALIDATE_VECTOR (1, vec);
   scm_array_get_handle (vec, h);
-  if (1 != scm_array_handle_rank (h))
-    {
-      scm_array_handle_release (h);
-      scm_wrong_type_arg_msg (NULL, 0, vec, "rank 1 array of Scheme values");
-    }
   
   if (lenp)
     {
       scm_t_array_dim *dim = scm_array_handle_dims (h);
       *lenp = dim->ubnd - dim->lbnd + 1;
-      *incp = dim->inc;
     }
+  if (incp)
+    *incp = 1;
+  
   return scm_array_handle_elements (h);
 }
+#undef FUNC_NAME
 
 SCM *
 scm_vector_writable_elements (SCM vec, scm_t_array_handle *h,
                              size_t *lenp, ssize_t *incp)
+#define FUNC_NAME "scm_vector_writable_elements"
 {
-  const SCM *ret = scm_vector_elements (vec, h, lenp, incp);
-
-  if (h->writable_elements != h->elements)
-    scm_wrong_type_arg_msg (NULL, 0, vec, "mutable vector");
-
-  return (SCM *) ret;
+  SCM_VALIDATE_MUTABLE_VECTOR (1, vec);
+  scm_array_get_handle (vec, h);
+  
+  if (lenp)
+    {
+      scm_t_array_dim *dim = scm_array_handle_dims (h);
+      *lenp = dim->ubnd - dim->lbnd + 1;
+    }
+  if (incp)
+    *incp = 1;
+  
+  return scm_array_handle_writable_elements (h);
 }
+#undef FUNC_NAME
 
 SCM_DEFINE (scm_vector_p, "vector?", 1, 0, 0, 
            (SCM obj),



reply via email to

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