[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] dynamic-modules 399d8ec 16/22: make `load' look for and ha
From: |
Teodor Zlatanov |
Subject: |
[Emacs-diffs] dynamic-modules 399d8ec 16/22: make `load' look for and handle dynamic modules. |
Date: |
Thu, 27 Nov 2014 02:01:54 +0000 |
branch: dynamic-modules
commit 399d8ec19d0488af276c5bb7e69b30b1553f15d3
Author: Aurélien Aptel <address@hidden>
Date: Sun Nov 23 21:33:02 2014 +0100
make `load' look for and handle dynamic modules.
When libltdl is available a new ".so" suffix is added to the
`load-suffixes' variable. The `load' function uses it and passes it to
openp() which does the actual search in `load-path'.
If the file found by openp() ends with ".so", then it is module and it
should be handled accordingly by calling `load-module'.
`require' calls `load' so nothing more is needed to make `require'
work. Modules should now be able to call `provide' at the end of
their init() function. `provide' runs eval-after-load code with no
additional work.
* Notes and potential problems
I have not payed too much attention to encoding problems: I only use
SDATA(filename). Does it need an ENCODE() call?
`load' is quite messy: big function, lots of side effets and spaghetti
code. I may have overlooked some things.
fix #3
fix #4
---
src/lread.c | 38 ++++++++++++++++++++++++++++++++++----
1 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index 2664766..ec3d58a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1110,6 +1110,8 @@ Return t if the file exists and loads successfully. */)
bool newer = 0;
/* True means we are loading a compiled file. */
bool compiled = 0;
+ /* True means we are loading a dynamic module. */
+ bool module = 0;
Lisp_Object handler;
bool safe_p = 1;
const char *fmode = "r";
@@ -1163,6 +1165,9 @@ Return t if the file exists and loads successfully. */)
/* 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
@@ -1344,6 +1349,12 @@ Return t if the file exists and loads successfully. */)
UNGCPRO;
}
}
+#ifdef HAVE_LTDL
+ else if (!memcmp (SDATA (found) + SBYTES (found) - 3, ".so", 3))
+ {
+ module = 1;
+ }
+#endif
else
{
/* We are loading a source file (*.el). */
@@ -1393,7 +1404,9 @@ Return t if the file exists and loads successfully. */)
if (NILP (nomessage) || force_load_messages)
{
- if (!safe_p)
+ if (module)
+ message_with_string ("Loading %s (dymamic module)...", file, 1);
+ else if (!safe_p)
message_with_string ("Loading %s (compiled; note unsafe, not compiled
in Emacs)...",
file, 1);
else if (!compiled)
@@ -1413,7 +1426,14 @@ Return t if the file exists and loads successfully. */)
if (lisp_file_lexically_bound_p (Qget_file_char))
Fset (Qlexical_binding, Qt);
- if (! version || version >= 22)
+#ifdef HAVE_LTDL
+ if (module)
+ {
+ /* XXX: should the fd/stream be closed before loading the module? */
+ Fload_module (found);
+ }
+#endif
+ else if (! version || version >= 22)
readevalloop (Qget_file_char, stream, hist_file_name,
0, Qnil, Qnil, Qnil, Qnil);
else
@@ -1442,7 +1462,9 @@ Return t if the file exists and loads successfully. */)
if (!noninteractive && (NILP (nomessage) || force_load_messages))
{
- if (!safe_p)
+ if (module)
+ message_with_string ("Loading %s (dymamic module)...done", file, 1);
+ else if (!safe_p)
message_with_string ("Loading %s (compiled; note unsafe, not compiled
in Emacs)...done",
file, 1);
else if (!compiled)
@@ -4605,8 +4627,16 @@ Initialized during startup as described in Info node
`(elisp)Library Search'. *
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"));
+ build_pure_c_string (".el"));
+#endif
+
DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes,
doc: /* List of suffixes that indicate representations of \
the same file.
- [Emacs-diffs] dynamic-modules fa450f8 07/22: doc.c: use DOC format sanity checks instead of bytecompiled checks on module doc files., (continued)
- [Emacs-diffs] dynamic-modules fa450f8 07/22: doc.c: use DOC format sanity checks instead of bytecompiled checks on module doc files., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules d2271bc 06/22: alloc.c: protect doc field from GC., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules cc5fe95 09/22: move fmod module in modules/fmod/., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules c0eb5a6 05/22: change Subr doc field from char* to Lisp_Object., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules e374b97 11/22: opaque: add comments., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 1be7b68 10/22: new module: opaque, Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules db69d49 12/22: new module: elisp, Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 106c15b 14/22: curl: use url arg., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 334564f 15/22: fix docstring., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules ada5c5e 13/22: new module: curl. basic URL fetcher working., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 399d8ec 16/22: make `load' look for and handle dynamic modules.,
Teodor Zlatanov <=
- [Emacs-diffs] dynamic-modules 01e2303 17/22: update modules examples with `provide' call., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 6334cf7 18/22: use `load-module-suffixes' as a source of module suffixes., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules eae5da9 20/22: yaml module: add `yaml-parse-string'., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 4efd6a2 21/22: yaml module: rename `yaml-parse' to `yaml-parse-buffer'., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 9313182 22/22: configure.ac: dynamic modules off by default., Teodor Zlatanov, 2014/11/26
- [Emacs-diffs] dynamic-modules 18920eb 19/22: new yaml parsing module using libyaml, Teodor Zlatanov, 2014/11/26