* movemail.c:
[bpt/emacs.git] / src / fns.c
index c75c4d6..aee268f 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -1,13 +1,13 @@
 /* Random utility Lisp functions.
    Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997,
                  1998, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007 Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -1451,7 +1451,7 @@ The value is actually the tail of LIST whose car is ELT.  */)
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NILP (tail); tail = XCDR (tail))
+  for (tail = list; CONSP (tail); tail = XCDR (tail))
     {
       register Lisp_Object tem;
       CHECK_LIST_CONS (tail, list);
@@ -1502,7 +1502,7 @@ The value is actually the tail of LIST whose car is ELT.  */)
   if (!FLOATP (elt))
     return Fmemq (elt, list);
 
-  for (tail = list; !NILP (tail); tail = XCDR (tail))
+  for (tail = list; CONSP (tail); tail = XCDR (tail))
     {
       register Lisp_Object tem;
       CHECK_LIST_CONS (tail, list);
@@ -1806,7 +1806,7 @@ to be sure of changing the value of `foo'.  */)
     {
       Lisp_Object tail, prev;
 
-      for (tail = seq, prev = Qnil; !NILP (tail); tail = XCDR (tail))
+      for (tail = seq, prev = Qnil; CONSP (tail); tail = XCDR (tail))
        {
          CHECK_LIST_CONS (tail, seq);
 
@@ -2060,7 +2060,7 @@ The PLIST is modified by side effects.  */)
       prev = tail;
       QUIT;
     }
-  newcell = Fcons (prop, Fcons (val, Qnil));
+  newcell = Fcons (prop, Fcons (val, NILP (prev) ? plist : XCDR (XCDR (prev))));
   if (NILP (prev))
     return newcell;
   else
@@ -2440,7 +2440,8 @@ Return PARENT.  PARENT must be either nil or another char-table.  */)
     {
       CHECK_CHAR_TABLE (parent);
 
-      for (temp = parent; !NILP (temp); temp = XCHAR_TABLE (temp)->parent)
+      for (temp = parent; CHAR_TABLE_P (temp);
+          temp = XCHAR_TABLE (temp)->parent)
        if (EQ (temp, char_table))
          error ("Attempt to make a chartable be its own parent");
     }
@@ -2825,8 +2826,8 @@ DEFUN ("optimize-char-table", Foptimize_char_table, Soptimize_char_table,
 void
 map_char_table (c_function, function, table, subtable, arg, depth, indices)
      void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
-     Lisp_Object function, table, subtable, arg, *indices;
-     int depth;
+     Lisp_Object function, table, subtable, arg;
+     int depth, *indices;
 {
   int i, to;
   struct gcpro gcpro1, gcpro2,  gcpro3, gcpro4;
@@ -2860,7 +2861,7 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
     }
   else
     {
-      int charset = XFASTINT (indices[0]) - 128;
+      int charset = indices[0] - 128;
 
       i = 32;
       to = SUB_CHAR_TABLE_ORDINARY_SLOTS;
@@ -2874,8 +2875,8 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
       int charset;
 
       elt = XCHAR_TABLE (subtable)->contents[i];
-      XSETFASTINT (indices[depth], i);
-      charset = XFASTINT (indices[0]) - 128;
+      indices[depth] = i;
+      charset = indices[0] - 128;
       if (depth == 0
          && (!CHARSET_DEFINED_P (charset)
              || charset == CHARSET_8_BIT_CONTROL
@@ -2892,8 +2893,8 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
        {
          int c1, c2, c;
 
-         c1 = depth >= 1 ? XFASTINT (indices[1]) : 0;
-         c2 = depth >= 2 ? XFASTINT (indices[2]) : 0;
+         c1 = depth >= 1 ? indices[1] : 0;
+         c2 = depth >= 2 ? indices[2] : 0;
          c = MAKE_CHAR (charset, c1, c2);
 
          if (NILP (elt))
@@ -2927,14 +2928,14 @@ The key is always a possible IDX argument to `aref'.  */)
      Lisp_Object function, char_table;
 {
   /* The depth of char table is at most 3. */
-  Lisp_Object indices[3];
+  int indices[3];
 
   CHECK_CHAR_TABLE (char_table);
 
   /* When Lisp_Object is represented as a union, `call2' cannot directly
      be passed to map_char_table because it returns a Lisp_Object rather
      than returning nothing.
-     Casting leads to crashes on some architectures.  -stef  */
+     Casting leads to crashes on some architectures.  --Stef  */
   map_char_table (void_call2, Qnil, char_table, char_table, function, 0, indices);
   return Qnil;
 }
@@ -3134,7 +3135,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string.  */)
   len = Flength (sequence);
   leni = XINT (len);
   nargs = leni + leni - 1;
