emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] feature/aptel/dynamic-modules-rc3 8254721 16/25: make `loa


From: Teodor Zlatanov
Subject: [Emacs-diffs] feature/aptel/dynamic-modules-rc3 8254721 16/25: make `load' look for and handle dynamic modules.
Date: Wed, 04 Feb 2015 22:56:16 +0000

branch: feature/aptel/dynamic-modules-rc3
commit 8254721c162ba6d060cd7dedea075dc54668db27
Author: Aurélien Aptel <address@hidden>
Commit: Aurélien Aptel <address@hidden>

    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.



reply via email to

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