Avoid signed overflow and use size_t in bytevectors.c.
[bpt/guile.git] / libguile / vectors.c
index c01b3e3..abcbfa0 100644 (file)
@@ -1,18 +1,20 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008 Free Software Foundation, Inc.
- * 
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 2009, 2010,
+ *   2011, 2012, 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 as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
  */
 
 
 #include "libguile/eq.h"
 #include "libguile/root.h"
 #include "libguile/strings.h"
-#include "libguile/lang.h"
 
 #include "libguile/validate.h"
 #include "libguile/vectors.h"
-#include "libguile/unif.h"
-#include "libguile/ramap.h"
-#include "libguile/srfi-4.h"
+#include "libguile/arrays.h" /* Hit me with the ugly stick */
+#include "libguile/generalized-vectors.h"
 #include "libguile/strings.h"
 #include "libguile/srfi-13.h"
 #include "libguile/dynwind.h"
 #include "libguile/deprecation.h"
 
-#include "libguile/boehm-gc.h"
+#include "libguile/bdw-gc.h"
 
 
 \f
 int
 scm_is_vector (SCM obj)
 {
-  if (SCM_I_IS_VECTOR (obj))
+  if (SCM_I_IS_NONWEAK_VECTOR (obj))
     return 1;
-  if  (SCM_I_ARRAYP (obj) && SCM_I_ARRAY_NDIM (obj) == 1)
+  if (SCM_I_WVECTP (obj))
+    {
+      scm_c_issue_deprecation_warning
+        ("Expecting vector? to be true for weak vectors is deprecated.  "
+         "Use weak-vector? instead.");
+      return 1;
+    }
+  if (SCM_I_ARRAYP (obj) && SCM_I_ARRAY_NDIM (obj) == 1)
     {
       SCM v = SCM_I_ARRAY_V (obj);
-      return SCM_I_IS_VECTOR (v);
+      if (SCM_I_IS_VECTOR (v))
+        {
+          scm_c_issue_deprecation_warning
+            ("Expecting vector? to be true for rank-1 arrays is deprecated.  "
+             "Use array?, array-rank, and array-type instead.");
+          return 1;
+        }
+      return 0;
     }
   return 0;
 }
@@ -60,7 +74,16 @@ scm_is_vector (SCM obj)
 int
 scm_is_simple_vector (SCM obj)
 {
-  return SCM_I_IS_VECTOR (obj);
+  if (SCM_I_IS_NONWEAK_VECTOR (obj))
+    return 1;
+  if (SCM_I_WVECTP (obj))
+    {
+      scm_c_issue_deprecation_warning
+        ("Expecting scm_is_simple_vector to be true for weak vectors is "
+         "deprecated.  Use scm_is_weak_vector instead.");
+      return 1;
+    }
+  return 0;
 }
 
 const SCM *
