Auto-commit of loaddefs files.
[bpt/emacs.git] / src / fns.c
index a963291..a128b92 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -23,11 +23,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <time.h>
 #include <setjmp.h>
 
-/* Note on some machines this defines `vector' as a typedef,
-   so make sure we don't use that name in this file.  */
-#undef vector
-#define vector *****
-
 #include "lisp.h"
 #include "commands.h"
 #include "character.h"
@@ -49,17 +44,15 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #define NULL ((POINTER_TYPE *)0)
 #endif
 
-Lisp_Object Qstring_lessp, Qprovide, Qrequire;
-Lisp_Object Qyes_or_no_p_history;
+Lisp_Object Qstring_lessp;
+static Lisp_Object Qprovide, Qrequire;
+static Lisp_Object Qyes_or_no_p_history;
 Lisp_Object Qcursor_in_echo_area;
-Lisp_Object Qwidget_type;
-Lisp_Object Qcodeset, Qdays, Qmonths, Qpaper;
+static Lisp_Object Qwidget_type;
+static Lisp_Object Qcodeset, Qdays, Qmonths, Qpaper;
 
 static int internal_equal (Lisp_Object , Lisp_Object, int, int);
 
-extern long get_random (void);
-extern void seed_random (long);
-
 #ifndef HAVE_UNISTD_H
 extern long time ();
 #endif
@@ -351,7 +344,7 @@ Symbols are also allowed; their print names are used instead.  */)
   return i1 < SCHARS (s2) ? Qt : Qnil;
 }
 \f
-static Lisp_Object concat (int nargs, Lisp_Object *args,
+static Lisp_Object concat (size_t nargs, Lisp_Object *args,
                           enum Lisp_Type target_type, int last_special);
 
 /* ARGSUSED */
@@ -381,7 +374,7 @@ The result is a list whose elements are the elements of all the arguments.
 Each argument may be a list, vector or string.
 The last argument is not copied, just used as the tail of the new list.
 usage: (append &rest SEQUENCES)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   return concat (nargs, args, Lisp_Cons, 1);
 }
@@ -391,7 +384,7 @@ DEFUN ("concat", Fconcat, Sconcat, 0, MANY, 0,
 The result is a string whose elements are the elements of all the arguments.
 Each argument may be a string or a list or vector of characters (integers).
 usage: (concat &rest SEQUENCES)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   return concat (nargs, args, Lisp_String, 0);
 }
@@ -401,7 +394,7 @@ DEFUN ("vconcat", Fvconcat, Svconcat, 0, MANY, 0,
 The result is a vector whose elements are the elements of all the arguments.
 Each argument may be a list, vector or string.
 usage: (vconcat &rest SEQUENCES)   */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   return concat (nargs, args, Lisp_Vectorlike, 0);
 }
@@ -449,7 +442,8 @@ struct textprop_rec
 };
 
 static Lisp_Object
-concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special)
+concat (size_t nargs, Lisp_Object *args,
+       enum Lisp_Type target_type, int last_special)
 {
   Lisp_Object val;
   register Lisp_Object tail;
@@ -458,7 +452,7 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
   EMACS_INT toindex_byte = 0;
   register EMACS_INT result_len;
   register EMACS_INT result_len_byte;
-  register int argnum;
+  register size_t argnum;
   Lisp_Object last_tail;
   Lisp_Object prev;
   int some_multibyte;
@@ -512,7 +506,7 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
          Lisp_Object ch;
          EMACS_INT this_len_byte;
 
-         if (VECTORP (this))
+         if (VECTORP (this) || COMPILEDP (this))
            for (i = 0; i < len; i++)
              {
                ch = AREF (this, i);
@@ -1078,7 +1072,7 @@ an error is signaled.  */)
       EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0);
 
       if (converted < chars)
-       error ("Can't convert the %dth character to unibyte", converted);
+       error ("Can't convert the %"pI"dth character to unibyte", converted);
       string = make_unibyte_string ((char *) str, chars);
       xfree (str);
     }
