all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Dynamic module building and reloading
@ 2023-06-13 16:11 Nicolas Martyanoff
  2023-06-13 16:55 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Martyanoff @ 2023-06-13 16:11 UTC (permalink / raw)
  To: emacs-devel


Hi,

I was playing a bit with dynamic modules and found two issues.

1. There does not seem to be any builtin utilities to deal with
the process of building and loading shared library. I ended up writing a
couple elisp functions to find the location of the C file, spawn cc,
load the shared library… Is this the expected method? In this state, it
would seem that every Emacs packages using dynamic modules has to write
its own build/load code.

2. It seems that once a dynamic module has been loaded, it cannot be
reloaded after the shared library has been rebuilt. A Google search
seems to confirm it. Is there a workaround? If I pursue my little
project, I'll have to write quite a lot of C code in the dynamic module;
I *really* do not want to restart Emacs to test every single
modification.

Hopefully I'm not the only one with these issues!

Regards,

-- 
Nicolas Martyanoff
https://n16f.net
nicolas@n16f.net



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Dynamic module building and reloading
  2023-06-13 16:11 Dynamic module building and reloading Nicolas Martyanoff
@ 2023-06-13 16:55 ` Eli Zaretskii
  2023-06-13 17:10   ` Nicolas Martyanoff
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-06-13 16:55 UTC (permalink / raw)
  To: Nicolas Martyanoff; +Cc: emacs-devel

> From: Nicolas Martyanoff <nicolas@n16f.net>
> Date: Tue, 13 Jun 2023 18:11:47 +0200
> 
> 1. There does not seem to be any builtin utilities to deal with
> the process of building and loading shared library. I ended up writing a
> couple elisp functions to find the location of the C file, spawn cc,
> load the shared library… Is this the expected method? In this state, it
> would seem that every Emacs packages using dynamic modules has to write
> its own build/load code.

The expected method of building a shared library is the same as you'd
use for building any other shared library out there.  The Emacs
modules aren't special in any way, and the details of their build
procedures depend on what code you are compiling in, which other
libraries you need to link against, etc.  There's no way an Emacs
command could cover all that.  However, if you write a Makefile to
compile and link the module, you can use "M-x compile" to run the Make
utility to build your module.

> 2. It seems that once a dynamic module has been loaded, it cannot be
> reloaded after the shared library has been rebuilt. A Google search
> seems to confirm it. Is there a workaround? If I pursue my little
> project, I'll have to write quite a lot of C code in the dynamic module;
> I *really* do not want to restart Emacs to test every single
> modification.

We don't have a facility to unload a module, no.  The usual way of
testing your development code is to start a new scratch session (in
addition to your production Emacs session) each time you recompile a
module.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Dynamic module building and reloading
  2023-06-13 16:55 ` Eli Zaretskii
@ 2023-06-13 17:10   ` Nicolas Martyanoff
  2023-06-13 17:26     ` chad
  2023-06-13 18:12     ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Martyanoff @ 2023-06-13 17:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Got it, thank you for responding this quickly. 

Are there technical limitations against reloading or is this just a case of “if you need it send a patch”? I know that some platforms may have issues with it; but I use foreign library reloading in Common Lisp on Linux all the time, and it also works en BSD.

Nicolas Martyanoff
https://www.n16f.net
nicolas@n16f.net

> On 13 Jun 2023, at 18:55, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> 
>> 
>> From: Nicolas Martyanoff <nicolas@n16f.net>
>> Date: Tue, 13 Jun 2023 18:11:47 +0200
>> 
>> 1. There does not seem to be any builtin utilities to deal with
>> the process of building and loading shared library. I ended up writing a
>> couple elisp functions to find the location of the C file, spawn cc,
>> load the shared library… Is this the expected method? In this state, it
>> would seem that every Emacs packages using dynamic modules has to write
>> its own build/load code.
> 
> The expected method of building a shared library is the same as you'd
> use for building any other shared library out there.  The Emacs
> modules aren't special in any way, and the details of their build
> procedures depend on what code you are compiling in, which other
> libraries you need to link against, etc.  There's no way an Emacs
> command could cover all that.  However, if you write a Makefile to
> compile and link the module, you can use "M-x compile" to run the Make
> utility to build your module.
> 
>> 2. It seems that once a dynamic module has been loaded, it cannot be
>> reloaded after the shared library has been rebuilt. A Google search
>> seems to confirm it. Is there a workaround? If I pursue my little
>> project, I'll have to write quite a lot of C code in the dynamic module;
>> I *really* do not want to restart Emacs to test every single
>> modification.
> 
> We don't have a facility to unload a module, no.  The usual way of
> testing your development code is to start a new scratch session (in
> addition to your production Emacs session) each time you recompile a
> module.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Dynamic module building and reloading
  2023-06-13 17:10   ` Nicolas Martyanoff
@ 2023-06-13 17:26     ` chad
  2023-06-13 18:12     ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: chad @ 2023-06-13 17:26 UTC (permalink / raw)
  To: Nicolas Martyanoff; +Cc: Eli Zaretskii, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

This sounded familiar, so I poked around and found this:


https://emacs.stackexchange.com/questions/33976/how-do-you-reload-a-dynamic-module

which suggests a workaround similar to what I vaguely remembered (fake it
with numbered "module names" during development), with a little bit of
automation glue. It's not something that would work as a supported
user-level feature, but could be helpful for rapid iteration cycles.

Hope that helps,
~Chad

[-- Attachment #2: Type: text/html, Size: 683 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Dynamic module building and reloading
  2023-06-13 17:10   ` Nicolas Martyanoff
  2023-06-13 17:26     ` chad
@ 2023-06-13 18:12     ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2023-06-13 18:12 UTC (permalink / raw)
  To: Nicolas Martyanoff; +Cc: emacs-devel

> From: Nicolas Martyanoff <nicolas@n16f.net>
> Date: Tue, 13 Jun 2023 19:10:25 +0200
> Cc: emacs-devel@gnu.org
> 
> Are there technical limitations against reloading or is this just a case of “if you need it send a patch”? I know that some platforms may have issues with it; but I use foreign library reloading in Common Lisp on Linux all the time, and it also works en BSD.

There are technical issues, AFAIK, yes.  Even unloading a Lisp feature
doesn't work 100% in Emacs, and a module is more complicated than
that.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-13 18:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13 16:11 Dynamic module building and reloading Nicolas Martyanoff
2023-06-13 16:55 ` Eli Zaretskii
2023-06-13 17:10   ` Nicolas Martyanoff
2023-06-13 17:26     ` chad
2023-06-13 18:12     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.