-  if (nargs < 0) return build_string ("");
+  if (nargs < 0) return empty_unibyte_string;
 
   SAFE_ALLOCA_LISP (args, nargs);
 
@@ -4271,7 +4272,7 @@ base64_decode_1 (from, to, length, multibyte, nchars_return)
 
 /* The list of all weak hash tables.  Don't staticpro this one.  */
 
-Lisp_Object Vweak_hash_tables;
+struct Lisp_Hash_Table *weak_hash_tables;
 
 /* Various symbols.  */
 
@@ -4598,7 +4599,7 @@ make_hash_table (test, size, rehash_size, rehash_threshold, weak,
   h->weak = weak;
   h->rehash_threshold = rehash_threshold;
   h->rehash_size = rehash_size;
-  h->count = make_number (0);
+  h->count = 0;
   h->key_and_value = Fmake_vector (make_number (2 * sz), Qnil);
   h->hash = Fmake_vector (size, Qnil);
   h->next = Fmake_vector (size, Qnil);
@@ -4617,11 +4618,11 @@ make_hash_table (test, size, rehash_size, rehash_threshold, weak,
 
   /* Maybe add this hash table to the list of all weak hash tables.  */
   if (NILP (h->weak))
-    h->next_weak = Qnil;
+    h->next_weak = NULL;
   else
     {
-      h->next_weak = Vweak_hash_tables;
-      Vweak_hash_tables = table;
+      h->next_weak = weak_hash_tables;
+      weak_hash_tables = h;
     }
 
   return table;
@@ -4652,8 +4653,8 @@ copy_hash_table (h1)
   /* Maybe add this hash table to the list of all weak hash tables.  */
   if (!NILP (h2->weak))
     {
-      h2->next_weak = Vweak_hash_tables;
-      Vweak_hash_tables = table;
+      h2->next_weak = weak_hash_tables;
+      weak_hash_tables = h2;
     }
 
   return table;
@@ -4778,7 +4779,7 @@ hash_put (h, key, value, hash)
 
   /* Increment count after resizing because resizing may fail.  */
   maybe_resize_hash_table (h);
-  h->count = make_number (XFASTINT (h->count) + 1);
+  h->count++;
 
   /* Store key/value in the key_and_value vector.  */
   i = XFASTINT (h->next_free);
@@ -4834,8 +4835,8 @@ hash_remove (h, key)
          HASH_KEY (h, i) = HASH_VALUE (h, i) = HASH_HASH (h, i) = Qnil;
          HASH_NEXT (h, i) = h->next_free;
          h->next_free = make_number (i);
-         h->count = make_number (XFASTINT (h->count) - 1);
-         xassert (XINT (h->count) >= 0);
+         h->count--;
+         xassert (h->count >= 0);
          break;
        }
       else
@@ -4853,7 +4854,7 @@ void
 hash_clear (h)
      struct Lisp_Hash_Table *h;
 {
-  if (XFASTINT (h->count) > 0)
+  if (h->count > 0)
     {
       int i, size = HASH_TABLE_SIZE (h);
 
@@ -4869,7 +4870,7 @@ hash_clear (h)
        AREF (h->index, i) = Qnil;
 
       h->next_free = make_number (0);
-      h->count = make_number (0);
+      h->count = 0;
     }
 }
 
@@ -4939,7 +4940,7 @@ sweep_weak_table (h, remove_entries_p)
                  HASH_KEY (h, i) = HASH_VALUE (h, i) = Qnil;
                  HASH_HASH (h, i) = Qnil;
 
-                 h->count = make_number (XFASTINT (h->count) - 1);
+                 h->count--;
                }
              else
                {
@@ -4972,13 +4973,12 @@ sweep_weak_table (h, remove_entries_p)
 
 /* Remove elements from weak hash tables that don't survive the
    current garbage collection.  Remove weak tables that don't survive
-   from Vweak_hash_tables.  Called from gc_sweep.  */
+   from weak_hash_tables.  Called from gc_sweep.  */
 
 void
 sweep_weak_hash_tables ()
 {
-  Lisp_Object table, used, next;
-  struct Lisp_Hash_Table *h;
+  struct Lisp_Hash_Table *h, *used, *next;
   int marked;
 
   /* Mark all keys and values that are in use.  Keep on marking until
@@ -4990,9 +4990,8 @@ sweep_weak_hash_tables ()
   do
     {
       marked = 0;
-      for (table = Vweak_hash_tables; !GC_NILP (table); table = h->next_weak)
+      for (h = weak_hash_tables; h; h = h->next_weak)
        {
-         h = XHASH_TABLE (table);
          if (h->size & ARRAY_MARK_FLAG)
            marked |= sweep_weak_table (h, 0);
        }
@@ -5000,24 +4999,23 @@ sweep_weak_hash_tables ()
   while (marked);
 
   /* Remove tables and entries that aren't used.  */
-  for (table = Vweak_hash_tables, used = Qnil; !GC_NILP (table); table = next)
+  for (h = weak_hash_tables, used = NULL; h; h = next)
     {
-      h = XHASH_TABLE (table);
       next = h->next_weak;
 
       if (h->size & ARRAY_MARK_FLAG)
        {
          /* TABLE is marked as used.  Sweep its contents.  */
-         if (XFASTINT (h->count) > 0)
+         if (h->count > 0)
            sweep_weak_table (h, 1);
 
          /* Add table to the list of used weak hash tables.  */
          h->next_weak = used;
-         used = table;
+         used = h;
        }
     }
 
-  Vweak_hash_tables = used;
+  weak_hash_tables = used;
 }
 
 
@@ -5215,7 +5213,7 @@ DEFUN ("sxhash", Fsxhash, Ssxhash, 1, 1, 0,
      (obj)
      Lisp_Object obj;
 {
-  unsigned hash = sxhash (obj, 0);;
+  unsigned hash = sxhash (obj, 0);
   return make_number (hash);
 }
 
@@ -5343,7 +5341,7 @@ DEFUN ("hash-table-count", Fhash_table_count, Shash_table_count, 1, 1, 0,
      (table)
      Lisp_Object table;
 {
-  return check_hash_table (table)->count;
+  return make_number (check_hash_table (table)->count);
 }
 
 
@@ -5561,7 +5559,7 @@ guesswork fails.  Normally, an error is signaled in such case.  */)
 
          if (STRING_MULTIBYTE (object))
            /* use default, we can't guess correct value */
-           coding_system = SYMBOL_VALUE (XCAR (Vcoding_category_list));
+           coding_system = find_symbol_value (XCAR (Vcoding_category_list));
          else
            coding_system = Qraw_text;
        }
@@ -5918,7 +5916,7 @@ used if both `use-dialog-box' and this variable are non-nil.  */);
 void
 init_fns ()
 {
-  Vweak_hash_tables = Qnil;
+  weak_hash_tables = NULL;
 }
 
 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31