libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

less mixing of object and function pointers


From: Ralf Wildenhues
Subject: less mixing of object and function pointers
Date: Mon, 28 Aug 2006 19:02:33 +0200
User-agent: Mutt/1.5.12 (2006-08-10)

This rather mechanical patch fixes one half of the issue of mixing
pointers to data and pointers to functions, by changing the set of
callback functions to using two pointers to void and one pointer to
a function type (since we only need one function signature, there
is no problem with just using that; otherwise, we could still cast
between different function types).

Since we now have even more unused arguments, I decided to add a macro
LT__UNUSED to make GCC emit less warnings, and used that throughout
libltdl.

OK to apply?  Tested on GNU/Linux, where libltdl now passes
  make CFLAGS='-W -Wall -Werror'

for me.  (But I'm fixing this now only because it will make my next
bugfix easier.)

Cheers,
Ralf
        
        Avoid mixing functions and data pointers in callback functions,
        mark unused arguments for GCC.

        * libltdl/libltdl/lt__private.h (__attribute__, LT__UNUSED):
        New macros.
        * libltdl/loaders/dld_link.c: Use LT__UNUSED where
        appropriate.
        * libltdl/loaders/dlopen.c, libltdl/loaders/load_add_on.c,
        libltdl/loaders/loadlibrary.c, libltdl/loaders/preopen.c,
        libltdl/loaders/shl_load.c: Likewise.
        * libltdl/ltdl.c: Likewise.
        (load_deplibs) [!LTDL_DLOPEN_DEPLIBS]: Use separate definition
        for less preprocessor clutter.
        (callback_helper_func): New type.
        (foreach_callback_func): Add pointer to function for callbacks.
        (dummy_callback): New dummy function.
        (foreach_dirinpath, find_file_callback, find_handle_callback)
        (foreachfile_callback, lt_dlforeachfile): Adjust all callers and
        callees.

Index: libltdl/ltdl.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v
retrieving revision 1.240
diff -u -r1.240 ltdl.c
--- libltdl/ltdl.c      22 Jul 2006 20:34:06 -0000      1.240
+++ libltdl/ltdl.c      28 Aug 2006 16:36:11 -0000
@@ -84,20 +84,22 @@
 
 
 /* The type of a function used at each iteration of  foreach_dirinpath().  */
-typedef int    foreach_callback_func (char *filename, void *data1,
-                                      void *data2);
+typedef int     callback_helper_func  (const char *, void *);
+typedef int    foreach_callback_func (char *filename, callback_helper_func *,
+                                      void *data1, void *data2);
 
 static int     foreach_dirinpath     (const char *search_path,
                                       const char *base_name,
                                       foreach_callback_func *func,
+                                      callback_helper_func *fun1,
                                       void *data1, void *data2);
 
-static int     find_file_callback    (char *filename, void *data,
-                                      void *ignored);
-static int     find_handle_callback  (char *filename, void *data,
-                                      void *ignored);
-static int     foreachfile_callback  (char *filename, void *data1,
-                                      void *data2);
+static int     find_file_callback    (char *filename, callback_helper_func 
*ignored,
+                                      void *data1, void *data2);
+static int     find_handle_callback  (char *filename, callback_helper_func 
*ignored1,
+                                      void *data, void *ignored2);
+static int     foreachfile_callback  (char *filename, callback_helper_func 
*func,
+                                      void *data, void *ignored);
 
 
 static int     canonicalize_path     (const char *path, char **pcanonical);
@@ -582,7 +584,8 @@
    it is appended to each SEARCH_PATH element before FUNC is called.  */
 static int
 foreach_dirinpath (const char *search_path, const char *base_name,
-                  foreach_callback_func *func, void *data1, void *data2)
+                  foreach_callback_func *func, callback_helper_func *fun1,
+                  void *data1, void *data2)
 {
   int   result         = 0;
   size_t filenamesize  = 0;
@@ -629,7 +632,7 @@
            strcpy (filename +lendir, base_name);
          }
 
