emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp b3ad62f: Do not load native code when `load' is expl


From: Andrea Corallo
Subject: feature/native-comp b3ad62f: Do not load native code when `load' is explicitly called on a .elc file
Date: Fri, 19 Mar 2021 10:03:30 -0400 (EDT)

branch: feature/native-comp
commit b3ad62f8a35617366886be2a86e8641282824adf
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    Do not load native code when `load' is explicitly called on a .elc file
    
        * src/lread.c (Fload): Do not load native code when `load' is
        explicitly called on a .elc file.
        (Flocate_file_internal): Update 'openp' call sites.
        (maybe_swap_for_eln): Add new 'no_native' parameter.
        (openp): Likewise + update 'maybe_swap_for_eln' and 'openp' call
        sites.
        * src/lisp.h: Update 'openp' signature.
        * src/w32proc.c (sys_spawnve): Update 'openp' call sites.
        * src/w32.c (check_windows_init_file): Likewise.
        * src/sound.c (Fplay_sound_internal): Likewise.
        * src/process.c (Fmake_process): Likewise.
        * src/image.c (image_create_bitmap_from_file)
        (image_find_image_fd): Likewise.
        * src/emacs.c (set_invocation_vars): Likewise.
        * src/charset.c (load_charset_map_from_file): Likewise.
        * src/callproc.c (call_process): Likewise.
---
 src/callproc.c |  2 +-
 src/charset.c  |  2 +-
 src/emacs.c    |  5 +++--
 src/image.c    |  4 ++--
 src/lisp.h     |  2 +-
 src/lread.c    | 24 ++++++++++++++++--------
 src/process.c  |  2 +-
 src/sound.c    |  5 +++--
 src/w32.c      |  3 ++-
 src/w32proc.c  |  3 ++-
 10 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/callproc.c b/src/callproc.c
index cd0f67f..5aa2cba 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -457,7 +457,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int 
filefd,
     int ok;
 
     ok = openp (Vexec_path, args[0], Vexec_suffixes, &path,
-               make_fixnum (X_OK), false);
+               make_fixnum (X_OK), false, false);
     if (ok < 0)
       report_file_error ("Searching for program", args[0]);
   }
diff --git a/src/charset.c b/src/charset.c
index eb388d1..7cd0fa7 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -486,7 +486,7 @@ load_charset_map_from_file (struct charset *charset, 
Lisp_Object mapfile,
   ptrdiff_t count = SPECPDL_INDEX ();
   record_unwind_protect_nothing ();
   specbind (Qfile_name_handler_alist, Qnil);
-  fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, false);
+  fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, false, false);
   fp = fd < 0 ? 0 : fdopen (fd, "r");
   if (!fp)
     {
diff --git a/src/emacs.c b/src/emacs.c
index ec62c19..d353679 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -468,8 +468,9 @@ set_invocation_vars (char *argv0, char const *original_pwd)
   if (NILP (Vinvocation_directory))
     {
       Lisp_Object found;
-      int yes = openp (Vexec_path, Vinvocation_name,
-                      Vexec_suffixes, &found, make_fixnum (X_OK), false);
+      int yes =
+       openp (Vexec_path, Vinvocation_name, Vexec_suffixes, &found,
+              make_fixnum (X_OK), false, false);
       if (yes == 1)
        {
          /* Add /: to the front of the name
diff --git a/src/image.c b/src/image.c
index 6d493f6..2f85e30 100644
--- a/src/image.c
+++ b/src/image.c
@@ -519,7 +519,7 @@ image_create_bitmap_from_file (struct frame *f, Lisp_Object 
file)
 
   /* Search bitmap-file-path for the file, if appropriate.  */
   if (openp (Vx_bitmap_file_path, file, Qnil, &found,
-            make_fixnum (R_OK), false)
+            make_fixnum (R_OK), false, false)
       < 0)
     return -1;
 
@@ -3128,7 +3128,7 @@ image_find_image_fd (Lisp_Object file, int *pfd)
 
   /* Try to find FILE in data-directory/images, then x-bitmap-file-path.  */
   fd = openp (search_path, file, Qnil, &file_found,
-             pfd ? Qt : make_fixnum (R_OK), false);
+             pfd ? Qt : make_fixnum (R_OK), false, false);
   if (fd >= 0 || fd == -2)
     {
       file_found = ENCODE_FILE (file_found);
diff --git a/src/lisp.h b/src/lisp.h
index fcdf8e2..4004b53 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4087,7 +4087,7 @@ extern bool suffix_p (Lisp_Object, const char *);
 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);
+                  Lisp_Object *, Lisp_Object, bool, bool);
 enum { S2N_IGNORE_TRAILING = 1 };
 extern Lisp_Object string_to_number (char const *, int, ptrdiff_t *);
 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
diff --git a/src/lread.c b/src/lread.c
index 989b55c..3bf3150 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1240,6 +1240,8 @@ Return t if the file exists and loads successfully.  */)
   else
     file = Fsubstitute_in_file_name (file);
 
+  bool no_native = suffix_p (file, ".elc");
+
   /* Avoid weird lossage with null string as arg,
      since it would try to load a directory as a Lisp file.  */
   if (SCHARS (file) == 0)
