]> code.delx.au - gnu-emacs/blobdiff - src/fns.c
Merged in changes from CVS trunk.
[gnu-emacs] / src / fns.c
index 693f3eaaa934130a4abade1aaf8d01c240faddcf..b163223803c7a91f7b4caa1eed6ebd0aa713afe9 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -26,8 +26,8 @@ Boston, MA 02111-1307, USA.  */
 #endif
 #include <time.h>
 
-#ifndef MAC_OSX
-/* On Mac OS X, defining this conflicts with precompiled headers.  */
+#ifndef MAC_OS
+/* On Mac OS, defining this conflicts with precompiled headers.  */
 
 /* Note on some machines this defines `vector' as a typedef,
    so make sure we don't use that name in this file.  */
@@ -562,6 +562,7 @@ concat (nargs, args, target_type, last_special)
   struct textprop_rec  *textprops = NULL;
   /* Number of elments in textprops.  */
   int num_textprops = 0;
+  USE_SAFE_ALLOCA;
 
   tail = Qnil;
 
@@ -670,8 +671,7 @@ concat (nargs, args, target_type, last_special)
 
   prev = Qnil;
   if (STRINGP (val))
-    textprops
-      = (struct textprop_rec *) alloca (sizeof (struct textprop_rec) * nargs);
+    SAFE_ALLOCA (textprops, struct textprop_rec *, sizeof (struct textprop_rec) * nargs);
 
   for (argnum = 0; argnum < nargs; argnum++)
     {
@@ -741,7 +741,7 @@ concat (nargs, args, target_type, last_special)
                  }
                else
                  {
-                   XSETFASTINT (elt, SREF (this, thisindex++));
+                   XSETFASTINT (elt, SREF (this, thisindex)); thisindex++;
                    if (some_multibyte
                        && (XINT (elt) >= 0240
                            || (XINT (elt) >= 0200
@@ -827,6 +827,8 @@ concat (nargs, args, target_type, last_special)
          last_to_end = textprops[argnum].to + SCHARS (this);
        }
     }
+
+  SAFE_FREE ();
   return val;
 }
 \f
@@ -1012,7 +1014,7 @@ string_make_multibyte (string)
             0, 1);
 
   ret = make_multibyte_string (buf, SCHARS (string), nbytes);
-  SAFE_FREE (nbytes);
+  SAFE_FREE ();
 
   return ret;
 }
@@ -1046,7 +1048,7 @@ string_to_multibyte (string)
   str_to_multibyte (buf, nbytes, SBYTES (string));
 
   ret = make_multibyte_string (buf, SCHARS (string), nbytes);
-  SAFE_FREE (nbytes);
+  SAFE_FREE ();
 
   return ret;
 }
@@ -1073,7 +1075,7 @@ string_make_unibyte (string)
             1, 0);
 
   ret = make_unibyte_string (buf, nchars);
-  SAFE_FREE (nchars);
+  SAFE_FREE ();
 
   return ret;
 }
@@ -1997,6 +1999,35 @@ one of the properties on the list.  */)
   return Qnil;
 }
 
+DEFUN ("safe-plist-get", Fsafe_plist_get, Ssafe_plist_get, 2, 2, 0,
+       doc: /* Extract a value from a property list.
+PLIST is a property list, which is a list of the form
+\(PROP1 VALUE1 PROP2 VALUE2...).  This function returns the value
+corresponding to the given PROP, or nil if PROP is not
+one of the properties on the list.
+This function never signals an error.  */)
+     (plist, prop)
+     Lisp_Object plist;
+     Lisp_Object prop;
+{
+  Lisp_Object tail, halftail;
+
+  /* halftail is used to detect circular lists.  */
+  tail = halftail = plist;
+  while (CONSP (tail) && CONSP (XCDR (tail)))
+    {
+      if (EQ (prop, XCAR (tail)))
+       return XCAR (XCDR (tail));
+
+      tail = XCDR (XCDR (tail));
+      halftail = XCDR (halftail);
+      if (EQ (tail, halftail))
+       break;
+    }
+
+  return Qnil;
+}
+
 DEFUN ("get", Fget, Sget, 2, 2, 0,
        doc: /* Return the value of SYMBOL's PROPNAME property.
 This is the last value stored with `(put SYMBOL PROPNAME VALUE)'.  */)
