* gc.h, gc.c (scm_gc_sweep): Issue deprecation warning when
[bpt/guile.git] / libguile / unif.c
index 70fda42..4e9c572 100644 (file)
@@ -39,8 +39,6 @@
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
 
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 
 /*
   This file has code for arrays in lots of variants (double, integer,
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+
 \f
 /* The set of uniform scm_vector types is:
  *  Vector of:          Called:
  * long long           llvect
  */
 
-scm_bits_t scm_tc16_array;
+scm_t_bits scm_tc16_array;
 
 /* return the size of an element in a uniform array or 0 if type not
    found.  */
-scm_sizet
+size_t
 scm_uniform_element_size (SCM obj)
 {
-  scm_sizet result;
+  size_t result;
 
   switch (SCM_TYP7 (obj))
     {
@@ -116,7 +118,7 @@ scm_uniform_element_size (SCM obj)
 
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
-      result = sizeof (long_long);
+      result = sizeof (long long);
       break;
 #endif 
 
@@ -163,19 +165,16 @@ scm_make_uve (long k, SCM prot)
 
   if (SCM_EQ_P (prot, SCM_BOOL_T))
     {
-      SCM_NEWCELL (v);
       if (k > 0)
        {
-         SCM_ASSERT_RANGE (1, scm_long2num (k), k <= SCM_BITVECTOR_MAX_LENGTH);
+         SCM_ASSERT_RANGE (1,
+                           scm_long2num (k), k <= SCM_BITVECTOR_MAX_LENGTH);
          i = sizeof (long) * ((k + SCM_LONG_BIT - 1) / SCM_LONG_BIT);
-         SCM_SET_BITVECTOR_BASE (v, (char *) scm_must_malloc (i, "vector"));
-         SCM_SET_BITVECTOR_LENGTH (v, k);
+         v = scm_alloc_cell (SCM_MAKE_BITVECTOR_TAG (k), 
+                             (scm_t_bits) scm_gc_malloc (i, "vector"));
        }
       else
-       {
-         SCM_SET_BITVECTOR_BASE (v, 0);
-         SCM_SET_BITVECTOR_LENGTH (v, 0);
-       }
+       v = scm_alloc_cell (SCM_MAKE_BITVECTOR_TAG (0), 0);
       return v;
     }
   else if (SCM_CHARP (prot) && (SCM_CHAR (prot) == '\0'))
@@ -209,7 +208,7 @@ scm_make_uve (long k, SCM prot)
 #ifdef HAVE_LONG_LONGS
       else if (s == 'l')
        {
-         i = sizeof (long_long) * k;
+         i = sizeof (long long) * k;
          type = scm_tc7_llvect;
        }
 #endif
@@ -240,12 +239,8 @@ scm_make_uve (long k, SCM prot)
 
   SCM_ASSERT_RANGE (1, scm_long2num (k), k <= SCM_UVECTOR_MAX_LENGTH);
 
-  SCM_NEWCELL (v);
-  SCM_DEFER_INTS;
-  SCM_SET_UVECTOR_BASE (v, (char *) scm_must_malloc (i ? i : 1, "vector"));
-  SCM_SET_UVECTOR_LENGTH (v, k, type);
-  SCM_ALLOW_INTS;
-  return v;
+  return scm_alloc_cell (SCM_MAKE_UVECTOR_TAG (k, type),
+                        (scm_t_bits) scm_gc_malloc (i, "vector"));
 }
 #undef FUNC_NAME
 
@@ -399,8 +394,8 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
 #define FUNC_NAME s_scm_array_dimensions
 {
   SCM res = SCM_EOL;
-  scm_sizet k;
-  scm_array_dim *s;
+  size_t k;
+  scm_t_array_dim *s;
   if (SCM_IMP (ra))
     return SCM_BOOL_F;
   switch (SCM_TYP7 (ra))
@@ -468,8 +463,8 @@ SCM_DEFINE (scm_shared_array_increments, "shared-array-increments", 1, 0, 0,
 #define FUNC_NAME s_scm_shared_array_increments
 {
   SCM res = SCM_EOL;
-  scm_sizet k;
-  scm_array_dim *s;
+  size_t k;
+  scm_t_array_dim *s;
   SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME);
   k = SCM_ARRAY_NDIM (ra);
   s = SCM_ARRAY_DIMS (ra);
@@ -489,16 +484,16 @@ scm_aind (SCM ra, SCM args, const char *what)
 {
   SCM ind;
   register long j;
-  register scm_sizet pos = SCM_ARRAY_BASE (ra);
-  register scm_sizet k = SCM_ARRAY_NDIM (ra);
-  scm_array_dim *s = SCM_ARRAY_DIMS (ra);
+  register unsigned long pos = SCM_ARRAY_BASE (ra);
+  register unsigned long k = SCM_ARRAY_NDIM (ra);
+  scm_t_array_dim *s = SCM_ARRAY_DIMS (ra);
   if (SCM_INUMP (args))
     {
       if (k != 1)
        scm_error_num_args_subr (what);
       return pos + (SCM_INUM (args) - s->lbnd) * (s->inc);
     }
-  while (k && SCM_NIMP (args))
+  while (k && !SCM_NULLP (args))
     {
       ind = SCM_CAR (args);
       args = SCM_CDR (args);
@@ -523,11 +518,11 @@ SCM
 scm_make_ra (int ndim)
 {
   SCM ra;
-  SCM_NEWCELL (ra);
   SCM_DEFER_INTS;
-  SCM_NEWSMOB(ra, ((long) ndim << 17) + scm_tc16_array,
-              scm_must_malloc ((long) (sizeof (scm_array) + ndim * sizeof (scm_array_dim)),
-                              "array"));
+  SCM_NEWSMOB(ra, ((scm_t_bits) ndim << 17) + scm_tc16_array,
+              scm_gc_malloc ((sizeof (scm_t_array) +
+                             ndim * sizeof (scm_t_array_dim)),
+                            "array"));
   SCM_ARRAY_V (ra) = scm_nullvect;
   SCM_ALLOW_INTS;
   return ra;
@@ -540,7 +535,7 @@ static char s_bad_spec[] = "Bad scm_array dimension";
 SCM 
 scm_shap2ra (SCM args, const char *what)
 {
-  scm_array_dim *s;
+  scm_t_array_dim *s;
   SCM ra, spec, sp;
   int ndim = scm_ilength (args);
   if (ndim < 0)
@@ -579,17 +574,18 @@ scm_shap2ra (SCM args, const char *what)
 
 SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1, 0,
            (SCM dims, SCM prot, SCM fill),
-           "@deffnx primitive make-uniform-vector length prototype [fill]\n"
+           "@deffnx {Scheme Procedure} make-uniform-vector length prototype [fill]\n"
            "Create and return a uniform array or vector of type\n"
            "corresponding to @var{prototype} with dimensions @var{dims} or\n"
            "length @var{length}.  If @var{fill} is supplied, it's used to\n"
            "fill the array, otherwise @var{prototype} is used.")
 #define FUNC_NAME s_scm_dimensions_to_uniform_array
 {
-  scm_sizet k;
-  unsigned long int rlen = 1;
-  scm_array_dim *s;
+  size_t k;
+  unsigned long rlen = 1;
+  scm_t_array_dim *s;
   SCM ra;
+  
   if (SCM_INUMP (dims))
     {
       SCM answer = scm_make_uve (SCM_INUM (dims), prot);
@@ -601,12 +597,14 @@ SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1,
        scm_array_fill_x (answer, prot);
       return answer;
     }
+  
   SCM_ASSERT (SCM_NULLP (dims) || SCM_CONSP (dims),
               dims, SCM_ARG1, FUNC_NAME);
   ra = scm_shap2ra (dims, FUNC_NAME);
-  SCM_SETOR_CAR (ra, SCM_ARRAY_CONTIGUOUS);
+  SCM_SET_ARRAY_CONTIGUOUS_FLAG (ra);
   s = SCM_ARRAY_DIMS (ra);
   k = SCM_ARRAY_NDIM (ra);
+
   while (k--)
     {
       s[k].inc = rlen;
@@ -634,7 +632,7 @@ SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1,
 void 
 scm_ra_set_contp (SCM ra)
 {
-  scm_sizet k = SCM_ARRAY_NDIM (ra);
+  size_t k = SCM_ARRAY_NDIM (ra);
   if (k)
     {
       long inc = SCM_ARRAY_DIMS (ra)[k - 1].inc;
@@ -642,14 +640,14 @@ scm_ra_set_contp (SCM ra)
        {
          if (inc != SCM_ARRAY_DIMS (ra)[k].inc)
            {
-             SCM_SETAND_CAR (ra, ~SCM_ARRAY_CONTIGUOUS);
+             SCM_CLR_ARRAY_CONTIGUOUS_FLAG (ra);
              return;
            }
          inc *= (SCM_ARRAY_DIMS (ra)[k].ubnd 
                  - SCM_ARRAY_DIMS (ra)[k].lbnd + 1);
        }
     }
-  SCM_SETOR_CAR (ra, SCM_ARRAY_CONTIGUOUS);
+  SCM_SET_ARRAY_CONTIGUOUS_FLAG (ra);
 }
 
 
@@ -675,9 +673,9 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
   SCM ra;
   SCM inds, indptr;
   SCM imap;
-  scm_sizet i, k;
+  size_t k, i;
   long old_min, new_min, old_max, new_max;
-  scm_array_dim *s;
+  scm_t_array_dim *s;
 
   SCM_VALIDATE_REST_ARGUMENT (dims);
   SCM_VALIDATE_ARRAY (1,oldra);
@@ -717,9 +715,9 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
          return ra;
        }
     }
-  imap = scm_apply (mapfunc, scm_reverse (inds), SCM_EOL);
+  imap = scm_apply_0 (mapfunc, scm_reverse (inds));
   if (SCM_ARRAYP (oldra))
-      i = (scm_sizet) scm_aind (oldra, imap, FUNC_NAME);
+      i = (size_t) scm_aind (oldra, imap, FUNC_NAME);
   else
     {
       if (SCM_NINUMP (imap))
@@ -739,7 +737,7 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
       if (s[k].ubnd > s[k].lbnd)
        {
          SCM_SETCAR (indptr, SCM_MAKINUM (SCM_INUM (SCM_CAR (indptr)) + 1));
-         imap = scm_apply (mapfunc, scm_reverse (inds), SCM_EOL);
+         imap = scm_apply_0 (mapfunc, scm_reverse (inds));
          if (SCM_ARRAYP (oldra))
 
              s[k].inc = scm_aind (oldra, imap, FUNC_NAME) - i;
@@ -805,7 +803,7 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
 #define FUNC_NAME s_scm_transpose_array
 {
   SCM res, vargs, *ve = &vargs;
-  scm_array_dim *s, *r;
+  scm_t_array_dim *s, *r;
   int ndim, i, k;
 
   SCM_VALIDATE_REST_ARGUMENT (args);
@@ -914,7 +912,7 @@ SCM_DEFINE (scm_enclose_array, "enclose-array", 1, 0, 1,
 #define FUNC_NAME s_scm_enclose_array
 {
   SCM axv, res, ra_inr;
-  scm_array_dim vdim, *s = &vdim;
+  scm_t_array_dim vdim, *s = &vdim;
   int ndim, j, k, ninr, noutr;
 
   SCM_VALIDATE_REST_ARGUMENT (axes);
@@ -999,9 +997,9 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
 {
   SCM ind = SCM_EOL;
   long pos = 0;
-  register scm_sizet k;
+  register size_t k;
   register long j;
-  scm_array_dim *s;
+  scm_t_array_dim *s;
 
   SCM_VALIDATE_REST_ARGUMENT (args);
   SCM_ASRTGO (SCM_NIMP (v), badarg1);
@@ -1078,7 +1076,7 @@ SCM_REGISTER_PROC(s_array_ref, "array-ref", 1, 0, 1, scm_uniform_vector_ref);
 
 SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
            (SCM v, SCM args),
-           "@deffnx primitive array-ref v . args\n"
+           "@deffnx {Scheme Procedure} array-ref v . args\n"
            "Return the element at the @code{(index1, index2)} element in\n"
            "@var{array}.")
 #define FUNC_NAME s_scm_uniform_vector_ref
@@ -1151,13 +1149,13 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
   case scm_tc7_uvect:
     return scm_ulong2num (((unsigned long *) SCM_VELTS (v))[pos]);
   case scm_tc7_ivect:
-    return scm_long2num(((signed long *) SCM_VELTS (v))[pos]);
+    return scm_long2num (((signed long *) SCM_VELTS (v))[pos]);
 
     case scm_tc7_svect:
       return SCM_MAKINUM (((short *) SCM_CELL_WORD_1 (v))[pos]);
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
-      return scm_long_long2num (((long_long *) SCM_CELL_WORD_1 (v))[pos]);
+      return scm_long_long2num (((long long *) SCM_CELL_WORD_1 (v))[pos]);
 #endif
 
     case scm_tc7_fvect:
@@ -1178,7 +1176,7 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
    tries to recycle conses.  (Make *sure* you want them recycled.) */
 
 SCM 
-scm_cvref (SCM v, scm_sizet pos, SCM last)
+scm_cvref (SCM v, unsigned long pos, SCM last)
 #define FUNC_NAME "scm_cvref"
 {
   switch SCM_TYP7 (v)
@@ -1202,7 +1200,7 @@ scm_cvref (SCM v, scm_sizet pos, SCM last)
       return SCM_MAKINUM (((short *) SCM_CELL_WORD_1 (v))[pos]);
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
-      return scm_long_long2num (((long_long *) SCM_CELL_WORD_1 (v))[pos]);
+      return scm_long_long2num (((long long *) SCM_CELL_WORD_1 (v))[pos]);
 #endif
     case scm_tc7_fvect:
       if (SCM_NIMP (last) && !SCM_EQ_P (last, scm_flo0) && SCM_SLOPPY_REALP (last))
@@ -1256,14 +1254,13 @@ SCM_REGISTER_PROC(s_uniform_array_set1_x, "uniform-array-set1!", 3, 0, 0, scm_ar
    PROC is used (and it's called from C too).  */
 SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1, 
            (SCM v, SCM obj, SCM args),
-           "@deffnx primitive uniform-array-set1! v obj args\n"
-           "Sets the element at the @code{(index1, index2)} element in @var{array} to\n"
+           "@deffnx {Scheme Procedure} uniform-array-set1! v obj args\n"
+           "Set the element at the @code{(index1, index2)} element in @var{array} to\n"
            "@var{new-value}.  The value returned by array-set! is unspecified.")
 #define FUNC_NAME s_scm_array_set_x           
 {
   long pos = 0;
 
-  SCM_VALIDATE_REST_ARGUMENT (args);
   SCM_ASRTGO (SCM_NIMP (v), badarg1);
   if (SCM_ARRAYP (v))
     {
@@ -1273,10 +1270,9 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
   else
     {
       unsigned long int length;
-      if (SCM_NIMP (args))
+      if (SCM_CONSP (args))
        {
-         SCM_ASSERT (SCM_CONSP(args) && SCM_INUMP (SCM_CAR (args)), args,
-                SCM_ARG3, FUNC_NAME);
+         SCM_ASSERT (SCM_INUMP (SCM_CAR (args)), args, SCM_ARG3, FUNC_NAME);
          SCM_ASRTGO (SCM_NULLP (SCM_CDR (args)), wna);
          pos = SCM_INUM (SCM_CAR (args));
        }
@@ -1317,36 +1313,39 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
       ((char *) SCM_UVECTOR_BASE (v))[pos] = SCM_INUM (obj);
       break;
     case scm_tc7_uvect:
-      SCM_VELTS(v)[pos] = SCM_PACK (scm_num2ulong(obj, SCM_ARG2, FUNC_NAME));
+      ((unsigned long *) SCM_UVECTOR_BASE (v))[pos] 
+       = scm_num2ulong (obj, SCM_ARG2, FUNC_NAME);
       break;
     case scm_tc7_ivect:
-      SCM_VELTS(v)[pos] = SCM_PACK (scm_num2long (obj, SCM_ARG2, FUNC_NAME));
+      ((long *) SCM_UVECTOR_BASE (v))[pos] 
+       = scm_num2long (obj, SCM_ARG2, FUNC_NAME);
       break;
     case scm_tc7_svect:
       SCM_ASRTGO (SCM_INUMP (obj), badobj);
-      ((short *) SCM_CELL_WORD_1 (v))[pos] = SCM_INUM (obj);
+      ((short *) SCM_UVECTOR_BASE (v))[pos] = SCM_INUM (obj);
       break;
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
-      ((long_long *) SCM_CELL_WORD_1 (v))[pos] = scm_num2long_long (obj, SCM_ARG2, FUNC_NAME);
+      ((long long *) SCM_UVECTOR_BASE (v))[pos]
+       = scm_num2long_long (obj, SCM_ARG2, FUNC_NAME);
       break;
 #endif
-
-
     case scm_tc7_fvect:
-      ((float *) SCM_CELL_WORD_1 (v))[pos] = (float) scm_num2dbl (obj, FUNC_NAME);
+      ((float *) SCM_UVECTOR_BASE (v))[pos]
+       = (float) scm_num2dbl (obj, FUNC_NAME);
       break;
     case scm_tc7_dvect:
-      ((double *) SCM_CELL_WORD_1 (v))[pos] = scm_num2dbl (obj, FUNC_NAME);
+      ((double *) SCM_UVECTOR_BASE (v))[pos]
+       = scm_num2dbl (obj, FUNC_NAME);
       break;
     case scm_tc7_cvect:
       SCM_ASRTGO (SCM_INEXACTP (obj), badobj);
       if (SCM_REALP (obj)) {
-       ((double *) SCM_CELL_WORD_1 (v))[2 * pos] = SCM_REAL_VALUE (obj);
-       ((double *) SCM_CELL_WORD_1 (v))[2 * pos + 1] = 0.0;
+       ((double *) SCM_UVECTOR_BASE (v))[2 * pos] = SCM_REAL_VALUE (obj);
+       ((double *) SCM_UVECTOR_BASE (v))[2 * pos + 1] = 0.0;
       } else {
-       ((double *) SCM_CELL_WORD_1 (v))[2 * pos] = SCM_COMPLEX_REAL (obj);
-       ((double *) SCM_CELL_WORD_1 (v))[2 * pos + 1] = SCM_COMPLEX_IMAG (obj);
+       ((double *) SCM_UVECTOR_BASE (v))[2 * pos] = SCM_COMPLEX_REAL (obj);
+       ((double *) SCM_UVECTOR_BASE (v))[2 * pos + 1] = SCM_COMPLEX_IMAG (obj);
       }
       break;
     case scm_tc7_vector:
@@ -1364,7 +1363,6 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
                     wouldn't have contiguous elements.  */
 SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
            (SCM ra, SCM strict),
-           "@deffnx primitive array-contents array strict\n"
            "If @var{array} may be @dfn{unrolled} into a one dimensional shared array\n"
            "without changing their order (last subscript changing fastest), then\n"
            "@code{array-contents} returns that shared array, otherwise it returns\n"
@@ -1400,7 +1398,7 @@ SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
       return ra;
     case scm_tc7_smob:
       {
-       scm_sizet k, ndim = SCM_ARRAY_NDIM (ra), len = 1;
+       size_t k, ndim = SCM_ARRAY_NDIM (ra), len = 1;
        if (!SCM_ARRAYP (ra) || !SCM_ARRAY_CONTP (ra))
          return SCM_BOOL_F;
        for (k = 0; k < ndim; k++)
@@ -1443,7 +1441,7 @@ scm_ra2contig (SCM ra, int copy)
 {
   SCM ret;
   long inc = 1;
-  scm_sizet k, len = 1;
+  size_t k, len = 1;
   for (k = SCM_ARRAY_NDIM (ra); k--;)
     len *= SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd + 1;
   k = SCM_ARRAY_NDIM (ra);
@@ -1465,7 +1463,7 @@ scm_ra2contig (SCM ra, int copy)
       SCM_ARRAY_DIMS (ret)[k].inc = inc;
       inc *= SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd + 1;
     }
-  SCM_ARRAY_V (ret) = scm_make_uve ((inc - 1), scm_array_prototype (ra));
+  SCM_ARRAY_V (ret) = scm_make_uve (inc, scm_array_prototype (ra));
   if (copy)
     scm_array_copy_x (ra, ret);
   return ret;
@@ -1475,11 +1473,11 @@ scm_ra2contig (SCM ra, int copy)
 
 SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
            (SCM ra, SCM port_or_fd, SCM start, SCM end),
-           "@deffnx primitive uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
-           "Attempts to read all elements of @var{ura}, in lexicographic order, as\n"
+           "@deffnx {Scheme Procedure} uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
+           "Attempt to read all elements of @var{ura}, in lexicographic order, as\n"
            "binary objects from @var{port-or-fdes}.\n"
-           "If an end of file is encountered during\n"
-           "uniform-array-read! the objects up to that point only are put into @var{ura}\n"
+           "If an end of file is encountered,\n"
+           "the objects up to that point are put into @var{ura}\n"
            "(starting at the beginning) and the remainder of the array is\n"
            "unchanged.\n\n"
            "The optional arguments @var{start} and @var{end} allow\n"
@@ -1504,7 +1502,9 @@ SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
     SCM_ASSERT (SCM_INUMP (port_or_fd)
                || (SCM_OPINPORTP (port_or_fd)),
                port_or_fd, SCM_ARG2, FUNC_NAME);
-  vlen = SCM_INUM (scm_uniform_vector_length (v));
+  vlen = (SCM_TYP7 (v) == scm_tc7_smob
+         ? 0
+         : SCM_INUM (scm_uniform_vector_length (v)));
 
 loop:
   switch SCM_TYP7 (v)
@@ -1545,7 +1545,7 @@ loop:
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
       base = (char *) SCM_UVECTOR_BASE (v);
-      sz = sizeof (long_long);
+      sz = sizeof (long long);
       break;
 #endif
     case scm_tc7_fvect:
@@ -1584,7 +1584,7 @@ loop:
 
   if (SCM_NIMP (port_or_fd))
     {
-      scm_port *pt = SCM_PTAB_ENTRY (port_or_fd);
+      scm_t_port *pt = SCM_PTAB_ENTRY (port_or_fd);
       int remaining = (cend - offset) * sz;
       char *dest = base + (cstart + offset) * sz;
 
@@ -1625,7 +1625,7 @@ loop:
     {
       SCM_SYSCALL (ans = read (SCM_INUM (port_or_fd),
                               base + (cstart + offset) * sz,
-                              (scm_sizet) (sz * (cend - offset))));
+                              (sz * (cend - offset))));
       if (ans == -1)
        SCM_SYSERROR;
     }
@@ -1641,13 +1641,13 @@ loop:
 
 SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
            (SCM v, SCM port_or_fd, SCM start, SCM end),
-           "@deffnx primitive uniform-vector-write uve [port-or-fdes] [start] [end]\n"
+           "@deffnx {Scheme Procedure} uniform-vector-write uve [port-or-fdes] [start] [end]\n"
            "Writes all elements of @var{ura} as binary objects to\n"
            "@var{port-or-fdes}.\n\n"
            "The optional arguments @var{start}\n"
            "and @var{end} allow\n"
            "a specified region of a vector (or linearized array) to be written.\n\n"
-           "The number of objects actually written is returned. \n"
+           "The number of objects actually written is returned.\n"
            "@var{port-or-fdes} may be\n"
            "omitted, in which case it defaults to the value returned by\n"
            "@code{(current-output-port)}.")
@@ -1668,8 +1668,10 @@ SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
     SCM_ASSERT (SCM_INUMP (port_or_fd)
                || (SCM_OPOUTPORTP (port_or_fd)),
                port_or_fd, SCM_ARG2, FUNC_NAME);
-  vlen = SCM_INUM (scm_uniform_vector_length (v));
-
+  vlen = (SCM_TYP7 (v) == scm_tc7_smob
+         ? 0
+         : SCM_INUM (scm_uniform_vector_length (v)));
+  
 loop:
   switch SCM_TYP7 (v)
     {
@@ -1679,8 +1681,8 @@ loop:
       SCM_ASRTGO (SCM_ARRAYP (v), badarg1);
       v = scm_ra2contig (v, 1);
       cstart = SCM_ARRAY_BASE (v);
-      vlen = SCM_ARRAY_DIMS (v)->inc
-       * (SCM_ARRAY_DIMS (v)->ubnd - SCM_ARRAY_DIMS (v)->lbnd + 1);
+      vlen = (SCM_ARRAY_DIMS (v)->inc
+             * (SCM_ARRAY_DIMS (v)->ubnd - SCM_ARRAY_DIMS (v)->lbnd + 1));
       v = SCM_ARRAY_V (v);
       goto loop;
     case scm_tc7_string:
@@ -1709,7 +1711,7 @@ loop:
 #ifdef HAVE_LONG_LONGS
     case scm_tc7_llvect:
       base = (char *) SCM_UVECTOR_BASE (v);
-      sz = sizeof (long_long);
+      sz = sizeof (long long);
       break;
 #endif
     case scm_tc7_fvect:
@@ -1757,7 +1759,7 @@ loop:
     {
       SCM_SYSCALL (ans = write (SCM_INUM (port_or_fd),
                                base + (cstart + offset) * sz,
-                               (scm_sizet) (sz * (cend - offset))));
+                               (sz * (cend - offset))));
       if (ans == -1)
        SCM_SYSERROR;
     }
@@ -1879,7 +1881,7 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
            "length.  If @var{bool} is @code{#t}, uve is OR'ed into\n"
            "@var{bv}; If @var{bool} is @code{#f}, the inversion of uve is\n"
            "AND'ed into @var{bv}.\n\n"
-           "If uve is a unsigned integer vector all the elements of uve\n"
+           "If uve is a unsigned long integer vector all the elements of uve\n"
            "must be between 0 and the @code{length} of @var{bv}.  The bits\n"
            "of @var{bv} corresponding to the indexes in uve are set to\n"
            "@var{bool}.  The return value is unspecified.")
@@ -1917,10 +1919,10 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
       SCM_ASSERT (SCM_BITVECTOR_LENGTH (v) == SCM_BITVECTOR_LENGTH (kv), v, SCM_ARG1, FUNC_NAME);
       if (SCM_FALSEP (obj))
        for (k = (SCM_BITVECTOR_LENGTH (v) + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-         SCM_UNPACK (SCM_VELTS (v)[k]) &= ~ SCM_UNPACK(SCM_VELTS (kv)[k]);
+         SCM_BITVECTOR_BASE (v) [k] &= ~SCM_BITVECTOR_BASE (kv) [k];
       else if (SCM_EQ_P (obj, SCM_BOOL_T))
        for (k = (SCM_BITVECTOR_LENGTH (v) + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-         SCM_UNPACK (SCM_VELTS (v)[k]) |= SCM_UNPACK (SCM_VELTS (kv)[k]);
+         SCM_BITVECTOR_BASE (v) [k] |= SCM_BITVECTOR_BASE (kv) [k];
       else
        goto badarg3;
       break;
@@ -2000,7 +2002,7 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
 
 SCM_DEFINE (scm_bit_invert_x, "bit-invert!", 1, 0, 0, 
            (SCM v),
-           "Modifies @var{bv} by replacing each element with its negation.")
+           "Modify @var{bv} by replacing each element with its negation.")
 #define FUNC_NAME s_scm_bit_invert_x
 {
   long int k;
@@ -2009,7 +2011,7 @@ SCM_DEFINE (scm_bit_invert_x, "bit-invert!", 1, 0, 0,
 
   k = SCM_BITVECTOR_LENGTH (v);
   for (k = (k + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-    SCM_UNPACK (SCM_VELTS (v)[k]) = ~SCM_UNPACK (SCM_VELTS (v)[k]);
+    SCM_BITVECTOR_BASE (v) [k] = ~SCM_BITVECTOR_BASE (v) [k];
 
   return SCM_UNSPECIFIED;
 }
@@ -2048,11 +2050,11 @@ scm_istr2bve (char *str, long len)
 
 
 static SCM 
-ra2l (SCM ra,scm_sizet base,scm_sizet k)
+ra2l (SCM ra,unsigned long base,unsigned long k)
 {
   register SCM res = SCM_EOL;
   register long inc = SCM_ARRAY_DIMS (ra)[k].inc;
-  register scm_sizet i;
+  register size_t i;
   if (SCM_ARRAY_DIMS (ra)[k].ubnd < SCM_ARRAY_DIMS (ra)[k].lbnd)
     return SCM_EOL;
   i = base + (1 + SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd) * inc;
@@ -2076,11 +2078,11 @@ ra2l (SCM ra,scm_sizet base,scm_sizet k)
 }
 
 
-SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0, 
+SCM_DEFINE (scm_t_arrayo_list, "array->list", 1, 0, 0, 
            (SCM v),
            "Return a list consisting of all the elements, in order, of\n"
            "@var{array}.")
-#define FUNC_NAME s_scm_array_to_list
+#define FUNC_NAME s_scm_t_arrayo_list
 {
   SCM res = SCM_EOL;
   register long k;
@@ -2108,36 +2110,44 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
          res = scm_cons (SCM_BOOL(((long *) data)[k] & mask), res);
        return res;
       }
-  case scm_tc7_uvect: {
-    long *data = (long *)SCM_VELTS(v);
-    for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-      res = scm_cons(scm_ulong2num(data[k]), res);
-    return res;
-  }
-  case scm_tc7_ivect: {
-    long *data = (long *)SCM_VELTS(v);
-    for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-      res = scm_cons(scm_long2num(data[k]), res);
-    return res;
-  }
-    case scm_tc7_svect: {
-      short *data;
-      data = (short *)SCM_VELTS(v);
-      for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-       res = scm_cons(SCM_MAKINUM (data[k]), res);
-      return res;
-    }
+    case scm_tc7_byvect:
+      {
+       signed char *data = (signed char *) SCM_VELTS (v);
+       unsigned long k = SCM_UVECTOR_LENGTH (v);
+       while (k != 0)
+         res = scm_cons (SCM_MAKINUM (data[--k]), res);
+       return res;
+      }
+    case scm_tc7_uvect:
+      {
+       long *data = (long *)SCM_VELTS(v);
+       for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
+         res = scm_cons(scm_ulong2num(data[k]), res);
+       return res;
+      }
+    case scm_tc7_ivect:
+      {
+       long *data = (long *)SCM_VELTS(v);
+       for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
+         res = scm_cons(scm_long2num(data[k]), res);
+       return res;
+      }
+    case scm_tc7_svect:
+      {
+       short *data = (short *)SCM_VELTS(v);
+       for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
+         res = scm_cons(scm_short2num (data[k]), res);
+       return res;
+      }
 #ifdef HAVE_LONG_LONGS
-    case scm_tc7_llvect: {
-      long_long *data;
-      data = (long_long *)SCM_VELTS(v);
-      for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-       res = scm_cons(scm_long_long2num(data[k]), res);
-      return res;
-    }
+    case scm_tc7_llvect:
+      {
+       long long *data = (long long *)SCM_VELTS(v);
+       for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
+         res = scm_cons(scm_long_long2num(data[k]), res);
+       return res;
+      }
 #endif
-
-
     case scm_tc7_fvect:
       {
        float *data = (float *) SCM_VELTS (v);
@@ -2164,11 +2174,11 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
 #undef FUNC_NAME
 
 
-static int l2ra(SCM lst, SCM ra, scm_sizet base, scm_sizet k);
+static int l2ra(SCM lst, SCM ra, unsigned long base, unsigned long k);
 
 SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
            (SCM ndim, SCM prot, SCM lst),
-           "@deffnx procedure list->uniform-vector prot lst\n"
+           "@deffnx {Scheme Procedure} list->uniform-vector prot lst\n"
            "Return a uniform array of the type indicated by prototype\n"
            "@var{prot} with elements the same as those of @var{lst}.\n"
            "Elements must be of the appropriate type, no coercions are\n"
@@ -2178,7 +2188,7 @@ SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
   SCM shp = SCM_EOL;
   SCM row = lst;
   SCM ra;
-  scm_sizet k;
+  unsigned long k;
   long n;
   SCM_VALIDATE_INUM_COPY (1,ndim,k);
   while (k--)
@@ -2207,12 +2217,13 @@ SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
   if (l2ra (lst, ra, SCM_ARRAY_BASE (ra), 0))
     return ra;
   else
-    badlst:SCM_MISC_ERROR ("Bad scm_array contents list: ~S", SCM_LIST1 (lst));
+    badlst:SCM_MISC_ERROR ("Bad scm_array contents list: ~S",
+                          scm_list_1 (lst));
 }
 #undef FUNC_NAME
 
 static int 
-l2ra (SCM lst, SCM ra, scm_sizet base, scm_sizet k)
+l2ra (SCM lst, SCM ra, unsigned long base, unsigned long k)
 {
   register long inc = SCM_ARRAY_DIMS (ra)[k].inc;
   register long n = (1 + SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd);
@@ -2250,7 +2261,7 @@ l2ra (SCM lst, SCM ra, scm_sizet base, scm_sizet k)
 
 
 static void 
-rapr1 (SCM ra,scm_sizet j,scm_sizet k,SCM port,scm_print_state *pstate)
+rapr1 (SCM ra,unsigned long j,unsigned long k,SCM port,scm_print_state *pstate)
 {
   long inc = 1;
   long n = (SCM_TYP7 (ra) == scm_tc7_smob
@@ -2293,8 +2304,7 @@ tail:
            }
          break;
        }
-      if SCM_ARRAY_NDIM
-       (ra)
+      if (SCM_ARRAY_NDIM (ra) > 0)
        {                       /* Could be zero-dimensional */
          inc = SCM_ARRAY_DIMS (ra)[k].inc;
          n = (SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd + 1);
@@ -2430,7 +2440,7 @@ int
 scm_raprin1 (SCM exp, SCM port, scm_print_state *pstate)
 {
   SCM v = exp;
-  scm_sizet base = 0;
+  unsigned long base = 0;
   scm_putc ('#', port);
 tail:
   switch SCM_TYP7 (v)
@@ -2461,7 +2471,7 @@ tail:
          scm_putc ('*', port);
          for (i = 0; i < (SCM_BITVECTOR_LENGTH (exp)) / SCM_LONG_BIT; i++)
            {
-             scm_bits_t w = SCM_UNPACK (SCM_VELTS (exp)[i]);
+             scm_t_bits w = SCM_UNPACK (SCM_VELTS (exp)[i]);
              for (j = SCM_LONG_BIT; j; j--)
                {
                  scm_putc (w & 1 ? '1' : '0', port);
@@ -2576,11 +2586,14 @@ array_mark (SCM ptr)
 }
 
 
-static scm_sizet
+static size_t
 array_free (SCM ptr)
 {
-  scm_must_free (SCM_ARRAY_MEM (ptr));
-  return sizeof (scm_array) + SCM_ARRAY_NDIM (ptr) * sizeof (scm_array_dim);
+  scm_gc_free (SCM_ARRAY_MEM (ptr),
+              (sizeof (scm_t_array) 
+               + SCM_ARRAY_NDIM (ptr) * sizeof (scm_t_array_dim)),
+              "array");
+  return 0;
 }
 
 void