mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-02-11 15:00:08 +08:00
There was no clean separation of abstraction layers in libltdl. The first step in fixing this is to factor out the memory management abstraction, making a start on removing promiscuity from the underlying portability layer: * doc/libtool.texi (Libltdl interface): Remove lt_dlmalloc, lt_dlrealloc and lt_dlfree references. The memory management layer used by libltdl is now private. * libltdl/lt_system.h: New installed header for system portability abstraction. * libltdl/ltdl.h: Use it. * libltdl/lt__alloc.c, libltdl/lt__alloc.h: New module above system portability layer to abstract ltdl's memory management. * libltdl/ltdl.c: Use lt__alloc.h. (closedir): Use free. (opendir): Use malloc/free. (lt__xalloc_die_callback): Report memory failures through lt_dlerror. (lt_dlinit): Use it to initialise memory management. (LT_DLMALLOC, LT_DLREALLOC, LT_DLFREE, LT_EMALLOC, LT_EREALLOC) (rpl_strdup, rpl_realloc, lt_estrdup, lt_emalloc, lt_erealloc): Removed in favour of... (lt__strdup, lt__memdup, MALLOC, REALLOC, FREE): ...these calls from libltdl/lt__alloc.h. Changed all callers. (rpl_argz_append, rpl_argz_create_sep, rpl_argz_insert): As part of the portability layer, these functions no longer use libltdl memory management API. (free_vars): Factored out. (LT_DLMEM_REASSIGN): While redoing memory handling, renamed... * libltdl/lt__alloc.h (MEMREASSIGN): ...to this. * libltdl/Makefile.am (AUTOMAKE_OPTIONS): Let automake track dependencies automatically. (pkgincludedir): Override from parent package's setting. (pkginclude_HEADERS): Install lt_system.h. (libltdl_la_SOURCES): Add new files. * NEWS: Updated. Reported by Dalibor Topic <robilad@kaffe.org>
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
/* lt__alloc.c -- internal memory management interface
|
|
Copyright (C) 2004 Free Software Foundation, Inc.
|
|
Originally by Gary V. Vaughan <gary@gnu.org>
|
|
|
|
NOTE: The canonical source of this file is maintained with the
|
|
GNU Libtool package. Report bugs to bug-libtool@gnu.org.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
As a special exception to the GNU Lesser General Public License,
|
|
if you distribute this file as part of a program or library that
|
|
is built using GNU libtool, you may include it under the same
|
|
distribution terms that you use for the rest of that program.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include HAVE_CONFIG_H
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "lt__alloc.h"
|
|
|
|
static void alloc_die_default (void);
|
|
|
|
void (*lt__alloc_die) (void) = alloc_die_default;
|
|
|
|
/* Unless overridden, exit on memory failure. */
|
|
static void
|
|
alloc_die_default (void)
|
|
{
|
|
fprintf (stderr, "Out of memory.\n");
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
|
|
void *
|
|
lt__malloc (size_t n)
|
|
{
|
|
void *mem;
|
|
|
|
if (! (mem = malloc (n)))
|
|
(*lt__alloc_die) ();
|
|
|
|
return mem;
|
|
}
|
|
|
|
void *
|
|
lt__realloc (void *mem, size_t n)
|
|
{
|
|
if (! (mem = realloc (mem, n)))
|
|
(*lt__alloc_die) ();
|
|
|
|
return mem;
|
|
}
|
|
|
|
void *
|
|
lt__memdup (void const *mem, size_t n)
|
|
{
|
|
return memcpy (lt__malloc (n), mem, n);
|
|
}
|
|
|
|
char *
|
|
lt__strdup (const char *string)
|
|
{
|
|
return lt__memdup (string, strlen (string) +1);
|
|
}
|