guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 01/01: Deprecate using vector->list, vector-copy on arra


From: Daniel Llorens
Subject: [Guile-commits] 01/01: Deprecate using vector->list, vector-copy on arrays
Date: Thu, 5 Aug 2021 06:35:25 -0400 (EDT)

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

commit 81f12bf86eed96c7ecdf6c9ce40d5abe6c729457
Author: Daniel Llorens <lloda@sarc.name>
AuthorDate: Thu Aug 5 12:33:34 2021 +0200

    Deprecate using vector->list, vector-copy on arrays
    
    * libguile/vectors.c (vector-copy, vector->list): As stated. Provide
      array free implementation for the supported case.
---
 libguile/vectors.c | 92 +++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 60 insertions(+), 32 deletions(-)

diff --git a/libguile/vectors.c b/libguile/vectors.c
index 0f1e608..4b701f7 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -24,19 +24,20 @@
 # include <config.h>
 #endif
 
+#include <string.h>
+
 #include "array-handle.h"
 #include "bdw-gc.h"
 #include "boolean.h"
+#include "deprecation.h"
 #include "eq.h"
+#include "generalized-vectors.h"
 #include "gsubr.h"
 #include "list.h"
 #include "numbers.h"
 #include "pairs.h"
 #include "vectors.h"
 
-#include "generalized-vectors.h"
-
-
 
 
 #define VECTOR_MAX_LENGTH (SCM_T_BITS_MAX >> 8)
@@ -269,29 +270,41 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
            "Return a copy of @var{vec}.")
 #define FUNC_NAME s_scm_vector_copy
 {
-  scm_t_array_handle handle;
-  size_t i, len;
-  ssize_t inc;
-  const SCM *src;
-  SCM result, *dst;
-
-  src = scm_vector_elements (vec, &handle, &len, &inc);
-
-  result = make_vector (len);
-  dst = SCM_I_VECTOR_WELTS (result);
-  for (i = 0; i < len; i++, src += inc)
-    dst[i] = *src;
-
-  scm_array_handle_release (&handle);
-
+  SCM result;
+  if (SCM_I_IS_VECTOR (vec))
+    {
+      size_t len = SCM_I_VECTOR_LENGTH (vec);
+      result = make_vector (len);
+      memcpy (SCM_I_VECTOR_WELTS (result), SCM_I_VECTOR_ELTS (vec), len * 
sizeof(SCM));
+    }
+  else
+    {
+      scm_t_array_handle handle;
+      size_t i, len;
+      ssize_t inc;
+      const SCM *src;
+      SCM *dst;
+
+      src = scm_vector_elements (vec, &handle, &len, &inc);
+      scm_c_issue_deprecation_warning
+        ("Using vector-copy on arrays is deprecated.  "
+         "Use array-copy instead.");
+
+      result = make_vector (len);
+      dst = SCM_I_VECTOR_WELTS (result);
+      for (i = 0; i < len; i++, src += inc)
+        dst[i] = *src;
+
+      scm_array_handle_release (&handle);
+    }
   return result;
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0, 
-           (SCM v),
-           "Return a newly allocated list composed of the elements of 
@var{v}.\n"
+           (SCM vec),
+           "Return a newly allocated list composed of the elements of 
@var{vec}.\n"
            "\n"
            "@lisp\n"
            "(vector->list '#(dah dah didah)) @result{}  (dah dah didah)\n"
@@ -300,18 +313,33 @@ SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
 #define FUNC_NAME s_scm_vector_to_list
 {
   SCM res = SCM_EOL;
-  const SCM *data;
-  scm_t_array_handle handle;
-  size_t i, count, len;
-  ssize_t inc;
-
-  data = scm_vector_elements (v, &handle, &len, &inc);
-  for (i = (len - 1) * inc, count = 0;
-       count < len;
-       i -= inc, count++)
-    res = scm_cons (data[i], res);
-
-  scm_array_handle_release (&handle);
+
+  if (SCM_I_IS_VECTOR (vec))
+    {
+      ssize_t len = SCM_I_VECTOR_LENGTH (vec);
+      const SCM * data = SCM_I_VECTOR_ELTS (vec);
+      for (ssize_t i = len-1; i >= 0; --i)
+        res = scm_cons (data[i], res);
+    }
+  else
+    {
+      const SCM *data;
+      scm_t_array_handle handle;
+      size_t i, count, len;
+      ssize_t inc;
+
+      data = scm_vector_elements (vec, &handle, &len, &inc);
+      scm_c_issue_deprecation_warning
+        ("Using vector->list on arrays is deprecated.  "
+         "Use array->list instead.");
+
+      for (i = (len - 1) * inc, count = 0;
+           count < len;
+           i -= inc, count++)
+        res = scm_cons (data[i], res);
+
+      scm_array_handle_release (&handle);
+    }
   return res;
 }
 #undef FUNC_NAME



reply via email to

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