view doc/out-of-memory.texi @ 40206:770a5696761e

relocatable-prog: Use wrapper-free installation on Mac OS X, take 2. This approach supports relocatable installation of shared libraries which depend on other shared libraries from the same package. * m4/relocatable.m4 (gl_RELOCATABLE_BODY): Determine use_macos_tools. If use_macos_tools is true, use reloc-ldflags and set LIBTOOL to be a wrapper around the original LIBTOOL. * build-aux/reloc-ldflags: Add support for Mac OS X, which uses the token '@loader_path' instead of '$ORIGIN'. * build-aux/libtool-reloc: New file. * modules/relocatable-prog (Files): Add it. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes. Document the need to set the *_LDFLAGS of libraries. RELOCATABLE_LIBRARY_PATH and RELOCATABLE_CONFIG_H_DIR should be set in Makefile.am, not in configure.ac.
author Bruno Haible <bruno@clisp.org>
date Mon, 04 Mar 2019 17:25:09 +0100
parents 99c5c7bed4f9
children
line wrap: on
line source

@node Out of memory handling
@section Out of memory handling

@cindex Out of Memory handling
@cindex Memory allocation failure
The gnulib API does not have a standard error code for the out of memory
error condition.  Instead of adding a non-standard error code, gnulib
has chosen to adopt a different strategy.  Out of memory handling
happens in rare situations, but performing the out of memory error
handling after almost all API function invocations pollute your source
code and might make it harder to spot more serious problems.  The
strategy chosen improves code readability and robustness.

@cindex Aborting execution
For most applications, aborting the application with an error message
when the out of memory situation occurs is the best that can be wished
for.  This is how the library behaves by default (using
the @samp{xalloc-die} module).

@vindex xalloc_die
However, we realize that some applications may not want to abort
execution in any situation.  Gnulib supports a hook to let the
application regain control and perform its own cleanups when an out of
memory situation has occurred.  The application can define a function
(having a @code{void} prototype, i.e., no return value and no
parameters) and set the library variable
@code{xalloc_die} to that function.  The variable should be
declared as follows.

@example
extern void (*xalloc_die) (void);
@end example

Gnulib will invoke this function if an out of memory error occurs.  Note
that the function should not return.  Of course, care must be taken to
not allocate more memory, as that will likely also fail.