-       if ((result = (*func) (filename, data1, data2)))
+       if ((result = (*func) (filename, fun1, data1, data2)))
          {
            break;
          }
@@ -644,11 +647,18 @@
   return result;
 }
 
+static int dummy_callback (const char *ignored1 LT__UNUSED,
+                          void *ignored2 LT__UNUSED)
+{
+  return 0;
+}
+
 /* If FILEPATH can be opened, store the name of the directory component
    in DATA1, and the opened FILE* structure address in DATA2.  Otherwise
    DATA1 is unchanged, but DATA2 is set to a pointer to NULL.  */
 static int
-find_file_callback (char *filename, void *data1, void *data2)
+find_file_callback (char *filename, callback_helper_func *ignored LT__UNUSED,
+                   void *data1, void *data2)
 {
   char      **pdir     = (char **) data1;
   FILE      **pfile    = (FILE **) data2;
@@ -678,13 +688,15 @@
 {
   FILE *file = 0;
 
-  foreach_dirinpath (search_path, base_name, find_file_callback, pdir, &file);
+  foreach_dirinpath (search_path, base_name, find_file_callback, 
dummy_callback,
+                    pdir, &file);
 
   return file;
 }
 
 static int
-find_handle_callback (char *filename, void *data, void *ignored)
+find_handle_callback (char *filename, callback_helper_func *ignored1 
LT__UNUSED,
+                     void *data, void *ignored2 LT__UNUSED)
 {
   lt_dlhandle  *handle         = (lt_dlhandle *) data;
   int          notfound        = access (filename, R_OK);
@@ -711,26 +723,32 @@
     return 0;
 
   if (!foreach_dirinpath (search_path, base_name, find_handle_callback,
-                         handle, 0))
+                         dummy_callback, handle, 0))
     return 0;
 
   return handle;
 }
 
+#if !defined(LTDL_DLOPEN_DEPLIBS)
+static int
+load_deplibs (lt_dlhandle handle, char *deplibs LT__UNUSED)
+{
+  ((lt__handle *) handle)->depcount = 0;
+  return 0;
+}
+
+#else /* defined(LTDL_DLOPEN_DEPLIBS) */
 static int
 load_deplibs (lt_dlhandle handle, char *deplibs)
 {
-#if defined(LTDL_DLOPEN_DEPLIBS)
   char *p, *save_search_path = 0;
   int   depcount = 0;
   int  i;
   char **names = 0;
-#endif
   int  errors = 0;
 
   ((lt__handle *) handle)->depcount = 0;
 
-#if defined(LTDL_DLOPEN_DEPLIBS)
   if (!deplibs)
     {
       return errors;
@@ -871,10 +889,10 @@
   if (save_search_path) {
     MEMREASSIGN (user_search_path, save_search_path);
   }
-#endif
 
   return errors;
 }
+#endif /* defined(LTDL_DLOPEN_DEPLIBS) */
 
 static int
 unload_deplibs (lt_dlhandle handle)
@@ -1596,11 +1614,9 @@
 /* If there are any files in DIRNAME, call the function passed in
    DATA1 (with the name of each file and DATA2 as arguments).  */
 static int
-foreachfile_callback (char *dirname, void *data1, void *data2)
+foreachfile_callback (char *dirname, callback_helper_func *func,
+                     void *data, void *ignored LT__UNUSED)
 {
-  int (*func) (const char *filename, void *data)
-       = (int (*) (const char *filename, void *data)) data1;
-
   int    is_done  = 0;
   char   *argz     = 0;
   size_t  argz_len = 0;
@@ -1613,7 +1629,7 @@
   {
     char *filename = 0;
     while ((filename = argz_next (argz, argz_len, filename)))
-      if ((is_done = (*func) (filename, data2)))
+      if ((is_done = (*func) (filename, data)))
        break;
   }
 
@@ -1632,8 +1648,7 @@
    then the same directories that lt_dlopen would search are examined.  */
 int
 lt_dlforeachfile (const char *search_path,
-                 int (*func) (const char *filename, void *data),
-                 void *data)
+                 callback_helper_func *func, void *data)
 {
   int is_done = 0;
 
@@ -1641,32 +1656,32 @@
     {
       /* If a specific path was passed, search only the directories
         listed in it.  */
-      is_done = foreach_dirinpath (search_path, 0,
-                                  foreachfile_callback, func, data);
+      is_done = foreach_dirinpath (search_path, 0, foreachfile_callback,
+                                  func, data, NULL);
     }
   else
     {
       /* Otherwise search the default paths.  */
-      is_done = foreach_dirinpath (user_search_path, 0,
-                                  foreachfile_callback, func, data);
+      is_done = foreach_dirinpath (user_search_path, 0, foreachfile_callback,
+                                  func, data, NULL);
       if (!is_done)
        {
          is_done = foreach_dirinpath (getenv(LTDL_SEARCHPATH_VAR), 0,
-                                      foreachfile_callback, func, data);
+                                      foreachfile_callback, func, data, NULL);
        }
 
 #if defined(LT_MODULE_PATH_VAR)
       if (!is_done)
        {
          is_done = foreach_dirinpath (getenv(LT_MODULE_PATH_VAR), 0,
-                                      foreachfile_callback, func, data);
+                                      foreachfile_callback, func, data, NULL);
        }
 #endif
 #if defined(LT_DLSEARCH_PATH)
       if (!is_done && sys_dlsearch_path)
        {
          is_done = foreach_dirinpath (sys_dlsearch_path, 0,
-                                      foreachfile_callback, func, data);
+                                      foreachfile_callback, func, data, NULL);
        }
 #endif
     }