@@ -1249,17 +1243,10 @@ substring_both (Lisp_Object string, EMACS_INT from, EMACS_INT from_byte,
 {
   Lisp_Object res;
   EMACS_INT size;
-  EMACS_INT size_byte;
 
   CHECK_VECTOR_OR_STRING (string);
 
-  if (STRINGP (string))
-    {
-      size = SCHARS (string);
-      size_byte = SBYTES (string);
-    }
-  else
-    size = ASIZE (string);
+  size = STRINGP (string) ? SCHARS (string) : ASIZE (string);
 
   if (!(0 <= from && from <= to && to <= size))
     args_out_of_range_3 (string, make_number (from), make_number (to));
@@ -2076,14 +2063,12 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int
        /* Boolvectors are compared much like strings.  */
        if (BOOL_VECTOR_P (o1))
          {
-           int size_in_chars
-             = ((XBOOL_VECTOR (o1)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
-                / BOOL_VECTOR_BITS_PER_CHAR);
-
            if (XBOOL_VECTOR (o1)->size != XBOOL_VECTOR (o2)->size)
              return 0;
            if (memcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data,
-                       size_in_chars))
+                       ((XBOOL_VECTOR (o1)->size
+                         + BOOL_VECTOR_BITS_PER_CHAR - 1)
+                        / BOOL_VECTOR_BITS_PER_CHAR)))
              return 0;
            return 1;
          }
@@ -2136,15 +2121,15 @@ DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
 ARRAY is a vector, string, char-table, or bool-vector.  */)
   (Lisp_Object array, Lisp_Object item)
 {
-  register EMACS_INT size, index;
+  register EMACS_INT size, idx;
   int charval;
 
   if (VECTORP (array))
     {
       register Lisp_Object *p = XVECTOR (array)->contents;
       size = ASIZE (array);
-      for (index = 0; index < size; index++)
-       p[index] = item;
+      for (idx = 0; idx < size; idx++)
+       p[idx] = item;
     }
   else if (CHAR_TABLE_P (array))
     {
@@ -2180,8 +2165,8 @@ ARRAY is a vector, string, char-table, or bool-vector.  */)
            *p++ = str[i % len];
        }
       else
-       for (index = 0; index < size; index++)
-         p[index] = charval;
+       for (idx = 0; idx < size; idx++)
+         p[idx] = charval;
     }
   else if (BOOL_VECTOR_P (array))
     {
@@ -2191,14 +2176,14 @@ ARRAY is a vector, string, char-table, or bool-vector.  */)
           / BOOL_VECTOR_BITS_PER_CHAR);
 
       charval = (! NILP (item) ? -1 : 0);