@@ -1280,7 +1282,9 @@ Return t if the file exists and loads successfully.  */)
            suffixes = CALLN (Fappend, suffixes, Vload_file_rep_suffixes);
        }
 
-      fd = openp (Vload_path, file, suffixes, &found, Qnil, load_prefer_newer);
+      fd =
+       openp (Vload_path, file, suffixes, &found, Qnil, load_prefer_newer,
+              no_native);
     }
 
   if (fd == -1)
@@ -1635,7 +1639,7 @@ directories, make sure the PREDICATE function returns 
`dir-ok' for them.  */)
   (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object 
predicate)
 {
   Lisp_Object file;
-  int fd = openp (path, filename, suffixes, &file, predicate, false);
+  int fd = openp (path, filename, suffixes, &file, predicate, false, false);
   if (NILP (predicate) && fd >= 0)
     emacs_close (fd);
   return file;
@@ -1645,12 +1649,13 @@ directories, make sure the PREDICATE function returns 
`dir-ok' for them.  */)
    If found replace the content of FILENAME and FD. */
 
 static void
-maybe_swap_for_eln (Lisp_Object *filename, int *fd)
+maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd)
 {
 #ifdef HAVE_NATIVE_COMP
   struct stat eln_st;
 
-  if (load_no_native
+  if (no_native
+      || load_no_native
       || !suffix_p (*filename, ".elc"))
     return;
 
@@ -1714,11 +1719,14 @@ maybe_swap_for_eln (Lisp_Object *filename, int *fd)
 
    If NEWER is true, try all SUFFIXes and return the result for the
    newest file that exists.  Does not apply to remote files,
-   or if a non-nil and non-t PREDICATE is specified.  */
+   or if a non-nil and non-t PREDICATE is specified.
+
+   if NO_NATIVE is true do not try to load native code.  */
 
 int
 openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
-       Lisp_Object *storeptr, Lisp_Object predicate, bool newer)
+       Lisp_Object *storeptr, Lisp_Object predicate, bool newer,
+       bool no_native)
 {
   ptrdiff_t fn_size = 100;
   char buf[100];
@@ -1928,7 +1936,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
                  }
                else
                  {
-                   maybe_swap_for_eln (&string, &fd);
+                   maybe_swap_for_eln (no_native, &string, &fd);
                    /* We succeeded; return this descriptor and filename.  */
                    if (storeptr)
                      *storeptr = string;
@@ -1940,7 +1948,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
            /* No more suffixes.  Return the newest.  */
            if (0 <= save_fd && ! CONSP (XCDR (tail)))
              {
-               maybe_swap_for_eln (&save_string, &save_fd);
+               maybe_swap_for_eln (no_native, &save_string, &save_fd);
                if (storeptr)
                  *storeptr = save_string;
                SAFE_FREE ();
diff --git a/src/process.c b/src/process.c
index b98bc29..84e301a 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1936,7 +1936,7 @@ usage: (make-process &rest ARGS)  */)
        {
          tem = Qnil;
          openp (Vexec_path, program, Vexec_suffixes, &tem,
-                make_fixnum (X_OK), false);
+                make_fixnum (X_OK), false, false);
          if (NILP (tem))
            report_file_error ("Searching for program", program);
          tem = Fexpand_file_name (tem, Qnil);
diff --git a/src/sound.c b/src/sound.c
index e5f66f8..9041076 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1370,8 +1370,9 @@ Internal use only, use `play-sound' instead.  */)
   if (STRINGP (attrs[SOUND_FILE]))
     {
       /* Open the sound file.  */
-      current_sound->fd = openp (list1 (Vdata_directory),
-                                attrs[SOUND_FILE], Qnil, &file, Qnil, false);
+      current_sound->fd =
+       openp (list1 (Vdata_directory), attrs[SOUND_FILE], Qnil, &file, Qnil,
+              false, false);
       if (current_sound->fd < 0)
        sound_perror ("Could not open sound file");
 
diff --git a/src/w32.c b/src/w32.c
index 14b8b11..467e6cb 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -10255,7 +10255,8 @@ check_windows_init_file (void)
         need to ENCODE_FILE here, but we do need to convert the file
         names from UTF-8 to ANSI.  */
       init_file = build_string ("term/w32-win");
-      fd = openp (Vload_path, init_file, Fget_load_suffixes (), NULL, Qnil, 0);
+      fd =
+       openp (Vload_path, init_file, Fget_load_suffixes (), NULL, Qnil, 0, 0);
       if (fd < 0)
        {
          Lisp_Object load_path_print = Fprin1_to_string (Vload_path, Qnil);
diff --git a/src/w32proc.c b/src/w32proc.c
index a50c877..ffa56e1 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1918,7 +1918,8 @@ sys_spawnve (int mode, char *cmdname, char **argv, char 
**envp)
     {
       program = build_string (cmdname);
       full = Qnil;
-      openp (Vexec_path, program, Vexec_suffixes, &full, make_fixnum (X_OK), 
0);
+      openp (Vexec_path, program, Vexec_suffixes, &full, make_fixnum (X_OK),
+            0, 0);
       if (NILP (full))
        {
          errno = EINVAL;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]