aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/internals.texi55
1 files changed, 50 insertions, 5 deletions
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index d95a3e445cc..c0b3fe5a1b0 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -1447,6 +1447,54 @@ The Lisp package which goes with your module could then load the
1447module using the @code{load} primitive (@pxref{Dynamic Modules}) when 1447module using the @code{load} primitive (@pxref{Dynamic Modules}) when
1448the package is loaded into Emacs. 1448the package is loaded into Emacs.
1449 1449
1450@anchor{Module Function Finalizers}
1451If you want to run some code when a module function object (i.e., an
1452object returned by @code{make_function}) is garbage-collected, you can
1453install a @dfn{function finalizer}. Function finalizers are available
1454since Emacs 28. For example, if you have passed some heap-allocated
1455structure to the @var{data} argument of @code{make_function}, you can
1456use the finalizer to deallocate the structure. @xref{Basic
1457Allocation,,,libc}, and @pxref{Freeing after Malloc,,,libc}. The
1458finalizer function has the following signature:
1459
1460@example
1461void finalizer (void *@var{data})
1462@end example
1463
1464Here, @var{data} receives the value passed to @var{data} when calling
1465@code{make_function}. Note that the finalizer can't interact with
1466Emacs in any way.
1467
1468Directly after calling @code{make_function}, the newly-created
1469function doesn't have a finalizer. Use @code{set_function_finalizer}
1470to add one, if desired.
1471
1472@deftypefun void emacs_finalizer (void *@var{ptr})
1473The header @file{emacs-module.h} provides the type
1474@code{emacs_finalizer} as a type alias for an Emacs finalizer
1475function.
1476@end deftypefun
1477
1478@deftypefun emacs_finalizer get_function_finalizer (emacs_env *@var{env}, emacs_value @var{arg})
1479This function, which is available since Emacs 28, returns the function
1480finalizer associated with the module function represented by
1481@var{arg}. @var{arg} must refer to a module function, that is, an
1482object returned by @code{make_function}. If no finalizer is
1483associated with the function, @code{NULL} is returned.
1484@end deftypefun
1485
1486@deftypefun void set_function_finalizer (emacs_env *@var{env}, emacs_value @var{arg}, emacs_finalizer @var{fin})
1487This function, which is available since Emacs 28, sets the function
1488finalizer associated with the module function represented by @var{arg}
1489to @var{fin}. @var{arg} must refer to a module function, that is, an
1490object returned by @code{make_function}. @var{fin} can either be
1491@code{NULL} to clear @var{arg}'s function finalizer, or a pointer to a
1492function to be called when the object represented by @var{arg} is
1493garbage-collected. At most one function finalizer can be set per
1494function; if @var{arg} already has a finalizer, it is replaced by
1495@var{fin}.
1496@end deftypefun
1497
1450@node Module Values 1498@node Module Values
1451@subsection Conversion Between Lisp and Module Values 1499@subsection Conversion Between Lisp and Module Values
1452@cindex module values, conversion 1500@cindex module values, conversion
@@ -1865,11 +1913,8 @@ represented by @var{arg} to be @var{fin}. If @var{fin} is a
1865finalizer. 1913finalizer.
1866@end deftypefn 1914@end deftypefn
1867 1915
1868@deftypefun void emacs_finalizer (void *@var{ptr}) 1916Note that the @code{emacs_finalizer} type works for both user pointer
1869The header @file{emacs-module.h} provides the type 1917an module function finalizers. @xref{Module Function Finalizers}.
1870@code{emacs_finalizer} as a type alias for an Emacs finalizer
1871function.
1872@end deftypefun
1873 1918
1874@node Module Misc 1919@node Module Misc
1875@subsection Miscellaneous Convenience Functions for Modules 1920@subsection Miscellaneous Convenience Functions for Modules