Index: libltdl/libltdl/lt__private.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt__private.h,v
retrieving revision 1.8
diff -u -r1.8 lt__private.h
--- libltdl/libltdl/lt__private.h       28 Aug 2006 16:02:14 -0000      1.8
+++ libltdl/libltdl/lt__private.h       28 Aug 2006 16:36:12 -0000
@@ -77,6 +77,16 @@
 #  define LT_GLOBAL_DATA
 #endif
 
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+#  define __attribute__(x)
+# endif
+#endif
+
+#ifndef LT__UNUSED
+# define LT__UNUSED __attribute__ ((__unused__))
+#endif
+
 
 LT_BEGIN_C_DECLS
 
Index: libltdl/loaders/dld_link.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/dld_link.c,v
retrieving revision 1.4
diff -u -r1.4 dld_link.c
--- libltdl/loaders/dld_link.c  22 Apr 2005 10:10:30 -0000      1.4
+++ libltdl/loaders/dld_link.c  28 Aug 2006 16:36:12 -0000
@@ -1,5 +1,5 @@
 /* loader-dld_link.c -- dynamic linking with dld
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -91,7 +91,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   lt_module module = lt__strdup (filename);
 
@@ -107,7 +107,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   int errors = 0;
 
@@ -127,7 +127,8 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module LT__UNUSED,
+       const char *name)
 {
   void *address = dld_get_func (name);
 
Index: libltdl/loaders/dlopen.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/dlopen.c,v
retrieving revision 1.5
diff -u -r1.5 dlopen.c
--- libltdl/loaders/dlopen.c    22 Apr 2005 10:10:30 -0000      1.5
+++ libltdl/loaders/dlopen.c    28 Aug 2006 16:36:12 -0000
@@ -1,5 +1,5 @@
 /* loader-dlopen.c --  dynamic linking with dlopen/dlsym
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -132,7 +132,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   lt_module module = dlopen (filename, LT_LAZY_OR_NOW);
 
@@ -148,7 +148,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   int errors = 0;
 
@@ -165,7 +165,7 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
   void *address = dlsym (module, name);
 
Index: libltdl/loaders/load_add_on.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/load_add_on.c,v
retrieving revision 1.4
diff -u -r1.4 load_add_on.c
--- libltdl/loaders/load_add_on.c       22 Apr 2005 10:10:30 -0000      1.4
+++ libltdl/loaders/load_add_on.c       28 Aug 2006 16:36:12 -0000
@@ -1,5 +1,5 @@
 /* loader-load_add_on.c --  dynamic linking for BeOS
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -89,7 +89,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   image_id image = 0;
 
@@ -118,7 +118,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   int errors = 0;
 
@@ -135,7 +135,7 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
   void *address = 0;
   image_id image = (image_id) module;
Index: libltdl/loaders/loadlibrary.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/loadlibrary.c,v
retrieving revision 1.10
diff -u -r1.10 loadlibrary.c
--- libltdl/loaders/loadlibrary.c       25 Nov 2005 18:44:43 -0000      1.10
+++ libltdl/loaders/loadlibrary.c       28 Aug 2006 16:36:12 -0000
@@ -96,7 +96,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   lt_module    module     = 0;
   char         *ext;
@@ -198,7 +198,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   int errors = 0;
 
@@ -215,7 +215,7 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
   void *address = GetProcAddress (module, name);
 
Index: libltdl/loaders/preopen.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/preopen.c,v
retrieving revision 1.8
diff -u -r1.8 preopen.c
--- libltdl/loaders/preopen.c   3 Apr 2006 13:54:35 -0000       1.8
+++ libltdl/loaders/preopen.c   28 Aug 2006 16:36:12 -0000
@@ -1,5 +1,5 @@
 /* loader-preopen.c -- emulate dynamic linking using preloaded_symbols
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -108,7 +108,7 @@
 
 /* A function called through the vtable to initialise this loader.  */
 static int
