diff options
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/internals.texi | 55 |
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 | |||
| 1447 | module using the @code{load} primitive (@pxref{Dynamic Modules}) when | 1447 | module using the @code{load} primitive (@pxref{Dynamic Modules}) when |
| 1448 | the package is loaded into Emacs. | 1448 | the package is loaded into Emacs. |
| 1449 | 1449 | ||
| 1450 | @anchor{Module Function Finalizers} | ||
| 1451 | If you want to run some code when a module function object (i.e., an | ||
| 1452 | object returned by @code{make_function}) is garbage-collected, you can | ||
| 1453 | install a @dfn{function finalizer}. Function finalizers are available | ||
| 1454 | since Emacs 28. For example, if you have passed some heap-allocated | ||
| 1455 | structure to the @var{data} argument of @code{make_function}, you can | ||
| 1456 | use the finalizer to deallocate the structure. @xref{Basic | ||
| 1457 | Allocation,,,libc}, and @pxref{Freeing after Malloc,,,libc}. The | ||
| 1458 | finalizer function has the following signature: | ||
| 1459 | |||
| 1460 | @example | ||
| 1461 | void finalizer (void *@var{data}) | ||
| 1462 | @end example | ||
| 1463 | |||
| 1464 | Here, @var{data} receives the value passed to @var{data} when calling | ||
| 1465 | @code{make_function}. Note that the finalizer can't interact with | ||
| 1466 | Emacs in any way. | ||
| 1467 | |||
| 1468 | Directly after calling @code{make_function}, the newly-created | ||
| 1469 | function doesn't have a finalizer. Use @code{set_function_finalizer} | ||
| 1470 | to add one, if desired. | ||
| 1471 | |||
| 1472 | @deftypefun void emacs_finalizer (void *@var{ptr}) | ||
| 1473 | The header @file{emacs-module.h} provides the type | ||
| 1474 | @code{emacs_finalizer} as a type alias for an Emacs finalizer | ||
| 1475 | function. | ||
| 1476 | @end deftypefun | ||
| 1477 | |||
| 1478 | @deftypefun emacs_finalizer get_function_finalizer (emacs_env *@var{env}, emacs_value @var{arg}) | ||
| 1479 | This function, which is available since Emacs 28, returns the function | ||
| 1480 | finalizer associated with the module function represented by | ||
| 1481 | @var{arg}. @var{arg} must refer to a module function, that is, an | ||
| 1482 | object returned by @code{make_function}. If no finalizer is | ||
| 1483 | associated 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}) | ||
| 1487 | This function, which is available since Emacs 28, sets the function | ||
| 1488 | finalizer associated with the module function represented by @var{arg} | ||
| 1489 | to @var{fin}. @var{arg} must refer to a module function, that is, an | ||
| 1490 | object 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 | ||
| 1492 | function to be called when the object represented by @var{arg} is | ||
| 1493 | garbage-collected. At most one function finalizer can be set per | ||
| 1494 | function; 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 | |||
| 1865 | finalizer. | 1913 | finalizer. |
| 1866 | @end deftypefn | 1914 | @end deftypefn |
| 1867 | 1915 | ||
| 1868 | @deftypefun void emacs_finalizer (void *@var{ptr}) | 1916 | Note that the @code{emacs_finalizer} type works for both user pointer |
| 1869 | The header @file{emacs-module.h} provides the type | 1917 | an module function finalizers. @xref{Module Function Finalizers}. |
| 1870 | @code{emacs_finalizer} as a type alias for an Emacs finalizer | ||
| 1871 | function. | ||
| 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 |