@@ -117,20 +140,38 @@ SCM
 scm_vector_length (SCM v)
 {
   if (SCM_I_IS_VECTOR (v))
-    return scm_from_size_t (SCM_I_VECTOR_LENGTH (v));
+    {
+      if (SCM_I_WVECTP (v))
+        scm_c_issue_deprecation_warning
+          ("Using vector-length on weak vectors is deprecated.  "
+           "Use weak-vector-length from (ice-9 weak-vectors) instead.");
+      return scm_from_size_t (SCM_I_VECTOR_LENGTH (v));
+    }
   else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
     {
       scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
+      scm_c_issue_deprecation_warning
+        ("Using vector-length on arrays is deprecated.  "
+         "Use array-length instead.");
       return scm_from_size_t (dim->ubnd - dim->lbnd + 1);
     }
+  else if (SCM_UNPACK (g_vector_length))
+    {
+      scm_c_issue_deprecation_warning
+        ("Using vector-length as a primitive-generic is deprecated.");
+      return scm_call_generic_1 (g_vector_length, v);
+    }
   else
-    SCM_WTA_DISPATCH_1 (g_vector_length, v, 1, NULL);
+    {
+      scm_wrong_type_arg_msg ("vector-length", 1, v, "vector");
+      return SCM_UNDEFINED;  /* not reached */
+    }
 }
 
 size_t
 scm_c_vector_length (SCM v)
 {
-  if (SCM_I_IS_VECTOR (v))
+  if (SCM_I_IS_NONWEAK_VECTOR (v))
     return SCM_I_VECTOR_LENGTH (v);
   else
     return scm_to_size_t (scm_vector_length (v));
@@ -206,7 +247,7 @@ scm_vector_ref (SCM v, SCM k)
 SCM
 scm_c_vector_ref (SCM v, size_t k)
 {
-  if (SCM_I_IS_VECTOR (v))
+  if (SCM_I_IS_NONWEAK_VECTOR (v))
     {
       register SCM elt;
 
@@ -214,12 +255,15 @@ scm_c_vector_ref (SCM v, size_t k)
        scm_out_of_range (NULL, scm_from_size_t (k));
       elt = (SCM_I_VECTOR_ELTS(v))[k];
 
-      if ((elt == SCM_PACK (NULL)) && SCM_I_WVECTP (v))
-       /* ELT was a weak pointer and got nullified by the GC.  */
-       return SCM_BOOL_F;
-
       return elt;
     }
+  else if (SCM_I_WVECTP (v))
+    {
+      scm_c_issue_deprecation_warning
+        ("Using vector-ref on weak vectors is deprecated.  "
+         "Instead, use weak-vector-ref from (ice-9 weak-vectors).");
+      return scm_c_weak_vector_ref (v, k);
+    }
   else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
     {
       scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
@@ -228,21 +272,38 @@ scm_c_vector_ref (SCM v, size_t k)
        {
          register SCM elt;
 
+          scm_c_issue_deprecation_warning
+            ("Using vector-ref on arrays is deprecated.  "
+             "Use array-ref instead.");
+
          if (k >= dim->ubnd - dim->lbnd + 1)
            scm_out_of_range (NULL, scm_from_size_t (k));
          k = SCM_I_ARRAY_BASE (v) + k*dim->inc;
          elt = (SCM_I_VECTOR_ELTS (vv))[k];
 
-         if ((elt == SCM_PACK (NULL)) && (SCM_I_WVECTP (vv)))
-           /* ELT was a weak pointer and got nullified by the GC.  */
-           return SCM_BOOL_F;
+         if (SCM_UNPACK (elt) == 0 && (SCM_I_WVECTP (vv)))
+            {
+              scm_c_issue_deprecation_warning
+                ("Weak arrays are deprecated.  Use weak vectors instead.");
+              /* ELT was a weak pointer and got nullified by the GC.  */
+              return SCM_BOOL_F;
+            }
 
          return elt;
        }
       scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
     }
+  else if (SCM_UNPACK (g_vector_ref))
+    {
+      scm_c_issue_deprecation_warning
+        ("Using vector-ref as a primitive-generic is deprecated.");
+      return scm_call_generic_2 (g_vector_ref, v, scm_from_size_t (k));
+    }
   else
-    SCM_WTA_DISPATCH_2 (g_vector_ref, v, scm_from_size_t (k), 2, NULL);
+    {
+      scm_wrong_type_arg_msg ("vector-ref", 1, v, "vector");
+      return SCM_UNDEFINED;  /* not reached */
+    }
 }
 
 SCM_GPROC (s_vector_set_x, "vector-set!", 3, 0, 0, scm_vector_set_x, g_vector_set_x);
@@ -270,17 +331,18 @@ scm_vector_set_x (SCM v, SCM k, SCM obj)
 void
 scm_c_vector_set_x (SCM v, size_t k, SCM obj)
 {
-  if (SCM_I_IS_VECTOR (v))
+  if (SCM_I_IS_NONWEAK_VECTOR (v))
     {
       if (k >= SCM_I_VECTOR_LENGTH (v))
        scm_out_of_range (NULL, scm_from_size_t (k)); 
       (SCM_I_VECTOR_WELTS(v))[k] = obj;
-      if (SCM_I_WVECTP (v))
-       {
-         /* Make it a weak pointer.  */
-         GC_PTR link = (GC_PTR) & ((SCM_I_VECTOR_WELTS (v))[k]);
-         GC_GENERAL_REGISTER_DISAPPEARING_LINK (link, obj);
-       }
+    }
+  else if (SCM_I_WVECTP (v))
+    {
+      scm_c_issue_deprecation_warning
+        ("Using vector-set! on weak vectors is deprecated.  "
+         "Instead, use weak-vector-set! from (ice-9 weak-vectors).");
+      scm_c_weak_vector_set_x (v, k, obj);
     }
   else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
     {
@@ -288,6 +350,10 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
       SCM vv = SCM_I_ARRAY_V (v);
       if (SCM_I_IS_VECTOR (vv))
        {
+          scm_c_issue_deprecation_warning
+            ("Using vector-set! on arrays is deprecated.  "
+             "Use array-set! instead, but note the change in argument order.");
+
          if (k >= dim->ubnd - dim->lbnd + 1)
            scm_out_of_range (NULL, scm_from_size_t (k));
          k = SCM_I_ARRAY_BASE (v) + k*dim->inc;
@@ -296,21 +362,23 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
          if (SCM_I_WVECTP (vv))
            {
              /* Make it a weak pointer.  */
-             GC_PTR link = (GC_PTR) & ((SCM_I_VECTOR_WELTS (vv))[k]);
-             GC_GENERAL_REGISTER_DISAPPEARING_LINK (link, obj);
+             SCM *link = & SCM_I_VECTOR_WELTS (vv)[k];
+             SCM_I_REGISTER_DISAPPEARING_LINK ((void **) link, SCM2PTR (obj));
+              scm_c_issue_deprecation_warning
+                ("Weak arrays are deprecated.  Use weak vectors instead.");
            }
        }
       else
        scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
     }
-  else
+  else if (SCM_UNPACK (g_vector_set_x))
     {
-      if (SCM_UNPACK (g_vector_set_x))
-       scm_apply_generic (g_vector_set_x,
-                          scm_list_3 (v, scm_from_size_t (k), obj));
-      else
-       scm_wrong_type_arg_msg (NULL, 0, v, "vector");
+      scm_c_issue_deprecation_warning
+        ("Using vector-set! as a primitive-generic is deprecated.");
+      scm_call_3 (g_vector_set_x, v, scm_from_size_t (k), obj);
     }
+  else
+    scm_wrong_type_arg_msg ("vector-set!", 1, v, "vector");
 }
 
 SCM_DEFINE (scm_make_vector, "make-vector", 1, 1, 0,
@@ -335,26 +403,28 @@ SCM
 scm_c_make_vector (size_t k, SCM fill)
 #define FUNC_NAME s_scm_make_vector
 {
-  SCM v;
-  SCM *base;
+  SCM *vector;
+
+  vector = (SCM *)
+    scm_gc_malloc ((k + SCM_I_VECTOR_HEADER_SIZE) * sizeof (SCM),
+                  "vector");
 
-  if (k > 0) 
+  if (k > 0)
     {
+      SCM *base;
       unsigned long int j;
 
       SCM_ASSERT_RANGE (1, scm_from_ulong (k), k <= VECTOR_MAX_LENGTH);
 
-      base = scm_gc_malloc (k * sizeof (SCM), "vector");
+      base = vector + SCM_I_VECTOR_HEADER_SIZE;
       for (j = 0; j != k; ++j)
        base[j] = fill;
     }
-  else
-    base = NULL;
 
-  v = scm_immutable_cell ((k << 8) | scm_tc7_vector, (scm_t_bits) base);
-  scm_remember_upto_here_1 (fill);
+  ((scm_t_bits *) vector)[0] = (k << 8) | scm_tc7_vector;
+  ((scm_t_bits *) vector)[1] = 0;
 
-  return v;
+  return PTR2SCM (vector);
 }
 #undef FUNC_NAME
 
@@ -367,54 +437,39 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
   size_t i, len;
   ssize_t inc;
   const SCM *src;
-  SCM *dst;
+  SCM result, *dst;
 
   src = scm_vector_elements (vec, &handle, &len, &inc);
-  dst = scm_gc_malloc (len * sizeof (SCM), "vector");
+
+  result = scm_c_make_vector (len, SCM_UNDEFINED);
+  dst = SCM_I_VECTOR_WELTS (result);
   for (i = 0; i < len; i++, src += inc)
     dst[i] = *src;
+
   scm_array_handle_release (&handle);
 
-  return scm_cell ((len << 8) | scm_tc7_vector, (scm_t_bits) dst);
+  return result;
 }
 #undef FUNC_NAME
 
-void
-scm_i_vector_free (SCM vec)
-{
-  scm_gc_free (SCM_I_VECTOR_WELTS (vec),
-              SCM_I_VECTOR_LENGTH (vec) * sizeof(SCM),
-              "vector");
-}
-
 \f
 /* Weak vectors.  */
 
-
-/* Initialize RET as a weak vector of type TYPE of SIZE elements pointed to
-   by BASE.  */
-#define MAKE_WEAK_VECTOR(_ret, _type, _size, _base)            \
-  (_ret) = scm_double_cell ((_size << 8) | scm_tc7_wvect,      \
-                           (scm_t_bits) (_base),               \
-                           (_type),                            \
-                           SCM_UNPACK (SCM_EOL));
-
-
 /* Allocate memory for the elements of a weak vector on behalf of the
    caller.  */
-static SCM *
-allocate_weak_vector (scm_t_bits type, size_t c_size)
+static SCM
+make_weak_vector (scm_t_bits type, size_t c_size)
 {
-  SCM *base;
+  SCM *vector;
+  size_t total_size;
 
-  if (c_size > 0)
-    /* The base itself should not be scanned for pointers otherwise those
-       pointers will always be reachable.  */
-    base = scm_gc_malloc_pointerless (c_size * sizeof (SCM), "weak vector");
-  else
-    base = NULL;
+  total_size = (c_size + SCM_I_VECTOR_HEADER_SIZE) * sizeof (SCM);
+  vector = (SCM *) scm_gc_malloc_pointerless (total_size, "weak vector");
+
+  ((scm_t_bits *) vector)[0] = (c_size << 8) | scm_tc7_wvect;
+  ((scm_t_bits *) vector)[1] = type;
 
-  return base;
+  return PTR2SCM (vector);
 }
 
 /* Return a new weak vector.  The allocated vector will be of the given weak
@@ -430,13 +485,12 @@ scm_i_make_weak_vector (scm_t_bits type, SCM size, SCM fill)
     fill = SCM_UNSPECIFIED;
 
   c_size = scm_to_unsigned_integer (size, 0, VECTOR_MAX_LENGTH);
-  base = allocate_weak_vector (type, c_size);
+  wv = make_weak_vector (type, c_size);
+  base = SCM_I_WVECT_GC_WVELTS (wv);
 
   for (j = 0; j != c_size; ++j)
     base[j] = fill;
 
-  MAKE_WEAK_VECTOR (wv, type, c_size, base);
-
   return wv;
 }
 
@@ -445,22 +499,21 @@ scm_i_make_weak_vector (scm_t_bits type, SCM size, SCM fill)
 SCM
 scm_i_make_weak_vector_from_list (scm_t_bits type, SCM lst)
 {
-  SCM wv, *base, *elt;
+  SCM wv, *elt;
   long c_size;
 
   c_size = scm_ilength (lst);
   SCM_ASSERT (c_size >= 0, lst, SCM_ARG2, "scm_i_make_weak_vector_from_list");
 
-  base = allocate_weak_vector (type, (size_t)c_size);
-  for (elt = base;
+  wv = make_weak_vector(type, (size_t) c_size);
+
+  for (elt = SCM_I_WVECT_GC_WVELTS (wv);
        scm_is_pair (lst);
        lst = SCM_CDR (lst), elt++)
     {
       *elt = SCM_CAR (lst);
     }
 
-  MAKE_WEAK_VECTOR (wv, type, (size_t)c_size, base);
-
   return wv;
 }
 
@@ -549,7 +602,9 @@ SCM_DEFINE (scm_vector_move_left_x, "vector-move-left!", 5, 0, 0,
 
   i = scm_to_unsigned_integer (start1, 0, len1);
   e = scm_to_unsigned_integer (end1, i, len1);
-  j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
+  SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
+  j = scm_to_unsigned_integer (start2, 0, len2);
+  SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
   
   i *= inc1;
   e *= inc1;
@@ -587,7 +642,11 @@ SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
 
   i = scm_to_unsigned_integer (start1, 0, len1);
   e = scm_to_unsigned_integer (end1, i, len1);
-  j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
+  SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
+  j = scm_to_unsigned_integer (start2, 0, len2);
+  SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
+  
+  j += (e - i);
   
   i *= inc1;
   e *= inc1;
@@ -606,136 +665,47 @@ SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
 }
 #undef FUNC_NAME
 
-
-/* Generalized vectors. */
-
-int
-scm_is_generalized_vector (SCM obj)
-{
-  return (scm_is_vector (obj)
-         || scm_is_string (obj)
-         || scm_is_bitvector (obj)
-         || scm_is_uniform_vector (obj));
-}
-
-SCM_DEFINE (scm_generalized_vector_p, "generalized-vector?", 1, 0, 0,
-           (SCM obj),
-           "Return @code{#t} if @var{obj} is a vector, string,\n"
-           "bitvector, or uniform numeric vector.")
-#define FUNC_NAME s_scm_generalized_vector_p
-{
-  return scm_from_bool (scm_is_generalized_vector (obj));
-}
-#undef FUNC_NAME
-
-void
-scm_generalized_vector_get_handle (SCM vec, scm_t_array_handle *h)
-{
-  scm_array_get_handle (vec, h);
-  if (scm_array_handle_rank (h) != 1)
-    scm_wrong_type_arg_msg (NULL, 0, vec, "vector");
-}
-
-size_t
-scm_c_generalized_vector_length (SCM v)
-{
-  if (scm_is_vector (v))
-    return scm_c_vector_length (v);
-  else if (scm_is_string (v))
-    return scm_c_string_length (v);
-  else if (scm_is_bitvector (v))
-    return scm_c_bitvector_length (v);
-  else if (scm_is_uniform_vector (v))
-    return scm_c_uniform_vector_length (v);
-  else
-    scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
-}
-
-SCM_DEFINE (scm_generalized_vector_length, "generalized-vector-length", 1, 0, 0,
-           (SCM v),
-           "Return the length of the generalized vector @var{v}.")
-#define FUNC_NAME s_scm_generalized_vector_length
-{
-  return scm_from_size_t (scm_c_generalized_vector_length (v));
-}
-#undef FUNC_NAME
-
-SCM
-scm_c_generalized_vector_ref (SCM v, size_t idx)
+\f
+static SCM
+vector_handle_ref (scm_t_array_handle *h, size_t idx)
 {
-  if (scm_is_vector (v))
-    return scm_c_vector_ref (v, idx);
-  else if (scm_is_string (v))
-    return scm_c_string_ref (v, idx);
-  else if (scm_is_bitvector (v))
-    return scm_c_bitvector_ref (v, idx);
-  else if (scm_is_uniform_vector (v))
-    return scm_c_uniform_vector_ref (v, idx);
-  else
-    scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
+  if (idx > h->dims[0].ubnd)
+    scm_out_of_range ("vector-handle-ref", scm_from_size_t (idx));
+  return ((SCM*)h->elements)[idx];
 }
 
-SCM_DEFINE (scm_generalized_vector_ref, "generalized-vector-ref", 2, 0, 0,
-           (SCM v, SCM idx),
-           "Return the element at index @var{idx} of the\n"
-           "generalized vector @var{v}.")
-#define FUNC_NAME s_scm_generalized_vector_ref
+static void
+vector_handle_set (scm_t_array_handle *h, size_t idx, SCM val)
 {
-  return scm_c_generalized_vector_ref (v, scm_to_size_t (idx));
+  if (idx > h->dims[0].ubnd)
+    scm_out_of_range ("vector-handle-set!", scm_from_size_t (idx));
+  ((SCM*)h->writable_elements)[idx] = val;
 }
-#undef FUNC_NAME
 
-void
-scm_c_generalized_vector_set_x (SCM v, size_t idx, SCM val)
+static void
+vector_get_handle (SCM v, scm_t_array_handle *h)
 {
-  if (scm_is_vector (v))
-    scm_c_vector_set_x (v, idx, val);
-  else if (scm_is_string (v))
-    scm_c_string_set_x (v, idx, val);
-  else if (scm_is_bitvector (v))
-    scm_c_bitvector_set_x (v, idx, val);
-  else if (scm_is_uniform_vector (v))
-    scm_c_uniform_vector_set_x (v, idx, val);
-  else
-    scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
+  h->array = v;
+  h->ndims = 1;
+  h->dims = &h->dim0;
+  h->dim0.lbnd = 0;
+  h->dim0.ubnd = SCM_I_VECTOR_LENGTH (v) - 1;
+  h->dim0.inc = 1;
+  h->element_type = SCM_ARRAY_ELEMENT_TYPE_SCM;
+  h->elements = h->writable_elements = SCM_I_VECTOR_WELTS (v);
 }
 
-SCM_DEFINE (scm_generalized_vector_set_x, "generalized-vector-set!", 3, 0, 0,
-           (SCM v, SCM idx, SCM val),
-           "Set the element at index @var{idx} of the\n"
-           "generalized vector @var{v} to @var{val}.")
-#define FUNC_NAME s_scm_generalized_vector_set_x
-{
-  scm_c_generalized_vector_set_x (v, scm_to_size_t (idx), val);
-  return SCM_UNSPECIFIED;
-}
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_generalized_vector_to_list, "generalized-vector->list", 1, 0, 0,
-           (SCM v),
-           "Return a new list whose elements are the elements of the\n"
-           "generalized vector @var{v}.")
-#define FUNC_NAME s_scm_generalized_vector_to_list
-{
-  if (scm_is_vector (v))
-    return scm_vector_to_list (v);
-  else if (scm_is_string (v))
-    return scm_string_to_list (v);
-  else if (scm_is_bitvector (v))
-    return scm_bitvector_to_list (v);
-  else if (scm_is_uniform_vector (v))
-    return scm_uniform_vector_to_list (v);
-  else
-    scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
-}
-#undef FUNC_NAME
+/* the & ~2 allows catching scm_tc7_wvect as well. needs changing if you change
+   tags.h. */
+SCM_ARRAY_IMPLEMENTATION (scm_tc7_vector, 0x7f & ~2,
+                          vector_handle_ref, vector_handle_set,
+                          vector_get_handle)
+SCM_VECTOR_IMPLEMENTATION (SCM_ARRAY_ELEMENT_TYPE_SCM, scm_make_vector)
 
 
 void
 scm_init_vectors ()
 {
-  scm_nullvect = scm_c_make_vector (0, SCM_UNDEFINED);
-
 #include "libguile/vectors.x"
 }