]> git.eshelyaron.com Git - emacs.git/commitdiff
Do not alter match data in Fcapitalize etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 9 Jul 2019 20:10:27 +0000 (13:10 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 9 Jul 2019 20:11:45 +0000 (13:11 -0700)
Without this patch, (capitalize "x") can alter the match data,
which is not what users expect.  Problem found by running
morse-tests-unnato-region in a stripped-down Emacs.
Perhaps ‘load’ should also save and restore the match data?
That would be a simpler fix, though arguably incompatible.
* src/lread.c (save_match_data_load): New function.
* src/chartab.c (uniprop_table):
* src/doc.c (reread_doc_file):
* src/eval.c (Fautoload_do_load):
* src/fns.c (Frequire): Use it.

src/chartab.c
src/doc.c
src/eval.c
src/fns.c
src/lisp.h
src/lread.c

index bf8e34b2529dd1883c73b12f5fe879228949ed39..04205ac1032ad25295748b71e0f5e709c136d997 100644 (file)
@@ -1288,7 +1288,7 @@ uniprop_table (Lisp_Object prop)
   if (STRINGP (table))
     {
       AUTO_STRING (intl, "international/");
-      result = Fload (concat2 (intl, table), Qt, Qt, Qt, Qt);
+      result = save_match_data_load (concat2 (intl, table), Qt, Qt, Qt, Qt);
       if (NILP (result))
        return Qnil;
       table = XCDR (val);
index 8875360d6e60a882cfb1101dfd6e9b582850b4c9..8b663f0f2498d76b72aabb13cf1aa4daa45ab9db 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -302,7 +302,7 @@ reread_doc_file (Lisp_Object file)
   if (NILP (file))
     Fsnarf_documentation (Vdoc_file_name);
   else
-    Fload (file, Qt, Qt, Qt, Qnil);
+    save_match_data_load (file, Qt, Qt, Qt, Qnil);
 
   return 1;
 }
index 8f569949036b10681ecb2f35ac92f775ccf93348..02a6c3555a97dc1cb46af80e017a4ecb7f1cb806 100644 (file)
@@ -2049,9 +2049,6 @@ it defines a macro.  */)
 
   CHECK_SYMBOL (funname);
 
-  /* Preserve the match data.  */
-  record_unwind_save_match_data ();
-
   /* If autoloading gets an error (which includes the error of failing
      to define the function being called), we use Vautoload_queue
      to undo function definitions and `provide' calls made by
@@ -2067,7 +2064,7 @@ it defines a macro.  */)
      so don't signal an error if autoloading fails.  */
   Lisp_Object ignore_errors
     = (EQ (kind, Qt) || EQ (kind, Qmacro)) ? Qnil : macro_only;
-  Fload (Fcar (Fcdr (fundef)), ignore_errors, Qt, Qnil, Qt);
+  save_match_data_load (Fcar (Fcdr (fundef)), ignore_errors, Qt, Qnil, Qt);
 
   /* Once loading finishes, don't undo it.  */
   Vautoload_queue = Qt;
index 77c0b15037f998b4a7e0f568505081d13f8e0ef5..11f5dddc858f7f67673beaa4193fc22ccf0f81b2 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -2984,8 +2984,9 @@ suppressed.  */)
       Vautoload_queue = Qt;
 
       /* Load the file.  */
-      tem = Fload (NILP (filename) ? Fsymbol_name (feature) : filename,
-                  noerror, Qt, Qnil, (NILP (filename) ? Qt : Qnil));
+      tem = save_match_data_load
+       (NILP (filename) ? Fsymbol_name (feature) : filename,
+        noerror, Qt, Qnil, (NILP (filename) ? Qt : Qnil));
 
       /* If load failed entirely, return nil.  */
       if (NILP (tem))
index 8acf63fe22715c64b792f5c2e2cf60160d823fda..fa57cad8a6000709d8da61ad208aa518195cb713 100644 (file)
@@ -4019,6 +4019,8 @@ LOADHIST_ATTACH (Lisp_Object x)
   if (initialized)
     Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
 }
+extern Lisp_Object save_match_data_load (Lisp_Object, Lisp_Object, Lisp_Object,
+                                        Lisp_Object, Lisp_Object);
 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
                   Lisp_Object *, Lisp_Object, bool);
 enum { S2N_IGNORE_TRAILING = 1 };
index e06eafcf6cf24e12657e2a7f8c514e66dd207b92..3152fcf867de0f0b26bcc4835163102e53290396 100644 (file)
@@ -1508,6 +1508,17 @@ Return t if the file exists and loads successfully.  */)
 
   return Qt;
 }
+
+Lisp_Object
+save_match_data_load (Lisp_Object file, Lisp_Object noerror,
+                     Lisp_Object nomessage, Lisp_Object nosuffix,
+                     Lisp_Object must_suffix)
+{
+  ptrdiff_t count = SPECPDL_INDEX ();
+  record_unwind_save_match_data ();
+  Lisp_Object result = Fload (file, noerror, nomessage, nosuffix, must_suffix);
+  return unbind_to (count, result);
+}
 \f
 static bool
 complete_filename_p (Lisp_Object pathname)