From da8c7ca2647d2e111a415f59c6b59053a19bdb61 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Nov 2015 18:48:42 -0800 Subject: [PATCH] =?utf8?q?Port=20better=20to=20FreeBSD=E2=80=99s=20dlfunc?= =?utf8?q?=20vs=20dlsym?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This avoids warnings when converting between void * and function pointers, which strict C11 does not allow. * configure.ac (dlfunc): Check for existence. * src/dynlib.c (dlfunc) [!HAVE_DLFUNC]: New macro. (dynlib_func): New function. * src/dynlib.h (dynlib_function_ptr, dynlib_func): New decls. * src/emacs-module.c (Fmodule_load): Use dynlib_func, not dynlib_sym, for function pointers. --- configure.ac | 5 +++++ src/dynlib.c | 10 ++++++++++ src/dynlib.h | 2 ++ src/emacs-module.c | 5 +++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index d5638bf2002..b2fa1eddaff 100644 --- a/configure.ac +++ b/configure.ac @@ -3316,6 +3316,11 @@ if test "${with_modules}" != "no"; then if test "${HAVE_MODULES}" = no; then AC_MSG_ERROR([Dynamic modules are not supported on your system]) + else + SAVE_LIBS=$LIBS + LIBS="$LIBS $LIBMODULES" + AC_CHECK_FUNCS([dlfunc]) + LIBS=$SAVE_LIBS fi fi diff --git a/src/dynlib.c b/src/dynlib.c index 47ffb418140..a41bed847bb 100644 --- a/src/dynlib.c +++ b/src/dynlib.c @@ -206,3 +206,13 @@ dynlib_close (dynlib_handle_ptr h) #error "No dynamic loading for this system" #endif + +#if !HAVE_DLFUNC +# define dlfunc dynlib_sym +#endif + +dynlib_function_ptr +dynlib_func (dynlib_handle_ptr h, const char *sym) +{ + return (dynlib_function_ptr) dlfunc (h, sym); +} diff --git a/src/dynlib.h b/src/dynlib.h index 1282c4fd719..1c19b5db8ac 100644 --- a/src/dynlib.h +++ b/src/dynlib.h @@ -25,6 +25,8 @@ along with GNU Emacs. If not, see . */ typedef void *dynlib_handle_ptr; dynlib_handle_ptr dynlib_open (const char *path); void *dynlib_sym (dynlib_handle_ptr h, const char *sym); +typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void); +dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym); bool dynlib_addr (void *ptr, const char **path, const char **sym); const char *dynlib_error (void); int dynlib_close (dynlib_handle_ptr h); diff --git a/src/emacs-module.c b/src/emacs-module.c index 1a5e253c969..209f99baf0f 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -710,7 +710,7 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, if (!gpl_sym) error ("Module %s is not GPL compatible", SDATA (file)); - module_init = (emacs_init_function) dynlib_sym (handle, "emacs_module_init"); + module_init = (emacs_init_function) dynlib_func (handle, "emacs_module_init"); if (!module_init) error ("Module %s does not have an init function.", SDATA (file)); @@ -937,7 +937,8 @@ allocate_emacs_value (emacs_env *env, struct emacs_value_storage *storage, /* Mark all objects allocated from local environments so that they don't get garbage-collected. */ -void mark_modules (void) +void +mark_modules (void) { for (Lisp_Object tem = Vmodule_environments; CONSP (tem); tem = XCDR (tem)) { -- 2.39.2