Merge branch 'master' into boehm-demers-weiser-gc
[bpt/guile.git] / libguile / unif.c
index 7f01f62..ecf96df 100644 (file)
@@ -25,7 +25,7 @@
 */
 \f
 
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
@@ -1150,10 +1150,10 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
 
   if (SCM_I_ARRAYP (v) || SCM_I_ENCLOSED_ARRAYP (v))
     {
-      size_t k = SCM_I_ARRAY_NDIM (v);
+      size_t k, ndim = SCM_I_ARRAY_NDIM (v);
       scm_t_array_dim *s = SCM_I_ARRAY_DIMS (v);
 
-      while (k > 0)
+      for (k = 0; k < ndim; k++)
        {
          long ind;
 
@@ -1161,9 +1161,8 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
            SCM_WRONG_NUM_ARGS ();
          ind = scm_to_long (SCM_CAR (args));
          args = SCM_CDR (args);
-         k -= 1;
 
-         if (ind < s->lbnd || ind > s->ubnd)
+         if (ind < s[k].lbnd || ind > s[k].ubnd)
            {
              res = SCM_BOOL_F;
              /* We do not stop the checking after finding a violation
@@ -1470,14 +1469,6 @@ static scm_t_bits scm_tc16_bitvector;
 #define BITVECTOR_BITS(obj)     ((scm_t_uint32 *)SCM_SMOB_DATA(obj))
 #define BITVECTOR_LENGTH(obj)   ((size_t)SCM_SMOB_DATA_2(obj))
 
-static size_t
-bitvector_free (SCM vec)
-{
-  scm_gc_free (BITVECTOR_BITS (vec),
-              sizeof (scm_t_uint32) * ((BITVECTOR_LENGTH (vec)+31)/32),
-              "bitvector");
-  return 0;
-}
 
 static int
 bitvector_print (SCM vec, SCM port, scm_print_state *pstate)
@@ -2669,7 +2660,7 @@ read_decimal_integer (SCM port, int c, ssize_t *resp)
     }
 
   if (got_it)
-    *resp = res;
+    *resp = sign * res;
   return c;
 }
 
@@ -2753,6 +2744,11 @@ scm_i_read_array (SCM port, int c)
            {
              c = scm_getc (port);
              c = read_decimal_integer (port, c, &len);
+             if (len < 0)
+               scm_i_input_error (NULL, port,
+                                  "array length must be non-negative",
+                                  SCM_EOL);
+
              s = scm_list_2 (s, scm_from_ssize_t (lbnd+len-1));
            }
 
@@ -2838,21 +2834,6 @@ SCM_DEFINE (scm_array_prototype, "array-prototype", 1, 0, 0,
 
 #endif
 
-static SCM
-array_mark (SCM ptr)
-{
-  return SCM_I_ARRAY_V (ptr);
-}
-
-static size_t
-array_free (SCM ptr)
-{
-  scm_gc_free (SCM_I_ARRAY_MEM (ptr),
-              (sizeof (scm_i_t_array) 
-               + SCM_I_ARRAY_NDIM (ptr) * sizeof (scm_t_array_dim)),
-              "array");
-  return 0;
-}
 
 #if SCM_ENABLE_DEPRECATED
 
@@ -2922,21 +2903,16 @@ void
 scm_init_unif ()
 {
   scm_i_tc16_array = scm_make_smob_type ("array", 0);
-  scm_set_smob_mark (scm_i_tc16_array, array_mark);
-  scm_set_smob_free (scm_i_tc16_array, array_free);
   scm_set_smob_print (scm_i_tc16_array, scm_i_print_array);
   scm_set_smob_equalp (scm_i_tc16_array, scm_array_equal_p);
 
   scm_i_tc16_enclosed_array = scm_make_smob_type ("enclosed-array", 0);
-  scm_set_smob_mark (scm_i_tc16_enclosed_array, array_mark);
-  scm_set_smob_free (scm_i_tc16_enclosed_array, array_free);
   scm_set_smob_print (scm_i_tc16_enclosed_array, scm_i_print_enclosed_array);
   scm_set_smob_equalp (scm_i_tc16_enclosed_array, scm_array_equal_p);
 
   scm_add_feature ("array");
 
   scm_tc16_bitvector = scm_make_smob_type ("bitvector", 0);
-  scm_set_smob_free (scm_tc16_bitvector, bitvector_free);
   scm_set_smob_print (scm_tc16_bitvector, bitvector_print);
   scm_set_smob_equalp (scm_tc16_bitvector, bitvector_equalp);