--- /dev/null
+/* lt_system.h -- system portability abstraction layer
+ 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
+*/
+
+#ifndef LT_SYSTEM_H
+#define LT_SYSTEM_H 1
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+/* Some systems do not define EXIT_*, even with STDC_HEADERS. */
+#ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+
+/* Saves on those hard to debug '\0' typos.... */
+#define LT_EOS_CHAR '\0'
+
+/* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations,
+ so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at
+ the end of C declarations. */
+#ifdef __cplusplus
+# define LT_BEGIN_C_DECLS extern "C" {
+# define LT_END_C_DECLS }
+#else
+# define LT_BEGIN_C_DECLS /* empty */
+# define LT_END_C_DECLS /* empty */
+#endif
+
+/* LT_STMT_START/END are used to create macros which expand to a
+ a single compound statement in a portable way. */
+#if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
+# define LT_STMT_START (void)(
+# define LT_STMT_END )
+#else
+# if (defined (sun) || defined (__sun__))
+# define LT_STMT_START if (1)
+# define LT_STMT_END else (void)0
+# else
+# define LT_STMT_START do
+# define LT_STMT_END while (0)
+# endif
+#endif
+
+/* Canonicalise Windows and Cygwin recognition macros.
+ To match the values set by recent Cygwin compilers, make sure that if
+ __CYGWIN__ is defined (after canonicalisation), __WINDOWS__ is NOT! */
+#if defined(__CYGWIN32__) && !defined(__CYGWIN__)
+# define __CYGWIN__ __CYGWIN32__
+#endif
+#if defined(__CYGWIN__)
+# if defined(__WINDOWS__)
+# undef __WINDOWS__
+# endif
+#elif defined(_WIN32)
+# define __WINDOWS__ _WIN32
+#elif defined(WIN32)
+# define __WINDOWS__ WIN32
+#endif
+#if defined(__CYGWIN__) && defined(__WINDOWS__)
+# undef __WINDOWS__
+#endif
+
+
+#ifdef __WINDOWS__
+/* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
+ separator when it is set. */
+# define LT_DIRSEP_CHAR '\\'
+# define LT_PATHSEP_CHAR ';'
+#else
+# define LT_PATHSEP_CHAR ':'
+#endif
+
+#if defined(_MSC_VER) /* Visual Studio */
+# define R_OK 4
+#endif
+
+/* fopen() mode flags for reading a text file */
+#undef LT_READTEXT_MODE
+#if defined(__WINDOWS__) || defined(__CYGWIN__)
+# define LT_READTEXT_MODE "rt"
+#else
+# define LT_READTEXT_MODE "r"
+#endif
+
+/* LT_CONC creates a new concatenated symbol for the compiler
+ in a portable way. */
+#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
+# define LT_CONC(s,t) s##t
+#else
+# define LT_CONC(s,t) s/**/t
+#endif
+
+#endif /*!LT__SYSTEM_H */
/* ltdl.c -- system independent dlopen wrapper
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
Originally by Thomas Tanner <tanner@ffii.org>
- This file is part of GNU Libtool.
+
+ 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
# include <stdio.h>
#endif
-/* Include the header defining malloc. On K&R C compilers,
- that's <malloc.h>, on ANSI C and ISO C compilers, that's <stdlib.h>. */
-#if HAVE_STDLIB_H
-# include <stdlib.h>
-#else
-# if HAVE_MALLOC_H
-# include <malloc.h>
-# endif
-#endif
-
#if HAVE_STRING_H
# include <string.h>
#else
#endif
#include "ltdl.h"
+#include "lt__alloc.h"
#if defined(HAVE_CLOSEDIR) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_DIRENT_H)
/* We have a fully operational dirent subsystem. */
# define LT_GLOBAL_DATA
#endif
-/* fopen() mode flags for reading a text file */
-#undef LT_READTEXT_MODE
-#if defined(__WINDOWS__) || defined(__CYGWIN__)
-# define LT_READTEXT_MODE "rt"
-#else
-# define LT_READTEXT_MODE "r"
-#endif
-
\f
/* --- MANIFEST CONSTANTS --- */
-\f
-/* --- MEMORY HANDLING --- */
-
-
-/* These are the functions used internally. In addition to making
- use of the associated function pointers above, they also perform
- error handling. */
-static char *lt_estrdup LT_PARAMS((const char *str));
-static lt_ptr lt_emalloc LT_PARAMS((size_t size));
-static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size));
-
-/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */
-#define rpl_realloc realloc
-
-/* These are the pointers that can be changed by the caller: */
-LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size))
- = (lt_ptr (*) LT_PARAMS((size_t))) malloc;
-LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size))
- = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc;
-LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
- = (void (*) LT_PARAMS((lt_ptr))) free;
-
-/* The following macros reduce the amount of typing needed to cast
- assigned memory. */
-#if WITH_DMALLOC
-
-#define LT_DLMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp)))
-#define LT_DLREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp)))
-#define LT_DLFREE(p) \
- LT_STMT_START { if (p) (p) = (xfree (p), (lt_ptr) 0); } LT_STMT_END
-
-#define LT_EMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp)))
-#define LT_EREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp)))
-
-#else
-
-#define LT_DLMALLOC(tp, n) ((tp *) lt_dlmalloc ((n) * sizeof(tp)))
-#define LT_DLREALLOC(tp, p, n) ((tp *) lt_dlrealloc ((p), (n) * sizeof(tp)))
-#define LT_DLFREE(p) \
- LT_STMT_START { if (p) (p) = (lt_dlfree (p), (lt_ptr) 0); } LT_STMT_END
-
-#define LT_EMALLOC(tp, n) ((tp *) lt_emalloc ((n) * sizeof(tp)))
-#define LT_EREALLOC(tp, p, n) ((tp *) lt_erealloc ((p), (n) * sizeof(tp)))
-
-#endif
-
-#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \
- if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \
- } LT_STMT_END
-
\f
/* --- REPLACEMENT FUNCTIONS --- */
-#undef strdup
-#define strdup rpl_strdup
-
-static char *strdup LT_PARAMS((const char *str));
-
-static char *
-strdup(str)
- const char *str;
-{
- char *tmp = 0;
-
- if (str)
- {
- tmp = LT_DLMALLOC (char, 1+ strlen (str));
- if (tmp)
- {
- strcpy(tmp, str);
- }
- }
-
- return tmp;
-}
-
-
#if ! HAVE_STRCMP
#undef strcmp
{
assert (entry != (DIR *) NULL);
FindClose (entry->hSearch);
- lt_dlfree ((lt_ptr) entry);
+ free ((lt_ptr) entry);
}
assert (path != (char *) NULL);
(void) strncpy (file_specification, path, LT_FILENAME_MAX-1);
(void) strcat (file_specification, "\\");
- entry = LT_DLMALLOC (DIR, sizeof(DIR));
+ entry = (DIR *) malloc (sizeof(DIR));
if (entry != (DIR *) 0)
{
entry->firsttime = TRUE;
entry->hSearch = FindFirstFile (file_specification,
&entry->Win32FindData);
- }
- if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- (void) strcat (file_specification, "\\*.*");
- entry->hSearch = FindFirstFile (file_specification,
- &entry->Win32FindData);
if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- LT_DLFREE (entry);
- return (DIR *) 0;
- }
+ {
+ (void) strcat (file_specification, "\\*.*");
+ entry->hSearch = FindFirstFile (file_specification,
+ &entry->Win32FindData);
+ if (entry->hSearch == INVALID_HANDLE_VALUE)
+ {
+ entry = (free (entry), (DIR *) 0);
+ }
+ }
}
return entry;
#endif /* !LT_USE_WINDOWS_DIRENT_EMULATION */
-/* According to Alexandre Oliva <oliva@lsd.ic.unicamp.br>,
- ``realloc is not entirely portable''
- In any case we want to use the allocator supplied by the user without
- burdening them with an lt_dlrealloc function pointer to maintain.
- Instead implement our own version (with known boundary conditions)
- using lt_dlmalloc and lt_dlfree. */
-
-/* #undef realloc
- #define realloc rpl_realloc
-*/
-#if 0
- /* You can't (re)define realloc unless you also (re)define malloc.
- Right now, this code uses the size of the *destination* to decide
- how much to copy. That's not right, but you can't know the size
- of the source unless you know enough about, or wrote malloc. So
- this code is disabled... */
-
-static lt_ptr
-realloc (ptr, size)
- lt_ptr ptr;
- size_t size;
-{
- if (size == 0)
- {
- /* For zero or less bytes, free the original memory */
- if (ptr != 0)
- {
- lt_dlfree (ptr);
- }
-
- return (lt_ptr) 0;
- }
- else if (ptr == 0)
- {
- /* Allow reallocation of a NULL pointer. */
- return lt_dlmalloc (size);
- }
- else
- {
- /* Allocate a new block, copy and free the old block. */
- lt_ptr mem = lt_dlmalloc (size);
-
- if (mem)
- {
- memcpy (mem, ptr, size);
- lt_dlfree (ptr);
- }
-
- /* Note that the contents of PTR are not damaged if there is
- insufficient memory to realloc. */
- return mem;
- }
-}
-#endif
-
#if ! HAVE_ARGZ_APPEND
# define argz_append rpl_argz_append
/* Ensure there is enough room to append BUF_LEN. */
argz_len = *pargz_len + buf_len;
- argz = LT_DLREALLOC (char, *pargz, argz_len);
+ argz = (char *) realloc (*pargz, argz_len);
if (!argz)
return ENOMEM;
/* Make a copy of STR, but replacing each occurence of
DELIM with '\0'. */
- argz_len = 1+ LT_STRLEN (str);
+ argz_len = 1+ strlen (str);
if (argz_len)
{
const char *p;
char *q;
- argz = LT_DLMALLOC (char, argz_len);
+ argz = (char *) malloc (argz_len);
if (!argz)
return ENOMEM;
/* If ARGZ_LEN has shrunk to nothing, release ARGZ's memory. */
if (!argz_len)
- LT_DLFREE (argz);
+ argz = (free (argz), (char *) 0);
/* Assign new values. */
*pargz = argz;
--before;
{
- size_t entry_len = 1+ LT_STRLEN (entry);
+ size_t entry_len = 1+ strlen (entry);
size_t argz_len = *pargz_len + entry_len;
size_t offset = before - *pargz;
- char *argz = LT_DLREALLOC (char, *pargz, argz_len);
+ char *argz = (char *) realloc (*pargz, argz_len);
if (!argz)
return ENOMEM;
#endif
-
\f
/* --- MUTEX LOCKING --- */
LT_DLMUTEX_LOCK ();
errindex = errorcount - LT_ERROR_MAX;
- temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex);
+ temp = REALLOC (const char *, user_error_strings, 1 + errindex);
if (temp)
{
user_error_strings = temp;
return errors;
}
-static lt_ptr
-lt_emalloc (size)
- size_t size;
-{
- lt_ptr mem = lt_dlmalloc (size);
- if (size && !mem)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return mem;
-}
-
-static lt_ptr
-lt_erealloc (addr, size)
- lt_ptr addr;
- size_t size;
-{
- lt_ptr mem = lt_dlrealloc (addr, size);
- if (size && !mem)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return mem;
-}
-
-static char *
-lt_estrdup (str)
- const char *str;
-{
- char *copy = strdup (str);
- if (LT_STRLEN (str) && !copy)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return copy;
-}
-
-
\f
/* --- DLOPEN() INTERFACE LOADER --- */
if (ext)
{
/* FILENAME already has an extension. */
- searchname = lt_estrdup (filename);
+ searchname = lt__strdup (filename);
}
else
{
/* Append a `.' to stop Windows from adding an
implicit `.dll' extension. */
- searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename));
+ searchname = MALLOC (char, 2+ LT_STRLEN (filename));
if (searchname)
sprintf (searchname, "%s.", filename);
}
#else
module = LoadLibrary (searchname);
#endif
- LT_DLFREE (searchname);
+ FREE (searchname);
/* libltdl expects this function to fail if it is unable
to physically load the library. Sadly, LoadLibrary
lt_user_data loader_data;
const char *filename;
{
- lt_module module = strdup (filename);
+ lt_module module = lt__strdup (filename);
if (dld_link (filename) != 0)
{
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
- LT_DLFREE (module);
- module = 0;
+ FREE (module);
}
return module;
}
else
{
- LT_DLFREE (module);
+ FREE (module);
}
return errors;
lt_dlsymlists_t *tmp = lists;
lists = lists->next;
- LT_DLFREE (tmp);
+ FREE (tmp);
}
preloaded_symbols = 0;
lists = lists->next;
}
- tmp = LT_EMALLOC (lt_dlsymlists_t, 1);
+ tmp = MALLOC (lt_dlsymlists_t, 1);
if (tmp)
{
memset (tmp, 0, sizeof(lt_dlsymlists_t));
const char *dlname,
const char *old_name,
int installed));
-static int free_vars LT_PARAMS((char *dlname, char *oldname,
- char *libdir, char *deplibs));
static int load_deplibs LT_PARAMS((lt_dlhandle handle,
char *deplibs));
static int trim LT_PARAMS((char **dest,
static lt_dlhandle handles = 0;
static int initialized = 0;
+/* Our memory failure callback sets the error message to be passed back
+ up to the client, so we must be careful to return from mallocation
+ callers if allocation fails (as this callback returns!!). */
+void
+lt__alloc_die_callback (void)
+{
+ LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
+}
+
/* Initialize libltdl. */
int
lt_dlinit ()
/* Initialize only at first call. */
if (++initialized == 1)
{
+ lt__alloc_die = lt__alloc_die_callback;
+
handles = 0;
user_search_path = 0; /* empty search path */
++errors;
}
- LT_DLMEM_REASSIGN (loader, next);
+ MEMREASSIGN (loader, next);
}
loaders = 0;
}
goto done;
} */
- cur->info.filename = lt_estrdup (filename);
+ cur->info.filename = lt__strdup (filename);
if (!cur->info.filename)
{
++errors;
if (!loader)
{
- LT_DLFREE (cur->info.filename);
+ FREE (cur->info.filename);
++errors;
goto done;
}
/* Allocate memory, and combine DIRNAME and MODULENAME into it.
The PREFIX (if any) is handled below. */
- filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1);
+ filename = MALLOC (char, dirname_len + 1 + filename_len + 1);
if (!filename)
return 1;
++error;
}
- LT_DLFREE (filename);
+ FREE (filename);
return error;
}
assert (path && *path);
assert (pcanonical);
- canonical = LT_EMALLOC (char, 1+ LT_STRLEN (path));
+ canonical = MALLOC (char, 1+ LT_STRLEN (path));
if (!canonical)
return 1;
if (lendir +1 +lenbase >= filenamesize)
{
- LT_DLFREE (filename);
+ FREE (filename);
filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */
- filename = LT_EMALLOC (char, filenamesize);
+ filename = MALLOC (char, filenamesize);
if (!filename)
goto cleanup;
}
}
cleanup:
- LT_DLFREE (argz);
- LT_DLFREE (canonical);
- LT_DLFREE (filename);
+ FREE (argz);
+ FREE (canonical);
+ FREE (filename);
LT_DLMUTEX_UNLOCK ();
if (dirend > filename)
*dirend = LT_EOS_CHAR;
- LT_DLFREE (*pdir);
- *pdir = lt_estrdup (filename);
+ FREE (*pdir);
+ *pdir = lt__strdup (filename);
is_done = (*pdir == 0) ? -1 : 1;
}
LT_DLMUTEX_LOCK ();
if (user_search_path)
{
- save_search_path = lt_estrdup (user_search_path);
+ save_search_path = lt__strdup (user_search_path);
if (!save_search_path)
goto cleanup;
}
}
/* restore the old search path */
- LT_DLFREE (user_search_path);
- user_search_path = save_search_path;
+ MEMREASSIGN (user_search_path, save_search_path);
LT_DLMUTEX_UNLOCK ();
goto cleanup;
}
- names = LT_EMALLOC (char *, depcount * sizeof (char*));
+ names = MALLOC (char *, depcount);
if (!names)
goto cleanup;
if (strncmp(p, "-l", 2) == 0)
{
size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2);
- name = LT_EMALLOC (char, 1+ name_len);
+ name = MALLOC (char, 1+ name_len);
if (name)
sprintf (name, "lib%s", p+2);
}
else
- name = lt_estrdup(p);
+ name = strdup(p);
if (!name)
goto cleanup_names;
{
int j = 0;
- handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount);
+ handle->deplibs = (lt_dlhandle*) MALLOC (lt_dlhandle *, depcount);
if (!handle->deplibs)
goto cleanup;
cleanup_names:
for (i = 0; i < depcount; ++i)
{
- LT_DLFREE (names[i]);
+ FREE (names[i]);
}
cleanup:
- LT_DLFREE (names);
+ FREE (names);
#endif
return errors;
size_t len = LT_STRLEN (str);
char *tmp;
- LT_DLFREE (*dest);
+ FREE (*dest);
if (len > 3 && str[0] == '\'')
{
- tmp = LT_EMALLOC (char, end - str);
+ tmp = MALLOC (char, end - str);
if (!tmp)
return 1;
return 0;
}
-static int
-free_vars (dlname, oldname, libdir, deplibs)
- char *dlname;
- char *oldname;
- char *libdir;
- char *deplibs;
-{
- LT_DLFREE (dlname);
- LT_DLFREE (oldname);
- LT_DLFREE (libdir);
- LT_DLFREE (deplibs);
-
- return 0;
-}
-
static int
try_dlopen (phandle, filename)
lt_dlhandle *phandle;
/* dlopen self? */
if (!filename)
{
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) MALLOC (struct lt_dlhandle_struct, 1);
if (*phandle == 0)
return 1;
if (tryall_dlopen (&newhandle, 0) != 0)
{
- LT_DLFREE (*phandle);
+ FREE (*phandle);
return 1;
}
{
size_t dirlen = (1+ base_name) - canonical;
- dir = LT_EMALLOC (char, 1+ dirlen);
+ dir = MALLOC (char, 1+ dirlen);
if (!dir)
{
++errors;
++base_name;
}
else
- LT_DLMEM_REASSIGN (base_name, canonical);
+ MEMREASSIGN (base_name, canonical);
assert (base_name && *base_name);
int installed = 1;
/* extract the module name from the file name */
- name = LT_EMALLOC (char, ext - base_name + 1);
+ name = MALLOC (char, ext - base_name + 1);
if (!name)
{
++errors;
}
line_len = LT_FILENAME_MAX;
- line = LT_EMALLOC (char, line_len);
+ line = MALLOC (char, line_len);
if (!line)
{
fclose (file);
that is longer than the initial buffer size. */
while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file)))
{
- line = LT_DLREALLOC (char, line, line_len *2);
+ line = REALLOC (char, line, line_len *2);
+ if (!line)
+ {
+ fclose (file);
+ ++errors;
+ goto cleanup;
+ }
if (!fgets (&line[line_len -1], (int) line_len +1, file))
{
break;
&& dlname
&& (last_libname = strrchr (dlname, ' ')) != 0)
{
- last_libname = lt_estrdup (last_libname + 1);
+ last_libname = strdup (last_libname + 1);
if (!last_libname)
{
++errors;
goto cleanup;
}
- LT_DLMEM_REASSIGN (dlname, last_libname);
+ MEMREASSIGN (dlname, last_libname);
}
}
}
fclose (file);
- LT_DLFREE (line);
+ FREE (line);
/* allocate the handle */
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) malloc (sizeof (struct lt_dlhandle_struct));
if (*phandle == 0)
++errors;
if (errors)
{
- free_vars (dlname, old_name, libdir, deplibs);
- LT_DLFREE (*phandle);
+ FREE (dlname);
+ FREE (old_name);
+ FREE (libdir);
+ FREE (deplibs);
+ FREE (*phandle);
goto cleanup;
}
++errors;
}
- free_vars (dlname, old_name, libdir, deplibs);
+ FREE (dlname);
+ FREE (old_name);
+ FREE (libdir);
+ FREE (deplibs);
+
if (errors)
{
- LT_DLFREE (*phandle);
+ FREE (*phandle);
goto cleanup;
}
else
{
/* not a libtool module */
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) MALLOC (struct lt_dlhandle_struct, 1);
if (*phandle == 0)
{
++errors;
if (!newhandle)
{
- LT_DLFREE (*phandle);
+ FREE (*phandle);
++errors;
goto cleanup;
}
}
register_handle:
- LT_DLMEM_REASSIGN (*phandle, newhandle);
+ MEMREASSIGN (*phandle, newhandle);
if ((*phandle)->info.ref_count == 0)
{
(*phandle)->info.ref_count = 1;
- LT_DLMEM_REASSIGN ((*phandle)->info.name, name);
+ MEMREASSIGN ((*phandle)->info.name, name);
LT_DLMUTEX_LOCK ();
(*phandle)->next = handles;
LT_DLMUTEX_SETERROR (saved_error);
cleanup:
- LT_DLFREE (dir);
- LT_DLFREE (name);
- LT_DLFREE (canonical);
+ FREE (dir);
+ FREE (name);
+ FREE (canonical);
return errors;
}
}
/* First try appending ARCHIVE_EXT. */
- tmp = LT_EMALLOC (char, len + LT_STRLEN (archive_ext) + 1);
+ tmp = MALLOC (char, len + LT_STRLEN (archive_ext) + 1);
if (!tmp)
return 0;
in the module search path. */
if (handle || ((errors > 0) && !file_not_found ()))
{
- LT_DLFREE (tmp);
+ FREE (tmp);
return handle;
}
/* Try appending SHLIB_EXT. */
if (LT_STRLEN (shlib_ext) > LT_STRLEN (archive_ext))
{
- LT_DLFREE (tmp);
- tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
+ FREE (tmp);
+ tmp = MALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
if (!tmp)
return 0;
with the current error message. */
if (handle || ((errors > 0) && !file_not_found ()))
{
- LT_DLFREE (tmp);
+ FREE (tmp);
return handle;
}
#endif
/* Still here? Then we really did fail to locate any of the file
names we tried. */
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
- LT_DLFREE (tmp);
+ FREE (tmp);
return 0;
}
/* Prepend the directory name. */
end_offset = end - dp->d_name;
buf_len = dir_len + 1+ end_offset;
- buf = LT_EMALLOC (char, 1+ buf_len);
+ buf = MALLOC (char, 1+ buf_len);
if (!buf)
return ++errors;
if (lt_argz_insertinorder (pargz, pargz_len, buf) != 0)
++errors;
- LT_DLFREE (buf);
+ FREE (buf);
return errors;
}
}
cleanup:
- LT_DLFREE (argz);
+ FREE (argz);
return is_done;
}
errors += unload_deplibs(handle);
/* It is up to the callers to free the data itself. */
- LT_DLFREE (handle->caller_data);
+ FREE (handle->caller_data);
- LT_DLFREE (handle->info.filename);
- LT_DLFREE (handle->info.name);
- LT_DLFREE (handle);
+ FREE (handle->info.filename);
+ FREE (handle->info.name);
+ FREE (handle);
goto done;
}
}
else
{
- sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1);
+ sym = MALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1);
if (!sym)
{
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW));
{
if (sym != lsym)
{
- LT_DLFREE (sym);
+ FREE (sym);
}
return address;
}
address = handle->loader->find_sym (data, handle->module, sym);
if (sym != lsym)
{
- LT_DLFREE (sym);
+ FREE (sym);
}
return address;
assert (!before); /* BEFORE cannot be set without PPATH. */
assert (dir); /* Without DIR, don't call this function! */
- *ppath = lt_estrdup (dir);
+ *ppath = strdup (dir);
if (*ppath == 0)
++errors;
}
argz_stringify (argz, argz_len, LT_PATHSEP_CHAR);
- LT_DLMEM_REASSIGN (*ppath, argz);
+ MEMREASSIGN(*ppath, argz);
cleanup:
- LT_DLFREE (canonical);
- LT_DLFREE (argz);
+ FREE (argz);
+ FREE (canonical);
return errors;
}
int errors = 0;
LT_DLMUTEX_LOCK ();
- LT_DLFREE (user_search_path);
+ FREE (user_search_path);
LT_DLMUTEX_UNLOCK ();
if (!search_path || !LT_STRLEN (search_path))
if (i == n_elements)
{
lt_caller_data *temp
- = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements);
+ = REALLOC (lt_caller_data, handle->caller_data, 2+ n_elements);
if (!temp)
{
}
/* Create a new dlloader node with copies of the user callbacks. */
- node = LT_EMALLOC (lt_dlloader, 1);
+ node = MALLOC (lt_dlloader, 1);
if (!node)
return 1;
errors = place->dlloader_exit (place->dlloader_data);
}
- LT_DLFREE (place);
+ FREE (place);
done:
LT_DLMUTEX_UNLOCK ();
return place;
}
+
+
+
+\f
+/* These pointers are part of the published interface to libltdl,
+ although they are no longer used. */
+LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) = 0;
+LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) = 0;
+LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) = 0;
/* ltdl.h -- generic dlopen functions
Copyright (C) 1998-2000 Free Software Foundation, Inc.
Originally by Thomas Tanner <tanner@ffii.org>
- This file is part of GNU Libtool.
+
+ 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
#ifndef LTDL_H
#define LTDL_H 1
-#include <sys/types.h> /* for size_t declaration */
-
-\f
-/* --- MACROS FOR PORTABILITY --- */
-
-
-/* Saves on those hard to debug '\0' typos.... */
-#define LT_EOS_CHAR '\0'
-
-/* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations,
- so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at
- the end of C declarations. */
-#ifdef __cplusplus
-# define LT_BEGIN_C_DECLS extern "C" {
-# define LT_END_C_DECLS }
-#else
-# define LT_BEGIN_C_DECLS /* empty */
-# define LT_END_C_DECLS /* empty */
-#endif
+#include <libltdl/lt_system.h>
LT_BEGIN_C_DECLS
-/* Canonicalise Windows and Cygwin recognition macros.
- To match the values set by recent Cygwin compilers, make sure that if
- __CYGWIN__ is defined (after canonicalisation), __WINDOWS__ is NOT! */
-#if defined(__CYGWIN32__) && !defined(__CYGWIN__)
-# define __CYGWIN__ __CYGWIN32__
-#endif
-#if defined(__CYGWIN__)
-# if defined(__WINDOWS__)
-# undef __WINDOWS__
-# endif
-#elif defined(_WIN32)
-# define __WINDOWS__ _WIN32
-#elif defined(WIN32)
-# define __WINDOWS__ WIN32
-#endif
-#if defined(__CYGWIN__) && defined(__WINDOWS__)
-# undef __WINDOWS__
-#endif
-
-
-#ifdef __WINDOWS__
-/* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
- separator when it is set. */
-# define LT_DIRSEP_CHAR '\\'
-# define LT_PATHSEP_CHAR ';'
-#else
-# define LT_PATHSEP_CHAR ':'
-#endif
-
/* DLL building support on win32 hosts; mostly to workaround their
ridiculous implementation of data symbol exporting. */
#ifndef LT_SCOPE
#endif
-#if defined(_MSC_VER) /* Visual Studio */
-# define R_OK 4
-#endif
-
-
/* LT_PARAMS is a macro used to wrap function prototypes, so that compilers
that don't understand ANSI C prototypes still work, and ANSI C
compilers can issue warnings about type mismatches. */
# define lt_ptr char*
#endif
-/* LT_STMT_START/END are used to create macros which expand to a
- a single compound statement in a portable way. */
-#if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
-# define LT_STMT_START (void)(
-# define LT_STMT_END )
-#else
-# if (defined (sun) || defined (__sun__))
-# define LT_STMT_START if (1)
-# define LT_STMT_END else (void)0
-# else
-# define LT_STMT_START do
-# define LT_STMT_END while (0)
-# endif
-#endif
-
-/* LT_CONC creates a new concatenated symbol for the compiler
- in a portable way. */
-#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
-# define LT_CONC(s,t) s##t
-#else
-# define LT_CONC(s,t) s/**/t
-#endif
/* LT_STRLEN can be used safely on NULL pointers. */
#define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0)
-\f
-/* --- MEMORY HANDLING --- */
-
-
-/* By default, the realloc function pointer is set to our internal
- realloc implementation which iself uses lt_dlmalloc and lt_dlfree.
- libltdl relies on a featureful realloc, but if you are sure yours
- has the right semantics then you can assign it directly. Generally,
- it is safe to assign just a malloc() and a free() function. */
-LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size));
-LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size));
-LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr));
-
-
-
\f
/* --- PRELOADED MODULE SUPPORT --- */
LT_SCOPE int lt_dlseterror LT_PARAMS((int errorcode));
+\f
+/* --- BINARY COMPATIBILITY WITH OLD LIBLTDL --- */
+
+LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size));
+LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size));
+LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr));
+
\f
-/* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */
+/* --- SOURCE COMPATIBILITY WITH ANCIENT LIBLTDL --- */
#ifdef LT_NON_POSIX_NAMESPACE