@@ -2370,7 +2401,9 @@ This makes STRING unibyte and may change its length.  */)
      (string)
      Lisp_Object string;
 {
-  int len = SBYTES (string);
+  int len;
+  CHECK_STRING (string);
+  len = SBYTES (string);
   bzero (SDATA (string), len);
   STRING_SET_CHARS (string, len);
   STRING_SET_UNIBYTE (string);
@@ -2703,6 +2736,9 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
      int depth;
 {
   int i, to;
+  struct gcpro gcpro1, gcpro2,  gcpro3, gcpro4;
+
+  GCPRO4 (arg, table, subtable, function);
 
   if (depth == 0)
     {
@@ -2722,7 +2758,10 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
 #if 0 /* If the char table has entries for higher characters,
         we should report them.  */
       if (NILP (current_buffer->enable_multibyte_characters))
-       return;
+       {
+         UNGCPRO;
+         return;
+       }
 #endif
       to = CHAR_TABLE_ORDINARY_SLOTS;
     }
@@ -2775,6 +2814,7 @@ map_char_table (c_function, function, table, subtable, arg, depth, indices)
            call2 (function, make_number (c), elt);
        }
     }
+  UNGCPRO;
 }
 
 static void void_call2 P_ ((Lisp_Object a, Lisp_Object b, Lisp_Object c));
@@ -3021,7 +3061,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string.  */)
     args[i] = separator;
 
   ret = Fconcat (nargs, args);
-  SAFE_FREE_LISP (nargs);
+  SAFE_FREE ();
 
   return ret;
 }
@@ -3047,7 +3087,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string.  */)
   mapcar1 (leni, args, function, sequence);
 
   ret = Flist (leni, args);
-  SAFE_FREE_LISP (leni);
+  SAFE_FREE ();
 
   return ret;
 }
@@ -3266,7 +3306,7 @@ is nil, and `use-dialog-box' is non-nil.  */)
     {
       ans = Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil,
                                              Qyes_or_no_p_history, Qnil,
-                                             Qnil));
+                                             Qnil, Qnil));
       if (SCHARS (ans) == 3 && !strcmp (SDATA (ans), "yes"))
        {
          UNGCPRO;
@@ -3754,7 +3794,7 @@ into shorter lines.  */)
   if (encoded_length < 0)
     {
       /* The encoding wasn't possible. */
-      SAFE_FREE (allength);
+      SAFE_FREE ();
       error ("Multibyte character in data for base64 encoding");
     }
 
@@ -3762,7 +3802,7 @@ into shorter lines.  */)
      and delete the old.  (Insert first in order to preserve markers.)  */
   SET_PT_BOTH (XFASTINT (beg), ibeg);
   insert (encoded, encoded_length);
-  SAFE_FREE (allength);
+  SAFE_FREE ();
   del_range_byte (ibeg + encoded_length, iend + encoded_length, 1);
 
   /* If point was outside of the region, restore it exactly; else just
@@ -3811,12 +3851,12 @@ into shorter lines.  */)
   if (encoded_length < 0)
     {
       /* The encoding wasn't possible. */
-      SAFE_FREE (allength);
+      SAFE_FREE ();
       error ("Multibyte character in data for base64 encoding");
     }
 
   encoded_string = make_unibyte_string (encoded, encoded_length);
-  SAFE_FREE (allength);
+  SAFE_FREE ();
 
   return encoded_string;
 }
@@ -3953,7 +3993,7 @@ If the region can't be decoded, signal an error and don't modify the buffer.  */
   if (decoded_length < 0)
     {
       /* The decoding wasn't possible. */
-      SAFE_FREE (allength);
+      SAFE_FREE ();
       error ("Invalid base64 data");
     }
 
@@ -3961,7 +4001,7 @@ If the region can't be decoded, signal an error and don't modify the buffer.  */
      and delete the old.  (Insert first in order to preserve markers.)  */
   TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg);
   insert_1_both (decoded, inserted_chars, decoded_length, 0, 1, 0);
-  SAFE_FREE (allength);
+  SAFE_FREE ();
 
   /* Delete the original text.  */
   del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars,
@@ -4005,7 +4045,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
   else
     decoded_string = Qnil;
 
-  SAFE_FREE (length);
+  SAFE_FREE ();
   if (!STRINGP (decoded_string))
     error ("Invalid base64 data");
 
@@ -4998,15 +5038,14 @@ sxhash (obj, depth)
       hash = XUINT (obj);
       break;
 
-    case Lisp_Symbol:
-      hash = sxhash_string (SDATA (SYMBOL_NAME (obj)),
-                           SCHARS (SYMBOL_NAME (obj)));
-      break;
-
     case Lisp_Misc:
       hash = XUINT (obj);
       break;
 
+    case Lisp_Symbol:
+      obj = SYMBOL_NAME (obj);
+      /* Fall through.  */
+
     case Lisp_String:
       hash = sxhash_string (SDATA (obj), SCHARS (obj));
       break;
@@ -5726,6 +5765,7 @@ used if both `use-dialog-box' and this variable are non-nil.  */);
   defsubr (&Sreverse);
   defsubr (&Ssort);
   defsubr (&Splist_get);
+  defsubr (&Ssafe_plist_get);
   defsubr (&Sget);
   defsubr (&Splist_put);
   defsubr (&Sput);