libtool-patches
[Top][All Lists]
Advanced

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

make libltdl work with C++ compilers


From: Ralf Wildenhues
Subject: make libltdl work with C++ compilers
Date: Sun, 3 Sep 2006 17:57:10 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

I've been approached about making libltdl work when compiled by a C++
compiler.  While I am not a huge fan of the idea, there may be practical
advantages for projects using libltdl to this.  And libltdl shows strong
signs of this having been supported a (rather long) time ago.

The patch below is mostly mechanical, and fixes some bitrot that turned
up along the way (which is definitely a good thing).  With it, I can get
a full testsuite pass with
  ./configure CC=g++

on GNU/Linux, also with Intel icpc, and no regressions on AIX/xlC,
Cygwin, MinGW.

Some notes:
- const objects have static linkage by default in C++, as opposed to
  extern linkage in C.  This is important for the dlsym file created
  by libtool at link time -- see the ltmain.m4sh part of the patch --
  and the definition of LT_SCOPE.
- The spelling _cplusplus is plain wrong.  I used LT_{BEGIN,END}_C_DECLS
  whereever appropriate (i.e., not in files that should not depend on
  ltdl.h).
- Compilation with g++ fails on Cygwin due to bugs (missing
  `extern "C"') in the argz.h system header (bug report to follow on Cygwin
  list).
- On MinGW, the g++-3.2.3 I have installed needs LT__UNUSED to go before
  the parameter name (separate patch coming up for this).  For MSVC, a
  couple more small changes may be needed (to be dealt with together
  with other unapplied changes for this compiler).  But in any way, this
  patch shouldn't cause any regressions for compilation with a C
  compiler.
- I have not adjusted the libltdl/loaders/*.c files that I have not
  tested, other than declaring `get_vtable' with C interface. Additions
  welcome.

OK to apply?

Cheers,
Ralf

2006-09-03  George Bosilca <address@hidden>
        and Ralf Wildenhues <address@hidden>

        Make libltdl work when compiled with a C++ compiler.

        * libltdl/lt__alloc.c, libltdl/lt_dlloader.c, libltdl/ltdl.c,
        libltdl/slist.c, libltdl/libltdl/lt__alloc.h,
        libltdl/libltdl/lt_error.h, libltdl/libltdl/slist.h,
        libltdl/loaders/dld_link.c, libltdl/loaders/dlopen.c,
        libltdl/loaders/dyld.c, libltdl/loaders/load_add_on.c,
        libltdl/loaders/loadlibrary.c, libltdl/loaders/preopen.c,
        libltdl/loaders/shl_load.c, tests/stresstest.at,
        tests/testsuite.at, tests/f77demo/foo.h, tests/fcdemo/foo.h,
        tests/mdemo/foo.h, tests/mdemo/foo1.c, tests/mdemo/foo2.c,
        tests/mdemo/main.c:
        Allow sources to be compiled by a C++ compiler: Cast
        appropriately, add C linkage for `get_vtable' functions,
        do not use C++ keyword `delete'.  Convert test suite to C89.

        * libltdl/libltdl/lt__glibc.h: Wrap included argz.h in
        `extern "C"', for broken headers on Cygwin.

        * libltdl/argz_.h: It's __cplusplus, not _cplusplus.
        * libltdl/libltdl/slist.h: Likewise.

        * libltdl/config/ltmain.m4sh (func_mode_link): In the dlsym
        file, define a type for the symbol list, and declare the list
        `extern', so that it is extern even if compiled by a C++
        compiler.  The type definition helps avoid a compiler warning
        against anonymous extern struct.
        * libltdl/libltdl/lt_system.h: Add `extern' to `LT_SCOPE' for
        the same reason.

        * libltdl/loaders/loadlibrary.c: Add some casts to w32 types,
        for MSVC.

Index: libltdl/argz_.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/argz_.h,v
retrieving revision 1.5
diff -u -r1.5 argz_.h
--- libltdl/argz_.h     22 Apr 2005 10:10:30 -0000      1.5
+++ libltdl/argz_.h     3 Sep 2006 15:28:40 -0000
@@ -40,7 +40,7 @@
 #  define LT_SCOPE
 #endif
 
-#if defined(_cplusplus)
+#if defined(__cplusplus)
 extern "C" {
 #endif
 
@@ -54,7 +54,7 @@
                                 const char *entry);
 LT_SCOPE void   argz_stringify (char *argz, size_t argz_len, int sep);
 
-#if defined(_cplusplus)
+#if defined(__cplusplus)
 }
 #endif
 