-      for (index = 0; index < size_in_chars - 1; index++)
-       p[index] = charval;
-      if (index < size_in_chars)
+      for (idx = 0; idx < size_in_chars - 1; idx++)
+       p[idx] = charval;
+      if (idx < size_in_chars)
        {
          /* Mask out bits beyond the vector size.  */
          if (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR)
            charval &= (1 << (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
-         p[index] = charval;
+         p[idx] = charval;
        }
     }
   else
@@ -2235,9 +2220,9 @@ DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0,
        doc: /* Concatenate any number of lists by altering them.
 Only the last argument is not altered, and need not be a list.
 usage: (nconc &rest LISTS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
-  register int argnum;
+  register size_t argnum;
   register Lisp_Object tail, tem, val;
 
   val = tail = Qnil;
@@ -2299,7 +2284,7 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
     1) lists are not relocated and 2) the list is marked via `seq' so will not
     be freed */
 
-  if (VECTORP (seq))
+  if (VECTORP (seq) || COMPILEDP (seq))
     {
       for (i = 0; i < leni; i++)
        {
@@ -2550,7 +2535,7 @@ advisable.  */)
   return ret;
 }
 \f
-Lisp_Object Qsubfeatures;
+static Lisp_Object Qsubfeatures;
 
 DEFUN ("featurep", Ffeaturep, Sfeaturep, 1, 2, 0,
        doc: /* Return t if FEATURE is present in this Emacs.
@@ -2601,9 +2586,9 @@ particular subfeatures supported in this version of FEATURE.  */)
 
 /* List of features currently being require'd, innermost first.  */
 
-Lisp_Object require_nesting_list;
+static Lisp_Object require_nesting_list;
 
-Lisp_Object
+static Lisp_Object
 require_unwind (Lisp_Object old_value)
 {
   return require_nesting_list = old_value;
@@ -2766,7 +2751,7 @@ DEFUN ("widget-apply", Fwidget_apply, Swidget_apply, 2, MANY, 0,
        doc: /* Apply the value of WIDGET's PROPERTY to the widget itself.
 ARGS are passed as extra arguments to the function.
 usage: (widget-apply WIDGET PROPERTY &rest ARGS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   /* This function can GC. */
   Lisp_Object newargs[3];
@@ -2984,7 +2969,7 @@ into shorter lines.  */)
   SAFE_ALLOCA (encoded, char *, allength);
   encoded_length = base64_encode_1 ((char *) BYTE_POS_ADDR (ibeg),
                                    encoded, length, NILP (no_line_break),
-                                   !NILP (B_ (current_buffer, enable_multibyte_characters)));
+                                   !NILP (BVAR (current_buffer, enable_multibyte_characters)));
   if (encoded_length > allength)
     abort ();
 
@@ -3166,7 +3151,7 @@ If the region can't be decoded, signal an error and don't modify the buffer.  */
   EMACS_INT old_pos = PT;
   EMACS_INT decoded_length;
   EMACS_INT inserted_chars;
-  int multibyte = !NILP (B_ (current_buffer, enable_multibyte_characters));
+  int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
   USE_SAFE_ALLOCA;
 
   validate_region (&beg, &end);
@@ -3359,18 +3344,19 @@ base64_decode_1 (const char *from, char *to, EMACS_INT length,
 
 /* The list of all weak hash tables.  Don't staticpro this one.  */
 
-struct Lisp_Hash_Table *weak_hash_tables;
+static struct Lisp_Hash_Table *weak_hash_tables;
 
 /* Various symbols.  */
 
-Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey, Qvalue;
+static Lisp_Object Qhash_table_p, Qkey, Qvalue;
+Lisp_Object Qeq, Qeql, Qequal;
 Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
-Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;
+static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;
 
 /* Function prototypes.  */
 
 static struct Lisp_Hash_Table *check_hash_table (Lisp_Object);
-static int get_key_arg (Lisp_Object, int, Lisp_Object *, char *);
+static size_t get_key_arg (Lisp_Object, size_t, Lisp_Object *, char *);
 static void maybe_resize_hash_table (struct Lisp_Hash_Table *);
 static int cmpfn_eql (struct Lisp_Hash_Table *, Lisp_Object, unsigned,
                       Lisp_Object, unsigned);
@@ -3425,27 +3411,23 @@ next_almost_prime (int n)
 /* Find KEY in ARGS which has size NARGS.  Don't consider indices for
    which USED[I] is non-zero.  If found at index I in ARGS, set
    USED[I] and USED[I + 1] to 1, and return I + 1.  Otherwise return
-   -1.  This function is used to extract a keyword/argument pair from
+   0.  This function is used to extract a keyword/argument pair from
    a DEFUN parameter list.  */
 
-static int
-get_key_arg (Lisp_Object key, int nargs, Lisp_Object *args, char *used)
+static size_t
+get_key_arg (Lisp_Object key, size_t nargs, Lisp_Object *args, char *used)
 {
-  int i;
-
-  for (i = 0; i < nargs - 1; ++i)
-    if (!used[i] && EQ (args[i], key))
-      break;
+  size_t i;
 
-  if (i >= nargs - 1)
-    i = -1;
-  else
-    {
-      used[i++] = 1;
-      used[i] = 1;
-    }
+  for (i = 1; i < nargs; i++)
+    if (!used[i - 1] && EQ (args[i - 1], key))
+      {
+       used[i - 1] = 1;
+       used[i] = 1;
+       return i;
+      }
 
-  return i;
+  return 0;
 }
 
 
@@ -3699,9 +3681,9 @@ copy_hash_table (struct Lisp_Hash_Table *h1)
   struct Lisp_Vector *next;
 
   h2 = allocate_hash_table ();
-  next = h2->vec_next;
+  next = h2->header.next.vector;
   memcpy (h2, h1, sizeof *h2);
-  h2->vec_next = next;
+  h2->header.next.vector = next;
   h2->key_and_value = Fcopy_sequence (h1->key_and_value);
   h2->hash = Fcopy_sequence (h1->hash);
   h2->next = Fcopy_sequence (h1->next);
@@ -4044,7 +4026,7 @@ sweep_weak_hash_tables (void)
       marked = 0;
       for (h = weak_hash_tables; h; h = h->next_weak)
        {
-         if (h->size & ARRAY_MARK_FLAG)
+         if (h->header.size & ARRAY_MARK_FLAG)
            marked |= sweep_weak_table (h, 0);
        }
     }
@@ -4055,7 +4037,7 @@ sweep_weak_hash_tables (void)
     {
       next = h->next_weak;
 
-      if (h->size & ARRAY_MARK_FLAG)
+      if (h->header.size & ARRAY_MARK_FLAG)
        {
          /* TABLE is marked as used.  Sweep its contents.  */
          if (h->count > 0)
@@ -4171,7 +4153,7 @@ sxhash_bool_vector (Lisp_Object vec)
   unsigned hash = XBOOL_VECTOR (vec)->size;
   int i, n;
 
-  n = min (SXHASH_MAX_LEN, XBOOL_VECTOR (vec)->vector_size);
+  n = min (SXHASH_MAX_LEN, XBOOL_VECTOR (vec)->header.size);
   for (i = 0; i < n; ++i)
     hash = SXHASH_COMBINE (hash, XBOOL_VECTOR (vec)->data[i]);
 
@@ -4232,9 +4214,9 @@ sxhash (Lisp_Object obj, int depth)
       {
        double val = XFLOAT_DATA (obj);
        unsigned char *p = (unsigned char *) &val;
-       unsigned char *e = p + sizeof val;
-       for (hash = 0; p < e; ++p)
-         hash = SXHASH_COMBINE (hash, *p);
+       size_t i;
+       for (hash = 0, i = 0; i < sizeof val; i++)
+         hash = SXHASH_COMBINE (hash, p[i]);
        break;
       }
 
@@ -4293,12 +4275,12 @@ WEAK.  WEAK t is equivalent to `key-and-value'.  Default value of WEAK
 is nil.
 
 usage: (make-hash-table &rest KEYWORD-ARGS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   Lisp_Object test, size, rehash_size, rehash_threshold, weak;
   Lisp_Object user_test, user_hash;
   char *used;
-  int i;
+  size_t i;
 
   /* The vector `used' is used to keep track of arguments that
      have been consumed.  */
@@ -4307,7 +4289,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS)  */)
 
   /* See if there's a `:test TEST' among the arguments.  */
   i = get_key_arg (QCtest, nargs, args, used);
-  test = i < 0 ? Qeql : args[i];
+  test = i ? args[i] : Qeql;
   if (!EQ (test, Qeq) && !EQ (test, Qeql) && !EQ (test, Qequal))
     {
       /* See if it is a user-defined test.  */
@@ -4324,7 +4306,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS)  */)
 
   /* See if there's a `:size SIZE' argument.  */
   i = get_key_arg (QCsize, nargs, args, used);
