From: "Nicolas Bértolo" <nicolasbertolo@gmail.com>
To: Andrea Corallo <akrl@sdf.org>
Cc: 41242@debbugs.gnu.org
Subject: bug#41242: Port feature/native-comp to Windows - Reduce the number of files probed when finding a lisp file.
Date: Sun, 31 May 2020 12:34:16 -0300 [thread overview]
Message-ID: <CAFnS-Omg7pp2yTqHx8P3VBf75A-ybb+HM4dKmUD0dGquV2QY=w@mail.gmail.com> (raw)
In-Reply-To: <xjfd06lmrul.fsf@sdf.org>
[-- Attachment #1: Type: text/plain, Size: 844 bytes --]
Hi Andrea,
> I could not compile this patch because non all the calls to openp has
> been updated for the new parameter (my question on adding this stands).
Sorry. I didn't check the GNU/Linux build.
> In general please recall to check the stock build when working on
> infrastructure integration, it's quite easy to break.
I have tested that this new patch builds and bootstraps in windows x64,
Ubuntu 18.04 amd64. Both with and without nativecomp.
> Generally speaking I think the behavior we want to have is that when a
> .eln file is specified this is loaded without re-adding
> Vcomp_native_path_postfix. I could not test it but I suspect this is
> not handled.
I tested moving company.eln to a directory in load-path without
`comp-native-path-postfix` and then ran (load "company.eln") and it was
loaded from that directory.
Nico.
[-- Attachment #2: 0001-Reduce-the-number-of-files-probed-when-finding-a-lis.patch --]
[-- Type: application/octet-stream, Size: 10669 bytes --]
From d659a8a7ed9918d7a77655109abc6db5338ac354 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=A1s=20B=C3=A9rtolo?= <nicolasbertolo@gmail.com>
Date: Mon, 25 May 2020 18:05:23 -0300
Subject: [PATCH] Reduce the number of files probed when finding a lisp file.
* src/lread.c (get-load-suffixes): Do not add any suffix to files that
need to be loaded by the dynamic linker.
(effective_load_path): Remove function.
(load): Don't add any suffix if file ends in a suffix already.
(effective_load_path): Remove function.
(openp_add_middle_dir_to_suffixes): Add helper function to create
pairs of middle directories and suffixes.
(openp_max_middledir_and_suffix_len): Add helper function to count the
number of bytes needed to store the middle directory and suffix.
(openp_fill_filename_buffer): Add helper function to copy middle
directory, basename and suffix to the filename buffer.
---
src/lread.c | 203 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 154 insertions(+), 49 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index 9f849eda42..c6666e4ea3 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1056,31 +1056,25 @@ DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
{
Lisp_Object exts = Vload_file_rep_suffixes;
Lisp_Object suffix = XCAR (suffixes);
- FOR_EACH_TAIL (exts)
- lst = Fcons (concat2 (suffix, XCAR (exts)), lst);
- }
- return Fnreverse (lst);
-}
+ bool native_code_suffix = (NATIVE_COMP_FLAG
+ && strcmp (NATIVE_ELISP_SUFFIX, SSDATA (suffix)) == 0);
-static Lisp_Object
-effective_load_path (void)
-{
-#ifndef HAVE_NATIVE_COMP
- return Vload_path;
-#else
- Lisp_Object lp = Vload_path;
- Lisp_Object new_lp = Qnil;
- FOR_EACH_TAIL (lp)
- {
- Lisp_Object el = XCAR (lp);
- new_lp =
- Fcons (concat2 (Ffile_name_as_directory (el),
- Vcomp_native_path_postfix),
- new_lp);
- new_lp = Fcons (el, new_lp);
- }
- return Fnreverse (new_lp);
+#ifdef HAVE_MODULES
+ native_code_suffix = native_code_suffix
+ || strcmp (MODULES_SUFFIX, SSDATA (suffix)) == 0;
+#ifdef MODULES_SECONDARY_SUFFIX
+ native_code_suffix = native_code_suffix
+ || strcmp (MODULES_SECONDARY_SUFFIX, SSDATA (suffix)) == 0;
+#endif
#endif
+
+ if (native_code_suffix)
+ lst = Fcons (suffix, lst);
+ else
+ FOR_EACH_TAIL (exts)
+ lst = Fcons (concat2 (suffix, XCAR (exts)), lst);
+ }
+ return Fnreverse (lst);
}
/* Return true if STRING ends with SUFFIX. */
@@ -1218,7 +1212,7 @@ DEFUN ("load", Fload, Sload, 1, 5, 0,
|| suffix_p (file, MODULES_SECONDARY_SUFFIX)
#endif
#endif
- )
+ || (NATIVE_COMP_FLAG && suffix_p (file, NATIVE_ELISP_SUFFIX)))
must_suffix = Qnil;
/* Don't insist on adding a suffix
if the argument includes a directory name. */
@@ -1236,8 +1230,7 @@ DEFUN ("load", Fload, Sload, 1, 5, 0,
}
fd =
- openp (effective_load_path (), file, suffixes, &found, Qnil,
- load_prefer_newer);
+ openp (Vload_path, file, suffixes, &found, Qnil, load_prefer_newer);
}
if (fd == -1)
@@ -1606,6 +1599,116 @@ DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2,
return file;
}
+/* This function turns a list of suffixes into a list of middle dirs
+ and suffixes. If the suffix is not NATIVE_ELISP_SUFFIX then its
+ suffix is nil and it is added to the list as is. Instead, if it
+ suffix is NATIVE_ELISP_SUFFIX then two elements are added to the
+ list. The first one has middledir equal to nil and the second uses
+ comp-native-path-postfix as middledir. This is because we'd like
+ to search for dir/foo.eln before dir/middledir/foo.eln.
+
+For example, it turns this:
+
+(".eln" ".elc" ".elc.gz" ".el" ".el.gz")
+
+ into this:
+
+((nil . ".eln")
+ (comp-native-path-postfix . ".eln")
+ (nil . ".elc")
+ (nil . ".elc.gz")
+ (nil . ".el")
+ (nil . ".el.gz"))
+*/
+static Lisp_Object
+openp_add_middle_dir_to_suffixes (Lisp_Object suffixes)
+{
+ Lisp_Object tail = suffixes;
+ Lisp_Object extended_suf = Qnil;
+ FOR_EACH_TAIL_SAFE (tail)
+ {
+#ifdef HAVE_NATIVE_COMP
+ CHECK_STRING_CAR (tail);
+ char * suf = SSDATA (XCAR (tail));
+ if (strcmp (NATIVE_ELISP_SUFFIX, suf) == 0)
+ {
+ CHECK_STRING (Vcomp_native_path_postfix);
+ /* Here we add them in the opposite order so that nreverse
+ corrects it. */
+ extended_suf = Fcons (Fcons (Qnil, XCAR (tail)), extended_suf);
+ extended_suf = Fcons (Fcons (Vcomp_native_path_postfix, XCAR (tail)),
+ extended_suf);
+ }
+ else
+#endif
+ {
+ extended_suf = Fcons (Fcons (Qnil, XCAR (tail)), extended_suf);
+ }
+ }
+
+ suffixes = Fnreverse (extended_suf);
+ return suffixes;
+}
+
+/* This function takes a list of middledirs and suffixes and returns
+ the maximum buffer space that this part of the filename will
+ need. */
+static ptrdiff_t
+openp_max_middledir_and_suffix_len (Lisp_Object middledir_and_suffixes)
+{
+ ptrdiff_t max_extra_len = 0;
+ Lisp_Object tail = middledir_and_suffixes;
+ FOR_EACH_TAIL_SAFE (tail)
+ {
+ Lisp_Object middledir_and_suffix = XCAR (tail);
+ Lisp_Object middledir = XCAR (middledir_and_suffix);
+ Lisp_Object suffix = XCDR (middledir_and_suffix);
+ ptrdiff_t len = SBYTES (suffix);
+ if (!NILP (middledir))
+ len += 2 + SBYTES (middledir); /* Add two slashes. */
+ max_extra_len = max (max_extra_len, len);
+ }
+ return max_extra_len;
+}
+
+/* This function completes the FN buffer with the middledir,
+ basenameme, and suffix. It takes the directory length in DIRNAME,
+ but it requires that it has been copied already to the start of
+ the buffer.
+
+ After this function the FN buffer will be (depending on middledir)
+ dirname/middledir/basename.suffix
+ or
+ dirname/basename.suffix
+*/
+static ptrdiff_t
+openp_fill_filename_buffer (char *fn, ptrdiff_t dirnamelen,
+ Lisp_Object basenamewext,
+ Lisp_Object middledir_and_suffix)
+{
+ Lisp_Object middledir = XCAR (middledir_and_suffix);
+ Lisp_Object suffix = XCDR (middledir_and_suffix);
+ ptrdiff_t basenamewext_len = SBYTES (basenamewext);
+ ptrdiff_t fnlen, lsuffix = SBYTES (suffix);
+ ptrdiff_t lmiddledir = 0;
+ if (!NILP (middledir))
+ {
+ /* Add 1 for the slash. */
+ lmiddledir = SBYTES (middledir) + 1;
+ memcpy (fn + dirnamelen, SDATA (middledir),
+ lmiddledir - 1);
+ fn[dirnamelen + (lmiddledir - 1)] = '/';
+ }
+
+ memcpy (fn + dirnamelen + lmiddledir, SDATA (basenamewext),
+ basenamewext_len);
+ /* Make complete filename by appending SUFFIX. */
+ memcpy (fn + dirnamelen + lmiddledir + basenamewext_len,
+ SDATA (suffix), lsuffix + 1);
+ fnlen = dirnamelen + lmiddledir + basenamewext_len + lsuffix;
+ return fnlen;
+}
+
/* Search for a file whose name is STR, looking in directories
in the Lisp list PATH, and trying suffixes from SUFFIX.
On success, return a file descriptor (or 1 or -2 as described below).
@@ -1643,7 +1746,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
ptrdiff_t want_length;
Lisp_Object filename;
Lisp_Object string, tail, encoded_fn, save_string;
- ptrdiff_t max_suffix_len = 0;
+ Lisp_Object middledir_and_suffixes;
+ ptrdiff_t max_extra_len = 0;
int last_errno = ENOENT;
int save_fd = -1;
USE_SAFE_ALLOCA;
@@ -1654,13 +1758,9 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
CHECK_STRING (str);
- tail = suffixes;
- FOR_EACH_TAIL_SAFE (tail)
- {
- CHECK_STRING_CAR (tail);
- max_suffix_len = max (max_suffix_len,
- SBYTES (XCAR (tail)));
- }
+ middledir_and_suffixes = openp_add_middle_dir_to_suffixes (suffixes);
+
+ max_extra_len = openp_max_middledir_and_suffix_len (middledir_and_suffixes);
string = filename = encoded_fn = save_string = Qnil;
@@ -1677,7 +1777,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
executable. */
FOR_EACH_TAIL_SAFE (path)
{
- ptrdiff_t baselen, prefixlen;
+ ptrdiff_t dirnamelen, prefixlen;
if (EQ (path, just_use_str))
filename = str;
@@ -1694,35 +1794,40 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
continue;
}
+
/* Calculate maximum length of any filename made from
this path element/specified file name and any possible suffix. */
- want_length = max_suffix_len + SBYTES (filename);
+ want_length = max_extra_len + SBYTES (filename);
if (fn_size <= want_length)
{
fn_size = 100 + want_length;
fn = SAFE_ALLOCA (fn_size);
}
+ Lisp_Object dirnamewslash = Ffile_name_directory (filename);
+ Lisp_Object basenamewext = Ffile_name_nondirectory (filename);
+
/* Copy FILENAME's data to FN but remove starting /: if any. */
- prefixlen = ((SCHARS (filename) > 2
- && SREF (filename, 0) == '/'
- && SREF (filename, 1) == ':')
+ prefixlen = ((SCHARS (dirnamewslash) > 2
+ && SREF (dirnamewslash, 0) == '/'
+ && SREF (dirnamewslash, 1) == ':')
? 2 : 0);
- baselen = SBYTES (filename) - prefixlen;
- memcpy (fn, SDATA (filename) + prefixlen, baselen);
+ dirnamelen = SBYTES (dirnamewslash) - prefixlen;
+ memcpy (fn, SDATA (dirnamewslash) + prefixlen, dirnamelen);
- /* Loop over suffixes. */
- AUTO_LIST1 (empty_string_only, empty_unibyte_string);
- tail = NILP (suffixes) ? empty_string_only : suffixes;
+ /* Loop over middledir_and_suffixes. */
+ AUTO_LIST1 (empty_string_only, Fcons (Qnil, empty_unibyte_string));
+ tail = NILP (middledir_and_suffixes) ? empty_string_only
+ : middledir_and_suffixes;
FOR_EACH_TAIL_SAFE (tail)
{
- Lisp_Object suffix = XCAR (tail);
- ptrdiff_t fnlen, lsuffix = SBYTES (suffix);
+ Lisp_Object middledir_and_suffix = XCAR (tail);
+ Lisp_Object suffix = XCDR (middledir_and_suffix);
Lisp_Object handler;
- /* Make complete filename by appending SUFFIX. */
- memcpy (fn + baselen, SDATA (suffix), lsuffix + 1);
- fnlen = baselen + lsuffix;
+ ptrdiff_t fnlen = openp_fill_filename_buffer (fn, dirnamelen,
+ basenamewext,
+ middledir_and_suffix);
/* Check that the file exists and is not a directory. */
/* We used to only check for handlers on non-absolute file names:
--
2.25.1.windows.1
next prev parent reply other threads:[~2020-05-31 15:34 UTC|newest]
Thread overview: 149+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 19:26 bug#41242: Port feature/native-comp to Windows Nicolas Bértolo
2020-05-13 19:36 ` Eli Zaretskii
2020-05-13 19:39 ` Eli Zaretskii
2020-05-13 20:01 ` Nicolas Bértolo
2020-05-13 22:25 ` Andrea Corallo
2020-05-14 13:42 ` Eli Zaretskii
2020-05-13 20:08 ` Andrea Corallo
2020-05-13 20:27 ` Andrea Corallo
2020-05-13 19:56 ` Andrea Corallo
2020-05-13 20:03 ` Nicolas Bértolo
2020-05-14 10:18 ` Andrea Corallo
2020-05-14 10:45 ` Eli Zaretskii
2020-05-14 11:17 ` Andrea Corallo
2020-05-14 14:32 ` Eli Zaretskii
2020-05-14 15:03 ` Andrea Corallo
2020-05-14 16:50 ` Nicolas Bértolo
2020-05-14 17:28 ` Eli Zaretskii
2020-05-14 17:35 ` Nicolas Bértolo
2020-05-14 17:56 ` Eli Zaretskii
2020-05-14 18:00 ` Nicolas Bértolo
2020-05-14 18:29 ` Eli Zaretskii
2020-05-14 18:35 ` Andrea Corallo
2020-05-14 18:29 ` Andrea Corallo
2020-05-14 18:59 ` Achim Gratz
2020-05-14 17:34 ` Andrea Corallo
2020-05-14 17:51 ` Nicolas Bértolo
2020-05-14 18:13 ` Andrea Corallo
2020-05-14 18:40 ` Nicolas Bértolo
2020-05-14 18:48 ` Andrea Corallo
2020-05-14 19:00 ` Nicolas Bértolo
2020-05-14 19:15 ` Andrea Corallo
2020-05-14 19:48 ` Nicolas Bértolo
2020-05-14 19:58 ` Andrea Corallo
2020-05-14 20:16 ` Nicolas Bértolo
2020-05-14 20:29 ` Andrea Corallo
2020-05-14 20:34 ` Nicolas Bértolo
2020-05-15 6:10 ` Eli Zaretskii
2020-05-14 19:16 ` Eli Zaretskii
2020-05-14 19:00 ` Eli Zaretskii
2020-05-14 19:36 ` Nicolas Bértolo
2020-05-15 6:08 ` Eli Zaretskii
2020-05-15 12:33 ` Nicolas Bértolo
2020-05-15 13:00 ` Eli Zaretskii
2020-05-15 19:44 ` Nicolas Bértolo
2020-05-16 6:22 ` Eli Zaretskii
2020-05-16 7:12 ` Andrea Corallo
2020-05-16 16:12 ` Nicolas Bértolo
2020-05-16 16:19 ` Eli Zaretskii
2020-05-16 16:31 ` Nicolas Bértolo
2020-05-16 16:42 ` Eli Zaretskii
2020-05-16 17:09 ` Nicolas Bértolo
2020-05-19 19:23 ` Nicolas Bértolo
2020-05-19 19:25 ` Nicolas Bértolo
2020-05-20 15:27 ` Eli Zaretskii
2020-05-20 15:46 ` Nicolas Bértolo
[not found] ` <83blmf13d1.fsf@gnu.org>
[not found] ` <xjfh7w7vyjk.fsf@sdf.org>
[not found] ` <83367r0zvb.fsf@gnu.org>
2020-05-23 10:37 ` Andrea Corallo
2020-05-23 11:03 ` Eli Zaretskii
2020-05-23 11:21 ` Andrea Corallo
2020-05-23 12:20 ` Eli Zaretskii
2020-05-23 12:54 ` Andrea Corallo
2020-05-23 14:41 ` Nicolas Bértolo
2020-05-23 15:11 ` Andrea Corallo
2020-05-23 15:26 ` Nicolas Bértolo
2020-05-23 16:00 ` Andrea Corallo
2020-05-23 16:04 ` Eli Zaretskii
2020-05-23 16:20 ` Nicolas Bértolo
2020-05-23 17:04 ` Eli Zaretskii
2020-05-23 17:20 ` Nicolas Bértolo
2020-05-23 17:35 ` Eli Zaretskii
2020-05-23 17:47 ` Nicolas Bértolo
2020-05-23 18:21 ` Eli Zaretskii
2020-05-23 18:29 ` Nicolas Bértolo
2020-05-23 18:37 ` Eli Zaretskii
2020-05-23 18:43 ` Nicolas Bértolo
2020-05-23 22:52 ` Nicolas Bértolo
2020-05-25 12:21 ` Andrea Corallo
2020-05-24 3:53 ` Richard Stallman
2020-05-23 17:56 ` Andrea Corallo
2020-05-23 15:52 ` Eli Zaretskii
2020-05-23 16:03 ` Nicolas Bértolo
2020-05-20 16:06 ` Andrea Corallo
2020-05-20 15:55 ` Eli Zaretskii
2020-05-20 16:12 ` Andrea Corallo
2020-05-20 16:17 ` Nicolas Bértolo
2020-05-20 17:24 ` Andrea Corallo
2020-05-20 17:29 ` Andrea Corallo
2020-05-20 17:59 ` Eli Zaretskii
2020-05-20 18:09 ` Andrea Corallo
2020-05-20 18:48 ` Nicolas Bértolo
2020-05-20 21:38 ` Andrea Corallo
2020-05-21 1:58 ` Nicolas Bértolo
2020-05-21 18:51 ` Andrea Corallo
2020-05-22 21:23 ` Andrea Corallo
2020-05-14 19:13 ` Eli Zaretskii
2020-05-14 17:14 ` Eli Zaretskii
2020-05-14 16:24 ` Nicolas Bértolo
2020-05-14 17:21 ` Eli Zaretskii
2020-05-20 16:44 ` Eli Zaretskii
2020-05-23 22:58 ` bug#41242: Port feature/native-comp to Windows - Improve handling of native compilation Andrea Corallo
2020-05-23 23:43 ` Nicolas Bértolo
2020-05-24 8:19 ` Andrea Corallo
2020-05-24 17:58 ` Nicolas Bértolo
2020-05-24 19:13 ` Andrea Corallo
2020-05-24 19:43 ` Nicolas Bértolo
2020-05-25 14:04 ` Andrea Corallo
2020-05-25 14:27 ` Nicolas Bértolo
2020-05-25 15:06 ` Andrea Corallo
2020-05-25 20:27 ` Andrea Corallo
2020-05-25 21:49 ` Nicolas Bértolo
2020-05-27 21:02 ` bug#41242: Port feature/native-comp to Windows - Determine the emacs root dir Andrea Corallo
2020-05-28 6:17 ` Eli Zaretskii
2020-05-29 0:39 ` Nicolas Bértolo
2020-05-29 12:12 ` Andrea Corallo
2020-05-29 13:54 ` Eli Zaretskii
2020-05-29 14:26 ` Andrea Corallo
2020-05-30 10:51 ` Andrea Corallo
2020-05-30 13:06 ` Nicolas Bértolo
2020-05-30 14:17 ` Andrea Corallo
2020-05-30 13:23 ` Nicolas Bértolo
2020-05-30 14:51 ` Andrea Corallo
2020-05-30 16:25 ` Nicolas Bértolo
2020-05-30 18:51 ` Andrea Corallo
2020-05-30 20:15 ` Nicolas Bértolo
2020-05-30 20:54 ` Nicolas Bértolo
2020-05-31 8:55 ` Andrea Corallo
2020-05-30 16:29 ` Eli Zaretskii
2020-05-30 14:15 ` bug#41242: Port feature/native-comp to Windows - Reduce the number of files probed when finding a lisp file Andrea Corallo
2020-05-31 15:34 ` Nicolas Bértolo [this message]
2020-05-31 22:41 ` Nicolas Bértolo
2020-06-01 7:21 ` Andrea Corallo
2020-06-01 13:56 ` Nicolas Bértolo
2020-06-01 19:24 ` Andrea Corallo
2020-06-02 0:42 ` Nicolas Bértolo
2020-06-02 14:43 ` Andrea Corallo
2020-06-02 15:02 ` Eli Zaretskii
2020-06-02 16:24 ` Andrea Corallo
2020-06-02 21:17 ` Nicolas Bértolo
2020-06-02 23:08 ` Andrea Corallo
2020-06-02 23:39 ` Nicolas Bértolo
2020-06-03 13:50 ` Andrea Corallo
2020-06-03 15:28 ` Nicolas Bértolo
2020-06-03 16:24 ` Andrea Corallo
2020-06-06 21:41 ` Andrea Corallo
2020-06-06 21:51 ` Nicolas Bértolo
2020-06-06 22:32 ` Andrea Corallo
2020-06-06 22:50 ` Nicolas Bértolo
2020-06-06 23:20 ` Andrea Corallo
2020-06-09 14:14 ` Nicolas Bértolo
2020-06-09 17:17 ` Andrea Corallo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFnS-Omg7pp2yTqHx8P3VBf75A-ybb+HM4dKmUD0dGquV2QY=w@mail.gmail.com' \
--to=nicolasbertolo@gmail.com \
--cc=41242@debbugs.gnu.org \
--cc=akrl@sdf.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).