2006-09-04 George Bosilca and Ralf Wildenhues 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'. 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 4 Sep 2006 17:25:38 -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 4 Sep 2006 17:25:38 -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 4 Sep 2006 17:25:38 -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; } @@ -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 4 Sep 2006 17:25:38 -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/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 4 Sep 2006 17:25:38 -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_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 4 Sep 2006 17:25:38 -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/slist.h =================================================================== RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/slist.h,v retrieving revision 1.4 diff -u -r1.4 slist.h --- libltdl/libltdl/slist.h 4 Sep 2006 17:23:30 -0000 1.4 +++ libltdl/libltdl/slist.h 4 Sep 2006 17:25:38 -0000 @@ -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); 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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 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); } @@ -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -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 4 Sep 2006 17:25:39 -0000 @@ -23,6 +23,10 @@ #include #include +LT_BEGIN_C_DECLS +extern int myfunc (void); +LT_END_C_DECLS + int test_dl (char *filename) {