If I have required a dynamic module in emacs, and then modify the source and rebuild it, how do I get emacs to reload the new module? I have not been able to just require it again. The only thing that works so far is to give the module a new name.
For example, here is a little c code that makes a module (adapted from http://nullprogram.com/blog/2016/11/05/)
#include "emacs-module.h"
int plugin_is_GPL_compatible;
int
emacs_module_init(struct emacs_runtime *ert)
{
emacs_env *env = ert->get_environment(ert);
emacs_value message = env->intern(env, "message");
const char hi[] = "Hello, cruel world!";
emacs_value string = env->make_string(env, hi, sizeof(hi) - 1);
env->funcall(env, message, 1, &string);
return 0;
}
You compile it with:
gcc -Wall -fPIC -c hello.c
gcc -shared -o hello.so hello.o
Then load (note in this case we have to load it because we did not provide any feature, so require does not work here) it with (assuming it is not built on your path):
(add-to-list 'load-path "path to hello.so")
(load "hello")
And you will get a message in Messages of "Hello, cruel world!"
Now, you decide to change the message to "Hello, world!" you recompile the c code and reload it, but you still get the old message.
You can restart emacs to get it to work, or start a second emacs for testing as suggested, but this is not something I usually have to do when writing elisp modules. You can also change the library name, but it is tedious).
You cannot (unload-feature 'hello) in this case, because it is not a feature. It turns out in more complete examples that do provide a feature, you cannot unload that feature either.