[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/aptel/dynamic-modules-rc3 1959b65 18/35: use `load
From: |
Noah Friedman |
Subject: |
[Emacs-diffs] feature/aptel/dynamic-modules-rc3 1959b65 18/35: use `load-module-suffixes' as a source of module suffixes. |
Date: |
Mon, 8 May 2017 19:46:28 -0400 (EDT) |
branch: feature/aptel/dynamic-modules-rc3
commit 1959b65ac4b09718879dc9766faebe9f6c5a3096
Author: Aurélien Aptel <address@hidden>
Commit: Aurélien Aptel <address@hidden>
use `load-module-suffixes' as a source of module suffixes.
* New `load-module-suffixes' variable:
- `load-suffixes' corresponds to elisp suffixes only
- `load-modules-suffixes' corresponds to modules suffixes only
- `get-load-suffixes' use both lists to build every possible suffixes
* Slightly simplify `load' by introducing 2 predicates:
- string_prefix_p (string, suffix)
Return truef if STRING ends with SUFFIX.
- string_suffixes_p (string, suffix_list)
Return true if STRING ends with any element of SUFFIX_LIST.
---
src/lread.c | 82 ++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 59 insertions(+), 23 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index ec3d58a..3a2c29a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -986,7 +986,15 @@ required.
This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
(void)
{
- Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext;
+ Lisp_Object lst = Qnil, suffixes, suffix, ext;
+
+ /* module suffixes, then regular elisp suffixes */
+
+ Lisp_Object args[2];
+ args[0] = Vload_module_suffixes;
+ args[1] = Vload_suffixes;
+ suffixes = Fappend (2, args);
+
while (CONSP (suffixes))
{
Lisp_Object exts = Vload_file_rep_suffixes;
@@ -1053,6 +1061,35 @@ DEFUN ("load-module", Fload_module, Sload_module, 1, 1,
0,
#endif
}
+
+/* Return true if STRING ends with SUFFIX. */
+static bool string_suffix_p (Lisp_Object string, const char *suffix)
+{
+ const ptrdiff_t len = strlen (suffix);
+ return memcmp (SDATA (string) + SBYTES (string) - len, suffix, len) == 0;
+}
+
+/* Return true if STRING ends with any element of SUFFIXES. */
+static bool string_suffixes_p (Lisp_Object string, Lisp_Object suffixes)
+{
+ ptrdiff_t length = SBYTES (string), suflen;
+ Lisp_Object tail, suffix;
+
+ for (tail = suffixes; CONSP (tail); tail = XCDR (tail))
+ {
+ suffix = XCAR (tail);
+ suflen = SBYTES (suffix);
+
+ if (suflen <= length)
+ {
+ if (memcmp (SDATA (string) + length - suflen, SDATA (suffix),
suflen) == 0)
+ return true;
+ }
+ }
+
+ return false;
+}
+
DEFUN ("load", Fload, Sload, 1, 5, 0,
doc: /* Execute a file of Lisp code named FILE.
First try FILE with `.elc' appended, then try with `.el',
@@ -1162,21 +1199,14 @@ Return t if the file exists and loads successfully. */)
if (! NILP (must_suffix))
{
- /* Don't insist on adding a suffix if FILE already ends with one. */
- ptrdiff_t size = SBYTES (file);
- if (size > 3
- && !strcmp (SSDATA (file) + size - 3, ".so"))
- must_suffix = Qnil;
- if (size > 3
- && !strcmp (SSDATA (file) + size - 3, ".el"))
- must_suffix = Qnil;
- else if (size > 4
- && !strcmp (SSDATA (file) + size - 4, ".elc"))
- must_suffix = Qnil;
- /* Don't insist on adding a suffix
- if the argument includes a directory name. */
- else if (! NILP (Ffile_name_directory (file)))
- must_suffix = Qnil;
+ /* Don't insist on adding a suffix if FILE already ends with
+ one or if FILE includes a directory name. */
+ if (string_suffixes_p (file, Vload_module_suffixes)
+ || string_suffixes_p (file, Vload_suffixes)
+ || ! NILP (Ffile_name_directory (file)))
+ {
+ must_suffix = Qnil;
+ }
}
if (!NILP (nosuffix))
@@ -1287,7 +1317,7 @@ Return t if the file exists and loads successfully. */)
specbind (Qold_style_backquotes, Qnil);
record_unwind_protect (load_warn_old_style_backquotes, file);
- if (!memcmp (SDATA (found) + SBYTES (found) - 4, ".elc", 4)
+ if (string_suffix_p (found, ".elc")
|| (fd >= 0 && (version = safe_to_load_version (fd)) > 0))
/* Load .elc files directly, but not when they are
remote and have no handler! */
@@ -1350,7 +1380,7 @@ Return t if the file exists and loads successfully. */)
}
}
#ifdef HAVE_LTDL
- else if (!memcmp (SDATA (found) + SBYTES (found) - 3, ".so", 3))
+ else if (string_suffixes_p (found, Vload_module_suffixes))
{
module = 1;
}
@@ -4628,13 +4658,19 @@ This list should not include the empty string.
`load' and related functions try to append these suffixes, in order,
to the specified file name if a Lisp suffix is allowed or required. */);
-#ifdef HAVE_LTDL
- Vload_suffixes = list3 (build_pure_c_string (".so"),
- build_pure_c_string (".elc"),
- build_pure_c_string (".el"));
-#else
Vload_suffixes = list2 (build_pure_c_string (".elc"),
build_pure_c_string (".el"));
+
+ DEFVAR_LISP ("load-module-suffixes", Vload_module_suffixes,
+ doc: /* List of suffixes for modules files.
+This list should not include the empty string. See `load-suffixes'. */);
+
+#ifdef HAVE_LTDL
+ Vload_module_suffixes = list3 (build_pure_c_string (".dll"),
+ build_pure_c_string (".so"),
+ build_pure_c_string (".dylib"));
+#else
+ Vload_module_suffixes = Qnil;
#endif
DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes,
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 0cfb066 07/35: doc.c: use DOC format sanity checks instead of bytecompiled checks on module doc files., (continued)
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 0cfb066 07/35: doc.c: use DOC format sanity checks instead of bytecompiled checks on module doc files., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 4000103 20/35: yaml module: add `yaml-parse-string'., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 4e1ad37 19/35: new yaml parsing module using libyaml, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 8147699 15/35: fix docstring., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 bfe16af 10/35: new module: opaque, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 582704c 14/35: curl: use url arg., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9330ca6 12/35: new module: elisp, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9da7346 13/35: new module: curl. basic URL fetcher working., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 c7248ea 21/35: yaml module: rename `yaml-parse' to `yaml-parse-buffer'., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 a95e032 17/35: update modules examples with `provide' call., Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 1959b65 18/35: use `load-module-suffixes' as a source of module suffixes.,
Noah Friedman <=
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 1da9b91 24/35: opaque module: rename Qc variable to Qc_ due to macro collision, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 6e9c6b1 26/35: doc.c: fix module doc prefix, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 3a2aab6 29/35: modules/fmod: use M prefix for module global vars, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 ef45794 32/35: modules/yaml: skip TODO tests, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9461927 33/35: modules/opaque/test.el: use `should' macro instead of assert, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 b82611b 27/35: modules/tests.py: honnor module list from args, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 2e998a7 30/35: modules/fmod: use right docstring in test, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 4257b6b 28/35: lread.c: update load-module docstring, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 f52bd1f 31/35: modules: prefix all global module variable with M, Noah Friedman, 2017/05/08
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9a1d734 25/35: modules/: add proper testing, Noah Friedman, 2017/05/08