aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2019-12-26 10:29:21 +0100
committerPhilipp Stephani2019-12-26 10:29:21 +0100
commit719ad593872b606d2ca6ca5a144e37251c378078 (patch)
treeec4c57ed490cc4a86f7c743aa71b4438a334f93a /src
parent639fb50ed4c622f99dfbde32fbdbca42ce36d385 (diff)
downloademacs-719ad593872b606d2ca6ca5a144e37251c378078.tar.gz
emacs-719ad593872b606d2ca6ca5a144e37251c378078.zip
Promote function type aliases to the public module API.
Previously module authors had to define type aliases for module functions and finalizers themselves. This commit adds and documents aliases so that this is no longer necessary. * src/emacs-module.h.in: Add 'emacs_function' and 'emacs_finalizer' type aliases. * src/emacs-module.c: Remove old 'emacs_subr' and 'emacs_finalizer' type aliases. (struct Lisp_Module_Function, module_make_function): Switch from 'emacs_subr' to 'emacs_function'. * doc/lispref/internals.texi (Module Functions): Document and use 'emacs_function' type alias. (Module Values): Document 'emacs_finalizer' type alias. * etc/NEWS: Mention change.
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c14
-rw-r--r--src/emacs-module.h.in15
2 files changed, 17 insertions, 12 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index ff1a05450ce..76229137d87 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -122,12 +122,6 @@ To add a new module function, proceed as follows:
122/* Function prototype for the module init function. */ 122/* Function prototype for the module init function. */
123typedef int (*emacs_init_function) (struct emacs_runtime *); 123typedef int (*emacs_init_function) (struct emacs_runtime *);
124 124
125/* Function prototype for module user-pointer finalizers. These
126 should not throw C++ exceptions, so emacs-module.h declares the
127 corresponding interfaces with EMACS_NOEXCEPT. There is only C code
128 in this module, though, so this constraint is not enforced here. */
129typedef void (*emacs_finalizer) (void *);
130
131 125
132/* Memory management. */ 126/* Memory management. */
133 127
@@ -466,10 +460,6 @@ module_non_local_exit_throw (emacs_env *env, emacs_value tag, emacs_value value)
466 value_to_lisp (value)); 460 value_to_lisp (value));
467} 461}
468 462
469/* Function prototype for the module Lisp functions. */
470typedef emacs_value (*emacs_subr) (emacs_env *, ptrdiff_t,
471 emacs_value *, void *);
472
473/* Module function. */ 463/* Module function. */
474 464
475/* A function environment is an auxiliary structure returned by 465/* A function environment is an auxiliary structure returned by
@@ -486,7 +476,7 @@ struct Lisp_Module_Function
486 476
487 /* Fields ignored by GC. */ 477 /* Fields ignored by GC. */
488 ptrdiff_t min_arity, max_arity; 478 ptrdiff_t min_arity, max_arity;
489 emacs_subr subr; 479 emacs_function subr;
490 void *data; 480 void *data;
491} GCALIGNED_STRUCT; 481} GCALIGNED_STRUCT;
492 482
@@ -505,7 +495,7 @@ allocate_module_function (void)
505 495
506static emacs_value 496static emacs_value
507module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, 497module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity,
508 emacs_subr func, const char *docstring, void *data) 498 emacs_function func, const char *docstring, void *data)
509{ 499{
510 MODULE_FUNCTION_BEGIN (NULL); 500 MODULE_FUNCTION_BEGIN (NULL);
511 501
diff --git a/src/emacs-module.h.in b/src/emacs-module.h.in
index ecbfe28c72c..fbeaebd7956 100644
--- a/src/emacs-module.h.in
+++ b/src/emacs-module.h.in
@@ -78,6 +78,21 @@ struct emacs_runtime
78 EMACS_ATTRIBUTE_NONNULL(1); 78 EMACS_ATTRIBUTE_NONNULL(1);
79}; 79};
80 80
81/* Type aliases for function pointer types used in the module API.
82 Note that we don't use these aliases directly in the API to be able
83 to mark the function arguments as 'noexcept' before C++20.
84 However, users can use them if they want. */
85
86/* Function prototype for the module Lisp functions. These must not
87 throw C++ exceptions. */
88typedef emacs_value (*emacs_function) (emacs_env *env, ptrdiff_t nargs,
89 emacs_value *args,
90 void *data)
91 EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL (1);
92
93/* Function prototype for module user-pointer finalizers. These must
94 not throw C++ exceptions. */
95typedef void (*emacs_finalizer) (void *data) EMACS_NOEXCEPT;
81 96
82/* Possible Emacs function call outcomes. */ 97/* Possible Emacs function call outcomes. */
83enum emacs_funcall_exit 98enum emacs_funcall_exit