From d37201722e2151df1f6b6fa1e2f33b5f91e27e03 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 4 Jun 2017 19:28:50 +0200 Subject: [PATCH] Use more specific errors for module load failure * src/emacs-module.c (syms_of_module): Add more specific error symbols. (Fmodule_load): Use them. --- src/emacs-module.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/emacs-module.c b/src/emacs-module.c index 187a620cc08..f2efc83d257 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -626,15 +626,15 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, CHECK_STRING (file); handle = dynlib_open (SSDATA (file)); if (!handle) - error ("Cannot load file %s: %s", SDATA (file), dynlib_error ()); + xsignal2 (Qmodule_open_failed, file, build_string (dynlib_error ())); gpl_sym = dynlib_sym (handle, "plugin_is_GPL_compatible"); if (!gpl_sym) - error ("Module %s is not GPL compatible", SDATA (file)); + xsignal1 (Qmodule_not_gpl_compatible, file); 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)); + xsignal1 (Qmissing_module_init_function, file); struct emacs_runtime_private rt; /* Includes the public emacs_env. */ struct emacs_env_private priv; @@ -652,7 +652,7 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, { if (FIXNUM_OVERFLOW_P (r)) xsignal0 (Qoverflow_error); - xsignal2 (Qmodule_load_failed, file, make_number (r)); + xsignal2 (Qmodule_init_failed, file, make_number (r)); } return Qt; @@ -999,6 +999,34 @@ syms_of_module (void) listn (CONSTYPE_PURE, 2, Qinvalid_module_call, Qerror)); Fput (Qinvalid_module_call, Qerror_message, build_pure_c_string ("Invalid module call")); + DEFSYM (Qmodule_open_failed, "module-open-failed"); + Fput (Qmodule_open_failed, Qerror_conditions, + listn (CONSTYPE_PURE, 3, + Qmodule_open_failed, Qmodule_load_failed, Qerror)); + Fput (Qmodule_open_failed, Qerror_message, + build_pure_c_string ("Module could not be opened")); + + DEFSYM (Qmodule_not_gpl_compatible, "module-not-gpl-compatible"); + Fput (Qmodule_not_gpl_compatible, Qerror_conditions, + listn (CONSTYPE_PURE, 3, + Qmodule_not_gpl_compatible, Qmodule_load_failed, Qerror)); + Fput (Qmodule_not_gpl_compatible, Qerror_message, + build_pure_c_string ("Module is not GPL compatible")); + + DEFSYM (Qmissing_module_init_function, "missing-module-init-function"); + Fput (Qmissing_module_init_function, Qerror_conditions, + listn (CONSTYPE_PURE, 3, + Qmissing_module_init_function, Qmodule_load_failed, Qerror)); + Fput (Qmissing_module_init_function, Qerror_message, + build_pure_c_string ("Module does not export an " + "initialization function")); + + DEFSYM (Qmodule_init_failed, "module-init-failed"); + Fput (Qmodule_init_failed, Qerror_conditions, + listn (CONSTYPE_PURE, 3, + Qmodule_init_failed, Qmodule_load_failed, Qerror)); + Fput (Qmodule_init_failed, Qerror_message, + build_pure_c_string ("Module initialization failed")); DEFSYM (Qinvalid_arity, "invalid-arity"); Fput (Qinvalid_arity, Qerror_conditions, -- 2.39.2