-vl_init (lt_user_data loader_data)
+vl_init (lt_user_data loader_data LT__UNUSED)
 {
   int errors = 0;
 
@@ -125,7 +125,7 @@
 /* A function called through the vtable when this loader is no
    longer needed by the application.  */
 static int
-vl_exit (lt_user_data loader_data)
+vl_exit (lt_user_data loader_data LT__UNUSED)
 {
   free_symlists ();
   return 0;
@@ -136,7 +136,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   symlist_chain *lists;
   lt_module     module = 0;
@@ -188,7 +188,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   /* Just to silence gcc -Wall */
   module = 0;
@@ -199,7 +199,7 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
   lt_dlsymlist        *symbol = (lt_dlsymlist*) module;
 
Index: libltdl/loaders/shl_load.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/shl_load.c,v
retrieving revision 1.5
diff -u -r1.5 shl_load.c
--- libltdl/loaders/shl_load.c  22 Apr 2005 10:10:30 -0000      1.5
+++ libltdl/loaders/shl_load.c  28 Aug 2006 16:36:12 -0000
@@ -1,5 +1,5 @@
 /* loader-shl_load.c --  dynamic linking with shl_load (HP-UX)
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -132,7 +132,7 @@
    loader.  Returns an opaque representation of the newly opened
    module for processing with this loader's other vtable functions.  */
 static lt_module
-vm_open (lt_user_data loader_data, const char *filename)
+vm_open (lt_user_data loader_data LT__UNUSED, const char *filename)
 {
   static shl_t self = (shl_t) 0;
   lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L);
@@ -167,7 +167,7 @@
 /* A function called through the vtable when a particular module
    should be unloaded.  */
 static int
-vm_close (lt_user_data loader_data, lt_module module)
+vm_close (lt_user_data loader_data LT__UNUSED, lt_module module)
 {
   int errors = 0;
 
@@ -184,7 +184,7 @@
 /* A function called through the vtable to get the address of
    a symbol loaded from a particular module.  */
 static void *
-vm_sym (lt_user_data loader_data, lt_module module, const char *name)
+vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
   void *address = 0;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]