-  size = i < 0 ? Qnil : args[i];
+  size = i ? args[i] : Qnil;
   if (NILP (size))
     size = make_number (DEFAULT_HASH_SIZE);
   else if (!INTEGERP (size) || XINT (size) < 0)
@@ -4332,7 +4314,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS)  */)
 
   /* Look for `:rehash-size SIZE'.  */
   i = get_key_arg (QCrehash_size, nargs, args, used);
-  rehash_size = i < 0 ? make_float (DEFAULT_REHASH_SIZE) : args[i];
+  rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE);
   if (!NUMBERP (rehash_size)
       || (INTEGERP (rehash_size) && XINT (rehash_size) <= 0)
       || XFLOATINT (rehash_size) <= 1.0)
@@ -4340,7 +4322,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS)  */)
 
   /* Look for `:rehash-threshold THRESHOLD'.  */
   i = get_key_arg (QCrehash_threshold, nargs, args, used);
-  rehash_threshold = i < 0 ? make_float (DEFAULT_REHASH_THRESHOLD) : args[i];
+  rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD);
   if (!FLOATP (rehash_threshold)
       || XFLOATINT (rehash_threshold) <= 0.0
       || XFLOATINT (rehash_threshold) > 1.0)
@@ -4348,7 +4330,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS)  */)
 
   /* Look for `:weakness WEAK'.  */
   i = get_key_arg (QCweakness, nargs, args, used);
-  weak = i < 0 ? Qnil : args[i];
+  weak = i ? args[i] : Qnil;
   if (EQ (weak, Qt))
     weak = Qkey_and_value;
   if (!NILP (weak)
@@ -4684,12 +4666,12 @@ guesswork fails.  Normally, an error is signaled in such case.  */)
            {
              int force_raw_text = 0;
 
-             coding_system = B_ (XBUFFER (object), buffer_file_coding_system);
+             coding_system = BVAR (XBUFFER (object), buffer_file_coding_system);
              if (NILP (coding_system)
                  || NILP (Flocal_variable_p (Qbuffer_file_coding_system, Qnil)))
                {
                  coding_system = Qnil;
-                 if (NILP (B_ (current_buffer, enable_multibyte_characters)))
+                 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
                    force_raw_text = 1;
                }
 
@@ -4706,11 +4688,11 @@ guesswork fails.  Normally, an error is signaled in such case.  */)
                }
 
              if (NILP (coding_system)
-                 && !NILP (B_ (XBUFFER (object), buffer_file_coding_system)))
+                 && !NILP (BVAR (XBUFFER (object), buffer_file_coding_system)))
                {
                  /* If we still have not decided a coding system, use the
                     default value of buffer-file-coding-system.  */
-                 coding_system = B_ (XBUFFER (object), buffer_file_coding_system);
+                 coding_system = BVAR (XBUFFER (object), buffer_file_coding_system);
                }
 
              if (!force_raw_text