From 28268e47d844215b11f9a731d2bedb58bee0b343 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Wed, 25 Dec 2019 15:41:39 +0100 Subject: [PATCH] Support .dylib suffix for modules on macOS (Bug#36226). On macOS, shared libraries typically have the suffix .dylib. This commit switches the module suffix to .dylib on Darwin to account for that. To also support the .so suffix, introduce the concept of a secondary module suffix. * configure.ac: Switch MODULES_SUFFIX to .dylib for Darwin, introduce MODULES_SECONDARY_SUFFIX. * src/lread.c (Fload, syms_of_lread): Also use MODULES_SECONDARY_SUFFIX if defined. * test/src/emacs-module-tests.el (module-darwin-secondary-suffix): New unit test. --- configure.ac | 10 ++++++++++ src/lread.c | 17 ++++++++++++++++- test/src/emacs-module-tests.el | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1727bdc002a..f24597ae872 100644 --- a/configure.ac +++ b/configure.ac @@ -3676,8 +3676,13 @@ HAVE_MODULES=no MODULES_OBJ= case $opsys in cygwin|mingw32) MODULES_SUFFIX=".dll" ;; + darwin) MODULES_SUFFIX=".dylib" ;; *) MODULES_SUFFIX=".so" ;; esac +case "${opsys}" in + darwin) MODULES_SECONDARY_SUFFIX='.so' ;; + *) MODULES_SECONDARY_SUFFIX='' ;; +esac if test "${with_modules}" != "no"; then case $opsys in gnu|gnu-linux) @@ -3708,11 +3713,16 @@ if test "${HAVE_MODULES}" = yes; then AC_DEFINE(HAVE_MODULES, 1, [Define to 1 if dynamic modules are enabled]) AC_DEFINE_UNQUOTED(MODULES_SUFFIX, "$MODULES_SUFFIX", [System extension for dynamic libraries]) + if test -n "${MODULES_SECONDARY_SUFFIX}"; then + AC_DEFINE_UNQUOTED(MODULES_SECONDARY_SUFFIX, "$MODULES_SECONDARY_SUFFIX", + [Alternative system extension for dynamic libraries.]) + fi fi AC_SUBST(MODULES_OBJ) AC_SUBST(LIBMODULES) AC_SUBST(HAVE_MODULES) AC_SUBST(MODULES_SUFFIX) +AC_SUBST(MODULES_SECONDARY_SUFFIX) AC_CONFIG_FILES([src/emacs-module.h]) AC_SUBST_FILE([module_env_snippet_25]) diff --git a/src/lread.c b/src/lread.c index 7b3686b3d71..6329172f4b4 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1199,6 +1199,9 @@ Return t if the file exists and loads successfully. */) || suffix_p (file, ".elc") #ifdef HAVE_MODULES || suffix_p (file, MODULES_SUFFIX) +#ifdef MODULES_SECONDARY_SUFFIX + || suffix_p (file, MODULES_SECONDARY_SUFFIX) +#endif #endif ) must_suffix = Qnil; @@ -1268,7 +1271,12 @@ Return t if the file exists and loads successfully. */) } #ifdef HAVE_MODULES - bool is_module = suffix_p (found, MODULES_SUFFIX); + bool is_module = + suffix_p (found, MODULES_SUFFIX) +#ifdef MODULES_SECONDARY_SUFFIX + || suffix_p (found, MODULES_SECONDARY_SUFFIX) +#endif + ; #else bool is_module = false; #endif @@ -4856,9 +4864,16 @@ 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 suffix is allowed or required. */); #ifdef HAVE_MODULES +#ifdef MODULES_SECONDARY_SUFFIX + Vload_suffixes = list4 (build_pure_c_string (".elc"), + build_pure_c_string (".el"), + build_pure_c_string (MODULES_SUFFIX), + build_pure_c_string (MODULES_SECONDARY_SUFFIX)); +#else Vload_suffixes = list3 (build_pure_c_string (".elc"), build_pure_c_string (".el"), build_pure_c_string (MODULES_SUFFIX)); +#endif #else Vload_suffixes = list2 (build_pure_c_string (".elc"), build_pure_c_string (".el")); diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 18766081c0a..322500ff604 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -384,4 +384,22 @@ Interactively, you can try hitting \\[keyboard-quit] to quit." (ert-info ((format "input: %d" input)) (should (= (mod-test-double input) (* 2 input)))))) +(ert-deftest module-darwin-secondary-suffix () + "Check that on Darwin, both .so and .dylib suffixes work. +See Bug#36226." + (skip-unless (eq system-type 'darwin)) + (should (member ".dylib" load-suffixes)) + (should (member ".so" load-suffixes)) + ;; Preserve the old `load-history'. This is needed for some of the + ;; other unit tests that indirectly rely on `load-history'. + (let ((load-history load-history) + (dylib (concat mod-test-file ".dylib")) + (so (concat mod-test-file ".so"))) + (should (file-regular-p dylib)) + (should-not (file-exists-p so)) + (add-name-to-file dylib so) + (unwind-protect + (load so nil nil :nosuffix :must-suffix) + (delete-file so)))) + ;;; emacs-module-tests.el ends here -- 2.39.2