Index: libltdl/lt__alloc.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/lt__alloc.c,v
retrieving revision 1.7
diff -u -r1.7 lt__alloc.c
--- libltdl/lt__alloc.c 28 Aug 2006 16:02:14 -0000      1.7
+++ libltdl/lt__alloc.c 3 Sep 2006 15:28:40 -0000
@@ -97,5 +97,5 @@
 char *
 lt__strdup (const char *string)
 {
-  return lt__memdup (string, strlen (string) +1);
+  return (char*) lt__memdup (string, strlen (string) +1);
 }
Index: libltdl/lt_dlloader.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/lt_dlloader.c,v
retrieving revision 1.7
diff -u -r1.7 lt_dlloader.c
--- libltdl/lt_dlloader.c       22 Apr 2005 10:10:30 -0000      1.7
+++ libltdl/lt_dlloader.c       3 Sep 2006 15:28:40 -0000
@@ -46,8 +46,8 @@
 static void *
 loader_callback (SList *item, void *userdata)
 {
-  const lt_dlvtable *vtable = item->userdata;
-  const char *     name    = userdata;
+  const lt_dlvtable *vtable = (const lt_dlvtable * )item->userdata;
+  const char *     name    = (const char *) userdata;
 
   assert (vtable);
 
@@ -111,7 +111,7 @@
 const lt_dlvtable *
 lt_dlloader_get        (lt_dlloader loader)
 {
-  return loader ? ((SList *) loader)->userdata : 0;
+  return (const lt_dlvtable *) (loader ? ((SList *) loader)->userdata : 0);
 }
 
 
@@ -155,7 +155,8 @@
     }
 
   /* If we got this far, remove the loader from our global list.  */
-  return slist_unbox (slist_remove (&loaders, loader_callback, name));
+  return (lt_dlvtable *)
+      slist_unbox ((SList *) slist_remove (&loaders, loader_callback, name));
 }
 
 
Index: libltdl/ltdl.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v
retrieving revision 1.242
diff -u -r1.242 ltdl.c
--- libltdl/ltdl.c      31 Aug 2006 05:34:01 -0000      1.242
+++ libltdl/ltdl.c      3 Sep 2006 15:28:40 -0000
@@ -159,7 +159,8 @@
 static int
 loader_init_callback (lt_dlhandle handle)
 {
-  return loader_init (lt_dlsym (handle, "get_vtable"), 0);
+  lt_get_vtable *vtable_func = (lt_get_vtable *) lt_dlsym (handle, 
"get_vtable");
+  return loader_init (vtable_func, 0);
 }
 #endif /* HAVE_LIBDLLOADER */
 
@@ -195,7 +196,9 @@
 #define get_vtable             preopen_LTX_get_vtable
 #define preloaded_symbols      LT_CONC3(lt_, LTDLOPEN, _LTX_preloaded_symbols)
 
+LT_BEGIN_C_DECLS
 LT_SCOPE const lt_dlvtable *   get_vtable (lt_user_data data);
+LT_END_C_DECLS
 #ifdef HAVE_LIBDLLOADER
 extern lt_dlsymlist            preloaded_symbols;
 #endif
@@ -289,9 +292,9 @@
        }
 
       /* close all loaders */
-      for (loader = lt_dlloader_next (NULL); loader;)
+      for (loader = (lt_dlloader *) lt_dlloader_next (NULL); loader;)
        {
-         lt_dlloader *next   = lt_dlloader_next (loader);
+         lt_dlloader *next   = (lt_dlloader *) lt_dlloader_next (loader);
          lt_dlvtable *vtable = (lt_dlvtable *) lt_dlloader_get (loader);
 
          if ((vtable = lt_dlloader_remove ((char *) vtable->name)))
@@ -340,7 +343,7 @@
       goto done;
     }
 
