diff options
| author | Philipp Stephani | 2017-06-04 18:57:51 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-04 19:50:49 +0200 |
| commit | 3b0080de52db1756fc47f1642ee9980655421af9 (patch) | |
| tree | 5d2a765a0ef67144461de82fbc4043a9cb5de378 /src | |
| parent | 18396997b30c053a905c9a509777625ccc01c3d5 (diff) | |
| download | emacs-3b0080de52db1756fc47f1642ee9980655421af9.tar.gz emacs-3b0080de52db1756fc47f1642ee9980655421af9.zip | |
Rework printing of module functions
Fix a FIXME in emacs-module.c. Put the printing into print.c, like
other types.
* src/print.c (print_vectorlike): Add code to print module functions.
* src/emacs-module.c (funcall_module): Stop calling
'module_format_fun_env'. Now that module functions are first-class
objects, they can be added to signal data directly.
(module_handle_signal): Remove now-unused function
'module_format_fun_env'.
* test/src/emacs-module-tests.el (mod-test-sum-test): Adapt unit test.
* src/eval.c (funcall_lambda): Adapt call to changed signature of
'funcall_module'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs-module.c | 44 | ||||
| -rw-r--r-- | src/eval.c | 2 | ||||
| -rw-r--r-- | src/lisp.h | 4 | ||||
| -rw-r--r-- | src/print.c | 30 |
4 files changed, 37 insertions, 43 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index f2eaa71de3f..f9e76b5f0f8 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -645,14 +645,13 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, | |||
| 645 | } | 645 | } |
| 646 | 646 | ||
| 647 | Lisp_Object | 647 | Lisp_Object |
| 648 | funcall_module (const struct Lisp_Module_Function *const function, | 648 | funcall_module (Lisp_Object function, ptrdiff_t nargs, Lisp_Object *arglist) |
| 649 | ptrdiff_t nargs, Lisp_Object *arglist) | ||
| 650 | { | 649 | { |
| 651 | eassume (0 <= function->min_arity); | 650 | const struct Lisp_Module_Function *func = XMODULE_FUNCTION (function); |
| 652 | if (! (function->min_arity <= nargs | 651 | eassume (0 <= func->min_arity); |
| 653 | && (function->max_arity < 0 || nargs <= function->max_arity))) | 652 | if (! (func->min_arity <= nargs |
| 654 | xsignal2 (Qwrong_number_of_arguments, module_format_fun_env (function), | 653 | && (func->max_arity < 0 || nargs <= func->max_arity))) |
| 655 | make_number (nargs)); | 654 | xsignal2 (Qwrong_number_of_arguments, function, make_natnum (nargs)); |
| 656 | 655 | ||
| 657 | emacs_env pub; | 656 | emacs_env pub; |
| 658 | struct emacs_env_private priv; | 657 | struct emacs_env_private priv; |
| @@ -669,7 +668,7 @@ funcall_module (const struct Lisp_Module_Function *const function, | |||
| 669 | args[i] = lisp_to_value (arglist[i]); | 668 | args[i] = lisp_to_value (arglist[i]); |
| 670 | } | 669 | } |
| 671 | 670 | ||
| 672 | emacs_value ret = function->subr (&pub, nargs, args, function->data); | 671 | emacs_value ret = func->subr (&pub, nargs, args, func->data); |
| 673 | SAFE_FREE (); | 672 | SAFE_FREE (); |
| 674 | 673 | ||
| 675 | eassert (&priv == pub.private_members); | 674 | eassert (&priv == pub.private_members); |
| @@ -942,35 +941,6 @@ module_handle_throw (emacs_env *env, Lisp_Object tag_val) | |||
| 942 | } | 941 | } |
| 943 | 942 | ||
| 944 | 943 | ||
| 945 | /* Function environments. */ | ||
| 946 | |||
| 947 | /* Return a string object that contains a user-friendly | ||
| 948 | representation of the function environment. */ | ||
| 949 | Lisp_Object | ||
| 950 | module_format_fun_env (const struct Lisp_Module_Function *env) | ||
| 951 | { | ||
| 952 | /* Try to print a function name if possible. */ | ||
| 953 | /* FIXME: Move this function into print.c, then use prin1-to-string | ||
| 954 | above. */ | ||
| 955 | const char *path, *sym; | ||
| 956 | static char const noaddr_format[] = "#<module function at %p>"; | ||
| 957 | char buffer[sizeof noaddr_format + INT_STRLEN_BOUND (intptr_t) + 256]; | ||
| 958 | char *buf = buffer; | ||
| 959 | ptrdiff_t bufsize = sizeof buffer; | ||
| 960 | ptrdiff_t size | ||
| 961 | = (dynlib_addr (env->subr, &path, &sym) | ||
| 962 | ? exprintf (&buf, &bufsize, buffer, -1, | ||
| 963 | "#<module function %s from %s>", sym, path) | ||
| 964 | : sprintf (buffer, noaddr_format, env->subr)); | ||
| 965 | AUTO_STRING_WITH_LEN (unibyte_result, buffer, size); | ||
| 966 | Lisp_Object result = code_convert_string_norecord (unibyte_result, | ||
| 967 | Qutf_8, false); | ||
| 968 | if (buf != buffer) | ||
| 969 | xfree (buf); | ||
| 970 | return result; | ||
| 971 | } | ||
| 972 | |||
| 973 | |||
| 974 | /* Segment initializer. */ | 944 | /* Segment initializer. */ |
| 975 | 945 | ||
| 976 | void | 946 | void |
diff --git a/src/eval.c b/src/eval.c index f472efad52e..8aa33a11282 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -2952,7 +2952,7 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs, | |||
| 2952 | } | 2952 | } |
| 2953 | #ifdef HAVE_MODULES | 2953 | #ifdef HAVE_MODULES |
| 2954 | else if (MODULE_FUNCTIONP (fun)) | 2954 | else if (MODULE_FUNCTIONP (fun)) |
| 2955 | return funcall_module (XMODULE_FUNCTION (fun), nargs, arg_vector); | 2955 | return funcall_module (fun, nargs, arg_vector); |
| 2956 | #endif | 2956 | #endif |
| 2957 | else | 2957 | else |
| 2958 | emacs_abort (); | 2958 | emacs_abort (); |
diff --git a/src/lisp.h b/src/lisp.h index 7b8f1e754d8..ce939fcee62 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3952,10 +3952,8 @@ XMODULE_FUNCTION (Lisp_Object o) | |||
| 3952 | extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p); | 3952 | extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p); |
| 3953 | 3953 | ||
| 3954 | /* Defined in emacs-module.c. */ | 3954 | /* Defined in emacs-module.c. */ |
| 3955 | extern Lisp_Object funcall_module (const struct Lisp_Module_Function *, | 3955 | extern Lisp_Object funcall_module (Lisp_Object, ptrdiff_t, Lisp_Object *); |
| 3956 | ptrdiff_t, Lisp_Object *); | ||
| 3957 | extern Lisp_Object module_function_arity (const struct Lisp_Module_Function *); | 3956 | extern Lisp_Object module_function_arity (const struct Lisp_Module_Function *); |
| 3958 | extern Lisp_Object module_format_fun_env (const struct Lisp_Module_Function *); | ||
| 3959 | extern void syms_of_module (void); | 3957 | extern void syms_of_module (void); |
| 3960 | #endif | 3958 | #endif |
| 3961 | 3959 | ||
diff --git a/src/print.c b/src/print.c index 49408bbeb40..e89f3d80725 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -33,6 +33,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 33 | #include "intervals.h" | 33 | #include "intervals.h" |
| 34 | #include "blockinput.h" | 34 | #include "blockinput.h" |
| 35 | #include "xwidget.h" | 35 | #include "xwidget.h" |
| 36 | #include "dynlib.h" | ||
| 36 | 37 | ||
| 37 | #include <c-ctype.h> | 38 | #include <c-ctype.h> |
| 38 | #include <float.h> | 39 | #include <float.h> |
| @@ -1699,8 +1700,33 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, | |||
| 1699 | 1700 | ||
| 1700 | #ifdef HAVE_MODULES | 1701 | #ifdef HAVE_MODULES |
| 1701 | case PVEC_MODULE_FUNCTION: | 1702 | case PVEC_MODULE_FUNCTION: |
| 1702 | print_string (module_format_fun_env (XMODULE_FUNCTION (obj)), | 1703 | { |
| 1703 | printcharfun); | 1704 | print_c_string ("#<module function ", printcharfun); |
| 1705 | void *ptr = XMODULE_FUNCTION (obj)->subr; | ||
| 1706 | const char *file = NULL; | ||
| 1707 | const char *symbol = NULL; | ||
| 1708 | dynlib_addr (ptr, &file, &symbol); | ||
| 1709 | |||
| 1710 | if (symbol == NULL) | ||
| 1711 | { | ||
| 1712 | print_c_string (" at ", printcharfun); | ||
| 1713 | enum { pointer_bufsize = sizeof ptr * 16 / CHAR_BIT + 2 + 1 }; | ||
| 1714 | char buffer[pointer_bufsize]; | ||
| 1715 | int needed = snprintf (buffer, sizeof buffer, "%p", ptr); | ||
| 1716 | eassert (needed <= sizeof buffer); | ||
| 1717 | print_c_string (buffer, printcharfun); | ||
| 1718 | } | ||
| 1719 | else | ||
| 1720 | print_c_string (symbol, printcharfun); | ||
| 1721 | |||
| 1722 | if (file != NULL) | ||
| 1723 | { | ||
| 1724 | print_c_string (" from ", printcharfun); | ||
| 1725 | print_c_string (file, printcharfun); | ||
| 1726 | } | ||
| 1727 | |||
| 1728 | printchar ('>', printcharfun); | ||
| 1729 | } | ||
| 1704 | break; | 1730 | break; |
| 1705 | #endif | 1731 | #endif |
| 1706 | 1732 | ||