[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 363] Allow better compile time type checking for lt_dladvise
From: |
Gary V. Vaughan |
Subject: |
[PATCH 363] Allow better compile time type checking for lt_dladvise |
Date: |
Sun, 20 Apr 2008 20:39:37 -0400 (EDT) |
User-agent: |
mailnotify/0.9 |
* libltdl/lt__private.h (lt__handle, lt__advise): Typedefs
removed in favour of...
* libltdl/ltdl.h (lt_dlhandle),
libltdl/libltdl/lt_dlloader.h (lt_dladvise): ...changing from
void* to forward declarations.
* libltdl/loaders/dlopen.c, libltdl/loaders/loadlibrary.c,
libltdl/lt_dlloader.c, libltdl/ltdl.c: Remove many redundant
type casts.
* NEWS: Updated.
Suggested by Bob Friesenhahn <address@hidden>
---
Now we get compile time errors for mistakes like this:
] cat > advise.c <<EOF
#include <ltdl.h>
lt_dlhandle
my_dlopenext (const char *filename)
{
lt_dlhandle handle;
lt_dladvise advise;
if (lt_dladvise_init (&advise) || lt_dladvise_ext (&advise))
exit(1);
handle = lt_dlopenadvise (filename, &advise);
lt_dladvise_destroy (&advise);
return handle;
}
EOF
] gcc -c -I ../../libltdl -o advise.o advise.c
advise.c: In function 'my_dlopenext':
advise.c:11: warning: passing argument 2 of 'lt_dlopenadvise' from
incompatible pointer type
Okay to apply?
ChangeLog | 12 ++++
NEWS | 4 ++
libltdl/libltdl/lt__private.h | 8 +--
libltdl/libltdl/lt_dlloader.h | 4 +-
libltdl/loaders/dlopen.c | 8 ++--
libltdl/loaders/loadlibrary.c | 4 +-
libltdl/lt_dlloader.c | 4 +-
libltdl/ltdl.c | 113 ++++++++++++++++++++---------------------
libltdl/ltdl.h | 4 +-
9 files changed, 85 insertions(+), 76 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8d2e5c3..18a58e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2008-04-20 Gary V. Vaughan <address@hidden>
+ Allow better compile time type checking for lt_dladvise.
+ * libltdl/lt__private.h (lt__handle, lt__advise): Typedefs
+ removed in favour of...
+ * libltdl/ltdl.h (lt_dlhandle),
+ libltdl/libltdl/lt_dlloader.h (lt_dladvise): ...changing from
+ void* to forward declarations.
+ * libltdl/loaders/dlopen.c, libltdl/loaders/loadlibrary.c,
+ libltdl/lt_dlloader.c, libltdl/ltdl.c: Remove many redundant
+ type casts.
+ * NEWS: Updated.
+ Suggested by Bob Friesenhahn <address@hidden>
+
Fix misleading lt_dlopenadvise documentation.
* doc/libtool.texi (lt_dlopenadvise): The last parameter is of
type lt_dladvise, not lt_dladvise*.
diff --git a/NEWS b/NEWS
index 300a57f..2fd7f0d 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ New in 2.2.4: 2008-??-??: CVS version 2.2.3a, Libtool team:
- The documentation for lt_dlopenadvise showed the wrong type for
the lt_dladvise parameter.
+ - The public declarations for lt_dlhandle and lt_dladvise are now
+ incomplete struct types rather than void*, which means that nearly
+ all casting is eliminated allowing the compiler to provide more
+ type checking.
New in 2.2.2: 2008-04-01: CVS version 2.2.1a, Libtool team:
diff --git a/libltdl/libltdl/lt__private.h b/libltdl/libltdl/lt__private.h
index c258df8..4ce936d 100644
--- a/libltdl/libltdl/lt__private.h
+++ b/libltdl/libltdl/lt__private.h
@@ -1,6 +1,6 @@
/* lt__private.h -- internal apis for libltdl
- Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
NOTE: The canonical source of this file is maintained with the
@@ -107,10 +107,8 @@ typedef struct {
void * data;
} lt_interface_data;
-typedef struct lt__handle lt__handle;
-
struct lt__handle {
- lt__handle * next;
+ lt_dlhandle next;
const lt_dlvtable * vtable; /* dlopening interface */
lt_dlinfo info; /* user visible fields */
int depcount; /* number of dependencies */
@@ -121,8 +119,6 @@ struct lt__handle {
int flags; /* various boolean stats */
};
-typedef struct lt__advise lt__advise;
-
struct lt__advise {
unsigned int try_ext:1; /* try system library extensions. */
unsigned int is_resident:1; /* module can't be unloaded. */
diff --git a/libltdl/libltdl/lt_dlloader.h b/libltdl/libltdl/lt_dlloader.h
index 9512b35..ae131fa 100644
--- a/libltdl/libltdl/lt_dlloader.h
+++ b/libltdl/libltdl/lt_dlloader.h
@@ -1,6 +1,6 @@
/* lt_dlloader.h -- dynamic library loader interface
- Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
NOTE: The canonical source of this file is maintained with the
@@ -38,7 +38,7 @@ LT_BEGIN_C_DECLS
typedef void * lt_dlloader;
typedef void * lt_module;
typedef void * lt_user_data;
-typedef void * lt_dladvise;
+typedef struct lt__advise * lt_dladvise;
/* Function pointer types for module loader vtable entries: */
typedef lt_module lt_module_open (lt_user_data data,
diff --git a/libltdl/loaders/dlopen.c b/libltdl/loaders/dlopen.c
index 94680c5..b445407 100644
--- a/libltdl/loaders/dlopen.c
+++ b/libltdl/loaders/dlopen.c
@@ -174,20 +174,20 @@ vm_open (lt_user_data LT__UNUSED loader_data, const char
*filename,
#ifdef RTLD_GLOBAL
/* If there is some means of asking for global symbol resolution,
do so. */
- if (((lt__advise *) advise)->is_symglobal)
+ if (advise->is_symglobal)
module_flags |= RTLD_GLOBAL;
#else
/* Otherwise, reset that bit so the caller can tell it wasn't
acted on. */
- ((lt__advise *) advise)->is_symglobal = 0;
+ advise->is_symglobal = 0;
#endif
/* And similarly for local only symbol resolution. */
#ifdef RTLD_LOCAL
- if (((lt__advise *) advise)->is_symlocal)
+ if (advise->is_symlocal)
module_flags |= RTLD_LOCAL;
#else
- ((lt__advise *) advise)->is_symlocal = 0;
+ advise->is_symlocal = 0;
#endif
}
diff --git a/libltdl/loaders/loadlibrary.c b/libltdl/loaders/loadlibrary.c
index de5eee8..609870c 100644
--- a/libltdl/loaders/loadlibrary.c
+++ b/libltdl/loaders/loadlibrary.c
@@ -184,9 +184,9 @@ vm_open (lt_user_data LT__UNUSED loader_data, const char
*filename,
an already loaded module, and simulate failure if we
find one. */
{
- lt__handle * cur = 0;
+ lt_dlhandle cur = 0;
- while ((cur = (lt__handle *) lt_dlhandle_iterate (iface_id, (lt_dlhandle)
cur)))
+ while ((cur = lt_dlhandle_iterate (iface_id, cur)))
{
if (!cur->module)
{
diff --git a/libltdl/lt_dlloader.c b/libltdl/lt_dlloader.c
index cd4efcd..4e66a6c 100644
--- a/libltdl/lt_dlloader.c
+++ b/libltdl/lt_dlloader.c
@@ -1,6 +1,6 @@
/* lt_dlloader.c -- dynamic library loader interface
- Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
NOTE: The canonical source of this file is maintained with the
@@ -169,7 +169,7 @@ lt_dlloader_remove (char *name)
iface = lt_dlinterface_register (id_string, NULL);
while ((handle = lt_dlhandle_iterate (iface, handle)))
{
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
if (cur->vtable == vtable)
{
in_use = 1;
diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c
index 10716a8..c8edcb4 100644
--- a/libltdl/ltdl.c
+++ b/libltdl/ltdl.c
@@ -1,7 +1,7 @@
/* ltdl.c -- system independent dlopen wrapper
Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006,
- 2007 Free Software Foundation, Inc.
+ 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the
@@ -60,9 +60,9 @@ or obtained by writing to the Free Software Foundation, Inc.,
/* Various boolean flags can be stored in the flags field of an
lt_dlhandle... */
-#define LT_DLIS_RESIDENT(handle) (((lt__handle*)handle)->info.is_resident)
-#define LT_DLIS_SYMGLOBAL(handle) (((lt__handle*)handle)->info.is_symglobal)
-#define LT_DLIS_SYMLOCAL(handle) (((lt__handle*)handle)->info.is_symlocal)
+#define LT_DLIS_RESIDENT(handle) ((handle)->info.is_resident)
+#define LT_DLIS_SYMGLOBAL(handle) ((handle)->info.is_symglobal)
+#define LT_DLIS_SYMLOCAL(handle) ((handle)->info.is_symlocal)
static const char objdir[] = LT_OBJDIR;
@@ -251,7 +251,7 @@ lt_dlexit (void)
{
/* shut down libltdl */
lt_dlloader *loader = 0;
- lt__handle *handle = (lt__handle *) handles;
+ lt_dlhandle handle = handles;
int errors = 0;
if (!initialized)
@@ -268,18 +268,18 @@ lt_dlexit (void)
while (handles && LT_DLIS_RESIDENT (handles))
{
- handles = ((lt__handle *) handles)->next;
+ handles = handles->next;
}
/* close all modules */
for (level = 1; handle; ++level)
{
- lt__handle *cur = (lt__handle *) handles;
+ lt_dlhandle cur = handles;
int saw_nonresident = 0;
while (cur)
{
- lt__handle *tmp = cur;
+ lt_dlhandle tmp = cur;
cur = cur->next;
if (!LT_DLIS_RESIDENT (tmp))
{
@@ -296,11 +296,11 @@ lt_dlexit (void)
pointed to by 'cur'. */
if (cur)
{
- for (tmp = (lt__handle *) handles; tmp; tmp =
tmp->next)
+ for (tmp = handles; tmp; tmp = tmp->next)
if (tmp == cur)
break;
if (! tmp)
- cur = (lt__handle *) handles;
+ cur = handles;
}
}
}
@@ -351,12 +351,11 @@ lt_dlexit (void)
the dlhandle is stored at the address given in PHANDLE. */
static int
tryall_dlopen (lt_dlhandle *phandle, const char *filename,
- lt_dladvise padvise, const lt_dlvtable *vtable)
+ lt_dladvise advise, const lt_dlvtable *vtable)
{
- lt__handle * handle = (lt__handle *) handles;
+ lt_dlhandle handle = handles;
const char * saved_error = 0;
int errors = 0;
- lt__advise * advise = (lt__advise *) padvise;
#ifdef LT_DEBUG_LOADERS
fprintf (stderr, "tryall_dlopen (%s, %s)\n",
@@ -384,7 +383,7 @@ tryall_dlopen (lt_dlhandle *phandle, const char *filename,
goto done;
}
- handle = (lt__handle *) *phandle;
+ handle = *phandle;
if (filename)
{
/* Comment out the check of file permissions using access.
@@ -759,7 +758,7 @@ find_file (const char *search_path, const char *base_name,
char **pdir)
static int
find_handle_callback (char *filename, void *data, void *data2)
{
- lt_dlhandle *handle = (lt_dlhandle *) data;
+ lt_dlhandle *phandle = (lt_dlhandle *) data;
int notfound = access (filename, R_OK);
lt_dladvise advise = (lt_dladvise) data2;
@@ -769,8 +768,8 @@ find_handle_callback (char *filename, void *data, void
*data2)
/* Try to dlopen the file, but do not continue searching in any
case. */
- if (tryall_dlopen (handle, filename, advise, 0) != 0)
- *handle = 0;
+ if (tryall_dlopen (phandle, filename, advise, 0) != 0)
+ *phandle = 0;
return 1;
}
@@ -779,23 +778,23 @@ find_handle_callback (char *filename, void *data, void
*data2)
found but could not be opened, *HANDLE will be set to 0. */
static lt_dlhandle *
find_handle (const char *search_path, const char *base_name,
- lt_dlhandle *handle, lt_dladvise advise)
+ lt_dlhandle *phandle, lt_dladvise advise)
{
if (!search_path)
return 0;
if (!foreach_dirinpath (search_path, base_name, find_handle_callback,
- handle, advise))
+ phandle, advise))
return 0;
- return handle;
+ return phandle;
}
#if !defined(LTDL_DLOPEN_DEPLIBS)
static int
load_deplibs (lt_dlhandle handle, char * LT__UNUSED deplibs)
{
- ((lt__handle *) handle)->depcount = 0;
+ handle->depcount = 0;
return 0;
}
@@ -809,7 +808,7 @@ load_deplibs (lt_dlhandle handle, char *deplibs)
char **names = 0;
int errors = 0;
- ((lt__handle *) handle)->depcount = 0;
+ handle->depcount = 0;
if (!deplibs)
{
@@ -919,10 +918,10 @@ load_deplibs (lt_dlhandle handle, char *deplibs)
later on if the loaded module cannot resolve all of its symbols. */
if (depcount)
{
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
int j = 0;
- cur->deplibs = (lt_dlhandle *) MALLOC (lt__handle, depcount);
+ cur->deplibs = (lt_dlhandle) MALLOC (struct lt__handle, depcount);
if (!cur->deplibs)
goto cleanup_names;
@@ -961,7 +960,7 @@ unload_deplibs (lt_dlhandle handle)
{
int i;
int errors = 0;
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
if (cur->depcount)
{
@@ -1152,14 +1151,14 @@ try_dlopen (lt_dlhandle *phandle, const char *filename,
const char *ext,
/* dlopen self? */
if (!filename)
{
- *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));
+ *phandle = (lt_dlhandle) lt__zalloc (sizeof (struct lt__handle));
if (*phandle == 0)
return 1;
newhandle = *phandle;
/* lt_dlclose()ing yourself is very bad! Disallow it. */
- ((lt__handle *) newhandle)->info.is_resident = 1;
+ newhandle->info.is_resident = 1;
if (tryall_dlopen (&newhandle, 0, advise, 0) != 0)
{
@@ -1258,7 +1257,7 @@ try_dlopen (lt_dlhandle *phandle, const char *filename,
const char *ext,
if (vtable)
{
- *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));
+ *phandle = (lt_dlhandle) lt__zalloc (sizeof (struct lt__handle));
if (*phandle == NULL)
{
@@ -1349,7 +1348,7 @@ try_dlopen (lt_dlhandle *phandle, const char *filename,
const char *ext,
fclose (file);
/* allocate the handle */
- *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));
+ *phandle = (lt_dlhandle) lt__zalloc (sizeof (struct lt__handle));
if (*phandle == 0)
++errors;
@@ -1400,7 +1399,7 @@ try_dlopen (lt_dlhandle *phandle, const char *filename,
const char *ext,
else
{
/* not a libtool module */
- *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));
+ *phandle = (lt_dlhandle) lt__zalloc (sizeof (struct lt__handle));
if (*phandle == 0)
{
++errors;
@@ -1444,13 +1443,13 @@ try_dlopen (lt_dlhandle *phandle, const char *filename,
const char *ext,
register_handle:
MEMREASSIGN (*phandle, newhandle);
- if (((lt__handle *) *phandle)->info.ref_count == 0)
+ if ((*phandle)->info.ref_count == 0)
{
- ((lt__handle *) *phandle)->info.ref_count = 1;
- MEMREASSIGN (((lt__handle *) *phandle)->info.name, name);
+ (*phandle)->info.ref_count = 1;
+ MEMREASSIGN ((*phandle)->info.name, name);
- ((lt__handle *) *phandle)->next = (lt__handle *) handles;
- handles = *phandle;
+ (*phandle)->next = handles;
+ handles = *phandle;
}
LT__SETERRORSTR (saved_error);
@@ -1511,7 +1510,7 @@ has_library_ext (const char *filename)
int
lt_dladvise_init (lt_dladvise *padvise)
{
- lt__advise *advise = (lt__advise *) lt__zalloc (sizeof (lt__advise));
+ lt_dladvise advise = (lt_dladvise) lt__zalloc (sizeof (struct lt__advise));
*padvise = advise;
return (advise ? 0 : 1);
}
@@ -1528,7 +1527,7 @@ int
lt_dladvise_ext (lt_dladvise *padvise)
{
assert (padvise && *padvise);
- ((lt__advise *) *padvise)->try_ext = 1;
+ (*padvise)->try_ext = 1;
return 0;
}
@@ -1536,7 +1535,7 @@ int
lt_dladvise_resident (lt_dladvise *padvise)
{
assert (padvise && *padvise);
- ((lt__advise *) *padvise)->is_resident = 1;
+ (*padvise)->is_resident = 1;
return 0;
}
@@ -1544,7 +1543,7 @@ int
lt_dladvise_local (lt_dladvise *padvise)
{
assert (padvise && *padvise);
- ((lt__advise *) *padvise)->is_symlocal = 1;
+ (*padvise)->is_symlocal = 1;
return 0;
}
@@ -1552,7 +1551,7 @@ int
lt_dladvise_global (lt_dladvise *padvise)
{
assert (padvise && *padvise);
- ((lt__advise *) *padvise)->is_symglobal = 1;
+ (*padvise)->is_symglobal = 1;
return 0;
}
@@ -1589,9 +1588,7 @@ lt_dlopenadvise (const char *filename, lt_dladvise advise)
int errors = 0;
/* Can't have symbols hidden and visible at the same time! */
- if (advise
- && ((lt__advise *) advise)->is_symlocal
- && ((lt__advise *) advise)->is_symglobal)
+ if (advise && advise->is_symlocal && advise->is_symglobal)
{
LT__SETERROR (CONFLICTING_FLAGS);
return 0;
@@ -1599,7 +1596,7 @@ lt_dlopenadvise (const char *filename, lt_dladvise advise)
if (!filename
|| !advise
- || !((lt__advise *) advise)->try_ext
+ || !advise->try_ext
|| has_library_ext (filename))
{
/* Just incase we missed a code path in try_dlopen() that reports
@@ -1872,11 +1869,11 @@ lt_dlforeachfile (const char *search_path,
int
lt_dlclose (lt_dlhandle handle)
{
- lt__handle *cur, *last;
+ lt_dlhandle cur, last;
int errors = 0;
/* check whether the handle is valid */
- last = cur = (lt__handle *) handles;
+ last = cur = handles;
while (cur && handle != cur)
{
last = cur;
@@ -1890,7 +1887,7 @@ lt_dlclose (lt_dlhandle handle)
goto done;
}
- cur = (lt__handle *) handle;
+ cur = handle;
cur->info.ref_count--;
/* Note that even with resident modules, we must track the ref_count
@@ -1941,7 +1938,7 @@ lt_dlsym (lt_dlhandle place, const char *symbol)
char *sym;
void *address;
lt_user_data data;
- lt__handle *handle;
+ lt_dlhandle handle;
if (!place)
{
@@ -1949,7 +1946,7 @@ lt_dlsym (lt_dlhandle place, const char *symbol)
return 0;
}
- handle = (lt__handle *) place;
+ handle = place;
if (!symbol)
{
@@ -2189,7 +2186,7 @@ lt_dlmakeresident (lt_dlhandle handle)
}
else
{
- ((lt__handle *) handle)->info.is_resident = 1;
+ handle->info.is_resident = 1;
}
return errors;
@@ -2247,7 +2244,7 @@ lt_dlcaller_set_data (lt_dlinterface_id key, lt_dlhandle
handle, void *data)
{
int n_elements = 0;
void *stale = (void *) 0;
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
int i;
if (cur->interface_data)
@@ -2293,7 +2290,7 @@ void *
lt_dlcaller_get_data (lt_dlinterface_id key, lt_dlhandle handle)
{
void *result = (void *) 0;
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
/* Locate the index of the element with a matching KEY. */
if (cur->interface_data)
@@ -2321,20 +2318,20 @@ lt_dlgetinfo (lt_dlhandle handle)
return 0;
}
- return &(((lt__handle *) handle)->info);
+ return &(handle->info);
}
lt_dlhandle
lt_dlhandle_iterate (lt_dlinterface_id iface, lt_dlhandle place)
{
- lt__handle *handle = (lt__handle *) place;
+ lt_dlhandle handle = place;
lt__interface_id *iterator = (lt__interface_id *) iface;
assert (iface); /* iface is a required argument */
if (!handle)
- handle = (lt__handle *) handles;
+ handle = handles;
else
handle = handle->next;
@@ -2345,7 +2342,7 @@ lt_dlhandle_iterate (lt_dlinterface_id iface, lt_dlhandle
place)
handle = handle->next;
}
- return (lt_dlhandle) handle;
+ return handle;
}
@@ -2358,7 +2355,7 @@ lt_dlhandle_fetch (lt_dlinterface_id iface, const char
*module_name)
while ((handle = lt_dlhandle_iterate (iface, handle)))
{
- lt__handle *cur = (lt__handle *) handle;
+ lt_dlhandle cur = handle;
if (cur && cur->info.name && streq (cur->info.name, module_name))
break;
}
@@ -2372,7 +2369,7 @@ lt_dlhandle_map (lt_dlinterface_id iface,
int (*func) (lt_dlhandle handle, void *data), void *data)
{
lt__interface_id *iterator = (lt__interface_id *) iface;
- lt__handle *cur = (lt__handle *) handles;
+ lt_dlhandle cur = handles;
assert (iface); /* iface is a required argument */
diff --git a/libltdl/ltdl.h b/libltdl/ltdl.h
index bd76661..bc60b88 100644
--- a/libltdl/ltdl.h
+++ b/libltdl/ltdl.h
@@ -1,7 +1,7 @@
/* ltdl.h -- generic dlopen functions
Copyright (C) 1998-2000, 2004, 2005,
- 2007 Free Software Foundation, Inc.
+ 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the
@@ -47,7 +47,7 @@ LT_BEGIN_C_DECLS
/* --- DYNAMIC MODULE LOADING API --- */
-typedef void * lt_dlhandle; /* A loaded module. */
+typedef struct lt__handle *lt_dlhandle; /* A loaded module. */
/* Initialisation and finalisation functions for libltdl. */
LT_SCOPE int lt_dlinit (void);
--
1.5.4.3
pgpH_WnTHuHTJ.pgp
Description: PGP signature
- [PATCH 363] Allow better compile time type checking for lt_dladvise,
Gary V. Vaughan <=