-  handle = *phandle;
+  handle = (lt__handle *) *phandle;
   if (filename)
     {
       /* Comment out the check of file permissions using access.
@@ -371,7 +374,7 @@
     const lt_dlvtable *vtable = 0;
     lt_dlloader *loader = 0;
 
-    while ((loader = lt_dlloader_next (loader)))
+    while ((loader = (lt_dlloader *) lt_dlloader_next (loader)))
       {
        vtable = lt_dlloader_get (loader);
        handle->module = (*vtable->module_open) (vtable->dlloader_data,
@@ -1321,7 +1324,7 @@
       ((lt__handle *) *phandle)->info.ref_count        = 1;
       MEMREASSIGN (((lt__handle *) *phandle)->info.name, name);
 
-      ((lt__handle *) *phandle)->next  = handles;
+      ((lt__handle *) *phandle)->next  = (lt__handle *) handles;
       handles                          = *phandle;
     }
 
@@ -1385,7 +1388,7 @@
   assert (filename);
 
   len = LT_STRLEN (filename);
-  ext = strrchr (filename, '.');
+  ext = (char *) strrchr (filename, '.');
 
   /* If FILENAME already bears a suitable extension, there is no need
      to try appending additional extensions.  */
@@ -2033,7 +2036,7 @@
 lt_dlinterface_id
 lt_dlinterface_register (const char *id_string, lt_dlhandle_interface *iface)
 {
-  lt__interface_id *interface_id = lt__malloc (sizeof *interface_id);
+  lt__interface_id *interface_id = (lt__interface_id *) lt__malloc (sizeof 
*interface_id);
 
   /* If lt__malloc fails, it will LT__SETERROR (NO_MEMORY), which
      can then be detected with lt_dlerror() if we return 0.  */
Index: libltdl/slist.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/slist.c,v
retrieving revision 1.6
diff -u -r1.6 slist.c
--- libltdl/slist.c     22 Apr 2005 10:10:30 -0000      1.6
+++ libltdl/slist.c     3 Sep 2006 15:28:41 -0000
@@ -48,14 +48,14 @@
        ...
 */
 SList *
-slist_delete (SList *head, void (*delete) (void *item))
+slist_delete (SList *head, void (*delete_fct) (void *item))
 {
-  assert (delete);
+  assert (delete_fct);
 
   while (head)
     {
       SList *next = head->next;
-      (*delete) (head);
+      (*delete_fct) (head);
       head = next;
     }
 
@@ -340,7 +340,7 @@
 SList *
 slist_box (const void *userdata)
 {
-  SList *item = malloc (sizeof *item);
+  SList *item = (SList *) malloc (sizeof *item);
 
   if (item)
     {
Index: libltdl/config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/config/ltmain.m4sh,v
retrieving revision 1.52
diff -u -r1.52 ltmain.m4sh
--- libltdl/config/ltmain.m4sh  25 Aug 2006 15:08:14 -0000      1.52
+++ libltdl/config/ltmain.m4sh  3 Sep 2006 15:28:43 -0000
@@ -940,31 +940,29 @@
          $ECHO >> "$output_objdir/$my_dlsyms" "\
 
 /* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
 "
          case $host in
          *cygwin* | *mingw* )
            $ECHO >> "$output_objdir/$my_dlsyms" "\
 /* DATA imports from DLLs on WIN32 con't be const, because
    runtime relocations are performed -- see ld's documentation
-   on pseudo-relocs.  */
-   struct {
-"
-           ;;
+   on pseudo-relocs.  */"
+           lt_dlsym_const= ;;
          *)
-           $ECHO >> "$output_objdir/$my_dlsyms" "\
-const struct {
-"
-           ;;
+           lt_dlsym_const=const ;;
          esac
 
          $ECHO >> "$output_objdir/$my_dlsyms" "\
-   const char *name;
-   void *address;
-}
+extern $lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[[]];
+$lt_dlsym_const lt_dlsymlist
 lt_${my_prefix}_LTX_preloaded_symbols[[]] =
 {\
-  { \"$my_originator\", (void *) 0 },
-"
+  { \"$my_originator\", (void *) 0 },"
 
          eval "$global_symbol_to_c_name_address" < "$nlist" >> 
"$output_objdir/$my_dlsyms"
 
Index: libltdl/libltdl/lt__alloc.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt__alloc.h,v
retrieving revision 1.3
diff -u -r1.3 lt__alloc.h
--- libltdl/libltdl/lt__alloc.h 8 Dec 2005 17:27:09 -0000       1.3
+++ libltdl/libltdl/lt__alloc.h 3 Sep 2006 15:28:43 -0000
@@ -37,7 +37,7 @@
 #define MALLOC(tp, n)          (tp*) lt__malloc((n) * sizeof(tp))
 #define REALLOC(tp, mem, n)    (tp*) lt__realloc((mem), (n) * sizeof(tp))
 #define FREE(mem)                                      LT_STMT_START { \
-       if (mem) (mem) = (free ((void *)mem), (void *) 0);      } LT_STMT_END
+       if (mem) { free ((void *)mem); mem = NULL; }    } LT_STMT_END
 #define MEMREASSIGN(p, q)                              LT_STMT_START { \
        if ((p) != (q)) { if (p) free (p); (p) = (q); (q) = 0; }        \
                                                                } LT_STMT_END
Index: libltdl/libltdl/lt__glibc.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt__glibc.h,v
retrieving revision 1.5
diff -u -r1.5 lt__glibc.h
--- libltdl/libltdl/lt__glibc.h 28 Aug 2006 16:02:14 -0000      1.5
+++ libltdl/libltdl/lt__glibc.h 3 Sep 2006 15:28:43 -0000
@@ -55,8 +55,16 @@
 #  define argz_stringify       lt__argz_stringify
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <argz.h>
 
+#ifdef __cplusplus
+}
+#endif
+
 # define slist_concat  lt__slist_concat
 # define slist_cons    lt__slist_cons
 # define slist_delete  lt__slist_delete
Index: libltdl/libltdl/lt_error.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt_error.h,v
retrieving revision 1.3
diff -u -r1.3 lt_error.h
--- libltdl/libltdl/lt_error.h  25 Sep 2005 07:01:29 -0000      1.3
+++ libltdl/libltdl/lt_error.h  3 Sep 2006 15:28:43 -0000
@@ -69,8 +69,8 @@
        LT_ERROR_MAX
 };
 
-/* Should be max of the error string lengths above */
-#define LT_ERROR_LEN_MAX (35)
+/* Should be max of the error string lengths above (plus one for C++) */
+#define LT_ERROR_LEN_MAX (36)
 
 /* These functions are only useful from inside custom module loaders. */
 LT_SCOPE int   lt_dladderror   (const char *diagnostic);
Index: libltdl/libltdl/lt_system.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt_system.h,v
retrieving revision 1.2
diff -u -r1.2 lt_system.h
--- libltdl/libltdl/lt_system.h 22 Apr 2005 10:10:30 -0000      1.2
+++ libltdl/libltdl/lt_system.h 3 Sep 2006 15:28:43 -0000
@@ -99,7 +99,7 @@
 #if !defined(LT_SCOPE)
 #  if defined(__WINDOWS__)
 #    if defined(DLL_EXPORT)            /* defined by libtool (if required) */
-#      define LT_SCOPE __declspec(dllexport)
+#      define LT_SCOPE extern __declspec(dllexport)
 #    endif
 #    if defined(LIBLTDL_DLL_IMPORT)    /* define if linking with this dll */
 #      define LT_SCOPE extern __declspec(dllimport)
Index: libltdl/libltdl/slist.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/slist.h,v
retrieving revision 1.3
diff -u -r1.3 slist.h
--- libltdl/libltdl/slist.h     22 Apr 2005 10:10:30 -0000      1.3
+++ libltdl/libltdl/slist.h     3 Sep 2006 15:28:43 -0000
@@ -47,7 +47,7 @@
 #  define LT_SCOPE
 #endif
 
-#if defined(_cplusplus)
+#if defined(__cplusplus)
 extern "C" {
 #endif
 
@@ -63,7 +63,7 @@
 LT_SCOPE SList *slist_concat   (SList *head, SList *tail);
 LT_SCOPE SList *slist_cons     (SList *item, SList *slist);
 
-LT_SCOPE SList *slist_delete   (SList *slist, void (*delete) (void *item));
+LT_SCOPE SList *slist_delete   (SList *slist, void (*delete_fct) (void *item));
 LT_SCOPE void *        slist_remove    (SList **phead, SListCallback *find,
                                 void *matchdata);
 LT_SCOPE SList *slist_reverse  (SList *slist);
@@ -82,7 +82,7 @@
 LT_SCOPE SList *slist_box      (const void *userdata);
 LT_SCOPE void *        slist_unbox     (SList *item);
 
-#if defined(_cplusplus)
+#if defined(__cplusplus)
 }
 #endif
 
Index: libltdl/loaders/dld_link.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/dld_link.c,v
retrieving revision 1.5
diff -u -r1.5 dld_link.c
--- libltdl/loaders/dld_link.c  30 Aug 2006 04:14:21 -0000      1.5
+++ libltdl/loaders/dld_link.c  3 Sep 2006 15:28:43 -0000
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     dld_link_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
Index: libltdl/loaders/dlopen.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/dlopen.c,v
retrieving revision 1.6
diff -u -r1.6 dlopen.c
--- libltdl/loaders/dlopen.c    30 Aug 2006 04:14:21 -0000      1.6
+++ libltdl/loaders/dlopen.c    3 Sep 2006 15:28:43 -0000
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     dlopen_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
@@ -56,7 +58,7 @@
 
   if (!vtable)
     {
-      vtable = lt__zalloc (sizeof *vtable);
+      vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
     }
 
   if (vtable && !vtable->name)
Index: libltdl/loaders/dyld.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/dyld.c,v
retrieving revision 1.5
diff -u -r1.5 dyld.c
--- libltdl/loaders/dyld.c      22 Apr 2005 10:10:30 -0000      1.5
+++ libltdl/loaders/dyld.c      3 Sep 2006 15:28:43 -0000
@@ -1,5 +1,5 @@
 /* loader-dyld.c -- dynamic linking on darwin and OS X
-   Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
    Originally by Peter O'Gorman <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     dyld_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
Index: libltdl/loaders/load_add_on.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/load_add_on.c,v
retrieving revision 1.5
diff -u -r1.5 load_add_on.c
--- libltdl/loaders/load_add_on.c       30 Aug 2006 04:14:21 -0000      1.5
+++ libltdl/loaders/load_add_on.c       3 Sep 2006 15:28:43 -0000
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     load_add_on_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
Index: libltdl/loaders/loadlibrary.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/loadlibrary.c,v
retrieving revision 1.11
diff -u -r1.11 loadlibrary.c
--- libltdl/loaders/loadlibrary.c       30 Aug 2006 04:14:21 -0000      1.11
+++ libltdl/loaders/loadlibrary.c       3 Sep 2006 15:28:43 -0000
@@ -1,5 +1,5 @@
 /* loader-loadlibrary.c --  dynamic linking for Win32
-   Copyright (C) 1998, 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006 Free Software Foundation, 
Inc.
    Originally by Thomas Tanner <address@hidden>
 
    NOTE: The canonical source of this file is maintained with the
@@ -40,7 +40,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     loadlibrary_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
@@ -62,7 +64,7 @@
 
   if (!vtable)
     {
-      vtable = lt__zalloc (sizeof *vtable);
+      vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
       iface_id = lt_dlinterface_register ("ltdl loadlibrary", NULL);
     }
 
@@ -107,7 +109,7 @@
     {
       /* Get the name of main module */
       *wpath = 0;
-      GetModuleFileName (NULL, wpath, sizeof (wpath));
+      GetModuleFileName (NULL, (LPCH) wpath, sizeof (wpath));
       filename = wpath;
     }
   else
@@ -153,7 +155,7 @@
     UINT errormode = SetErrorMode(SEM_FAILCRITICALERRORS);
     SetErrorMode(errormode | SEM_FAILCRITICALERRORS);
 
-    module = LoadLibrary (wpath);
+    module = LoadLibrary ((LPCSTR) wpath);
 
     /* Restore the error mode. */
     SetErrorMode(errormode);
@@ -202,7 +204,7 @@
 {
   int errors = 0;
 
-  if (FreeLibrary(module) == 0)
+  if (FreeLibrary((HMODULE) module) == 0)
     {
       LT__SETERROR (CANNOT_CLOSE);
       ++errors;
@@ -217,7 +219,7 @@
 static void *
 vm_sym (lt_user_data loader_data LT__UNUSED, lt_module module, const char 
*name)
 {
-  void *address = GetProcAddress (module, name);
+  void *address = (void *) GetProcAddress ((HMODULE) module, name);
 
   if (!address)
     {
Index: libltdl/loaders/preopen.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/preopen.c,v
retrieving revision 1.9
diff -u -r1.9 preopen.c
--- libltdl/loaders/preopen.c   30 Aug 2006 04:14:21 -0000      1.9
+++ libltdl/loaders/preopen.c   3 Sep 2006 15:28:43 -0000
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     preopen_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
@@ -58,7 +60,7 @@
 
   if (!vtable)
     {
-      vtable = lt__zalloc (sizeof *vtable);
+      vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
     }
 
   if (vtable && !vtable->name)
@@ -259,7 +261,7 @@
   /* Don't add the same list twice:  */
   if (!lists)
     {
-      symlist_chain *tmp = lt__zalloc (sizeof *tmp);
+      symlist_chain *tmp = (symlist_chain *) lt__zalloc (sizeof *tmp);
 
       if (tmp)
        {
Index: libltdl/loaders/shl_load.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/loaders/shl_load.c,v
retrieving revision 1.6
diff -u -r1.6 shl_load.c
--- libltdl/loaders/shl_load.c  30 Aug 2006 04:14:21 -0000      1.6
+++ libltdl/loaders/shl_load.c  3 Sep 2006 15:28:43 -0000
@@ -36,7 +36,9 @@
    be fetched from the preloaded symbol list by lt_dlsym():  */
 #define get_vtable     shl_load_LTX_get_vtable
 
+LT_BEGIN_C_DECLS
 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
+LT_END_C_DECLS
 
 
 /* Boilerplate code to set up the vtable for hooking this loader into
Index: tests/stresstest.at
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/stresstest.at,v
retrieving revision 1.9
diff -u -r1.9 stresstest.at
--- tests/stresstest.at 5 Feb 2006 09:56:44 -0000       1.9
+++ tests/stresstest.at 3 Sep 2006 15:28:43 -0000
@@ -30,10 +30,17 @@
 
 AT_DATA(a.c,
 [[/* all kinds of data items */
+#ifdef __cplusplus
+extern "C" {
+#endif
 int v1;
 static int v2;
 int v3 = 0;
 int v4 = 1;
+extern const int v5, v6;
+extern const char *v7;
+extern const char v8[];
+extern int (*const v12) (void);
 const int v5 = 0;
 const int v6 = 1;
 const char* v7 = "\01foo";
@@ -47,6 +54,9 @@
 large v13;
 large v14 = { { 0 } };
 large v15 = { { 1 } };
+#ifdef __cplusplus
+}
+#endif
 ]])
 
 AT_DATA(asyms,
@@ -73,7 +83,11 @@
 ]])
 
 AT_DATA(main.c,
-[[extern int v1;
+[[
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int v1;
 extern int v3, v4;
 extern const int v5, v6;
 extern const char* v7;
@@ -82,6 +96,9 @@
 extern int (*v10) (void);
 extern int (*v11) (void);
 extern int (*const v12) (void);
+#ifdef __cplusplus
+}
+#endif
 
 typedef struct { int arr[1000]; } large;
 extern large v13, v14, v15;
@@ -96,7 +113,10 @@
 ]])
 
 AT_DATA(dlself.c,
-[[extern int v1;
+[[#ifdef __cplusplus
+extern "C" {
+#endif
+extern int v1;
 extern int v3, v4;
 extern const int v5, v6;
 extern const char* v7;
@@ -119,6 +139,9 @@
 extern int (*w11) (void);
 extern int (*const w12) (void);
 extern large w13, w14, w15;
+#ifdef __cplusplus
+}
+#endif
 
 int main(void)
 {
@@ -131,6 +154,9 @@
 }
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 int w1;
 static int w2;
 int w3 = 0;
@@ -146,6 +172,9 @@
 large w13;
 large w14 = { { 0 } };
 large w15 = { { 1 } };
+#ifdef __cplusplus
+}
+#endif
 ]])
 
 AT_DATA(dlselfsyms,
Index: tests/testsuite.at
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/testsuite.at,v
retrieving revision 1.44
diff -u -r1.44 testsuite.at
--- tests/testsuite.at  3 Sep 2006 15:19:38 -0000       1.44
+++ tests/testsuite.at  3 Sep 2006 15:28:43 -0000
@@ -167,7 +167,10 @@
 # is omitted, then no Makefile is created.
 m4_define([_LTDL_PROJECT_FILES],
 [AT_DATA([module.c],
-[[const char *
+[[#ifdef __cplusplus
+extern "C"
+#endif
+const char *
 hello (void)
 {
   return "Hello!";
Index: tests/f77demo/foo.h
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/f77demo/foo.h,v
retrieving revision 1.2
diff -u -r1.2 foo.h
--- tests/f77demo/foo.h 22 Apr 2005 10:10:31 -0000      1.2
+++ tests/f77demo/foo.h 3 Sep 2006 15:28:44 -0000
@@ -1,5 +1,5 @@
 /* foo.h -- interface to fortran and C libraries
-   Copyright (C) 1998-1999 Free Software Foundation, Inc.
+   Copyright (C) 1998-1999, 2006 Free Software Foundation, Inc.
    This file is part of GNU Libtool.
 
 This program is free software; you can redistribute it and/or modify
@@ -41,7 +41,10 @@
  * Note that fortran passes args by reference, so
  * you need to provide pointers to your ints.
  */
-extern void F77_FUNC(fsub,FSUB)(int *arg, int *res);
-
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void F77_FUNC(fsub,FSUB)(int *arg, int *res);
 
 #endif
Index: tests/fcdemo/foo.h
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/fcdemo/foo.h,v
retrieving revision 1.1
diff -u -r1.1 foo.h
--- tests/fcdemo/foo.h  8 Aug 2005 09:23:57 -0000       1.1
+++ tests/fcdemo/foo.h  3 Sep 2006 15:28:44 -0000
@@ -41,7 +41,11 @@
  * Note that fortran passes args by reference, so
  * you need to provide pointers to your ints.
  */
-extern void FC_FUNC(fsub,FSUB)(int *arg, int *res);
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void FC_FUNC(fsub,FSUB)(int *arg, int *res);
 
 
 #endif
Index: tests/mdemo/foo.h
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/mdemo/foo.h,v
retrieving revision 1.2
diff -u -r1.2 foo.h
--- tests/mdemo/foo.h   22 Apr 2005 10:10:31 -0000      1.2
+++ tests/mdemo/foo.h   3 Sep 2006 15:28:44 -0000
@@ -1,5 +1,5 @@
 /* foo.h -- interface to the libfoo* libraries
-   Copyright (C) 1998-1999 Free Software Foundation, Inc.
+   Copyright (C) 1998-1999, 2006 Free Software Foundation, Inc.
    Originally by Thomas Tanner <address@hidden>
    This file is part of GNU Libtool.
 
@@ -22,6 +22,19 @@
 #ifndef _FOO_H_
 #define _FOO_H_ 1
 
+/* __BEGIN_DECLS should be used at the beginning of your declarations,
+   so that C++ compilers don't mangle their names.  Use __END_DECLS at
+   the end of C declarations. */
+#undef __BEGIN_DECLS
+#undef __END_DECLS
+#ifdef __cplusplus
+# define __BEGIN_DECLS extern "C" {
+# define __END_DECLS }
+#else
+# define __BEGIN_DECLS /* empty */
+# define __END_DECLS /* empty */
+#endif
+
 /* Silly constants that the functions return. */
 #define HELLO_RET 0xe110
 #define FOO_RET 0xf00
Index: tests/mdemo/foo1.c
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/mdemo/foo1.c,v
retrieving revision 1.2
diff -u -r1.2 foo1.c
--- tests/mdemo/foo1.c  22 Apr 2005 10:10:31 -0000      1.2
+++ tests/mdemo/foo1.c  3 Sep 2006 15:28:44 -0000
@@ -41,6 +41,7 @@
 }
 
 /* exported functions */
+__BEGIN_DECLS
 
 int
 foo1()
@@ -55,3 +56,5 @@
   printf ("** This is foolib 1 **\n");
   return HELLO_RET;
 }
+
+__END_DECLS
Index: tests/mdemo/foo2.c
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/mdemo/foo2.c,v
retrieving revision 1.2
diff -u -r1.2 foo2.c
--- tests/mdemo/foo2.c  22 Apr 2005 10:10:31 -0000      1.2
+++ tests/mdemo/foo2.c  3 Sep 2006 15:28:44 -0000
@@ -41,6 +41,7 @@
 }
 
 /* exported functions */
+__BEGIN_DECLS
 
 int
 foo2()
@@ -55,3 +56,5 @@
   printf ("** This is foolib 2 **\n");
   return HELLO_RET;
 }
+
+__END_DECLS
Index: tests/mdemo/main.c
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/mdemo/main.c,v
retrieving revision 1.4
diff -u -r1.4 main.c
--- tests/mdemo/main.c  31 Aug 2006 06:20:15 -0000      1.4
+++ tests/mdemo/main.c  3 Sep 2006 15:28:44 -0000
@@ -23,6 +23,10 @@
 #include <stdio.h>
 #include <string.h>
 
+LT_BEGIN_C_DECLS
+extern int myfunc (void);
+LT_END_C_DECLS
+
 int
 test_dl (char *filename)
 {




reply via email to

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