From: George Bosilca Date: Mon, 4 Sep 2006 17:27:27 +0000 (+0000) Subject: Make libltdl work when compiled with a C++ compiler. X-Git-Tag: release-2-1b~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a17ccd68d2075b6c6d94f2c2d35c4c9e60a4952;p=thirdparty%2Flibtool.git 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'. --- diff --git a/ChangeLog b/ChangeLog index 380210877..73ad66038 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,21 @@ 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'. + * 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++ diff --git a/libltdl/libltdl/lt__alloc.h b/libltdl/libltdl/lt__alloc.h index b5c615715..6f95109fd 100644 --- a/libltdl/libltdl/lt__alloc.h +++ b/libltdl/libltdl/lt__alloc.h @@ -37,7 +37,7 @@ LT_BEGIN_C_DECLS #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 diff --git a/libltdl/libltdl/lt_error.h b/libltdl/libltdl/lt_error.h index 8773770a4..8e417469e 100644 --- a/libltdl/libltdl/lt_error.h +++ b/libltdl/libltdl/lt_error.h @@ -69,8 +69,8 @@ enum { 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); diff --git a/libltdl/libltdl/slist.h b/libltdl/libltdl/slist.h index 4b47cda6d..80a570fb8 100644 --- a/libltdl/libltdl/slist.h +++ b/libltdl/libltdl/slist.h @@ -63,7 +63,7 @@ typedef int SListCompare (const SList *item1, const SList *item2, 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); diff --git a/libltdl/loaders/dld_link.c b/libltdl/loaders/dld_link.c index b93868d20..c7b283e23 100644 --- a/libltdl/loaders/dld_link.c +++ b/libltdl/loaders/dld_link.c @@ -36,7 +36,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 diff --git a/libltdl/loaders/dlopen.c b/libltdl/loaders/dlopen.c index 95e7a07a8..3bd5bd3f7 100644 --- a/libltdl/loaders/dlopen.c +++ b/libltdl/loaders/dlopen.c @@ -36,7 +36,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 @@ get_vtable (lt_user_data loader_data) if (!vtable) { - vtable = lt__zalloc (sizeof *vtable); + vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable); } if (vtable && !vtable->name) diff --git a/libltdl/loaders/dyld.c b/libltdl/loaders/dyld.c index c5f94f069..2138de6cf 100644 --- a/libltdl/loaders/dyld.c +++ b/libltdl/loaders/dyld.c @@ -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 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 diff --git a/libltdl/loaders/load_add_on.c b/libltdl/loaders/load_add_on.c index d67e3a20d..03a155798 100644 --- a/libltdl/loaders/load_add_on.c +++ b/libltdl/loaders/load_add_on.c @@ -36,7 +36,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 diff --git a/libltdl/loaders/loadlibrary.c b/libltdl/loaders/loadlibrary.c index 47b0e664b..49a33ec6c 100644 --- a/libltdl/loaders/loadlibrary.c +++ b/libltdl/loaders/loadlibrary.c @@ -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 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 @@ get_vtable (lt_user_data loader_data) 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 @@ vm_close (lt_user_data loader_data LT__UNUSED, lt_module module) { int errors = 0; - if (FreeLibrary(module) == 0) + if (FreeLibrary((HMODULE) module) == 0) { LT__SETERROR (CANNOT_CLOSE); ++errors; @@ -217,7 +219,7 @@ vm_close (lt_user_data loader_data LT__UNUSED, lt_module module) 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) { diff --git a/libltdl/loaders/preopen.c b/libltdl/loaders/preopen.c index e71c46f2d..dc2e92680 100644 --- a/libltdl/loaders/preopen.c +++ b/libltdl/loaders/preopen.c @@ -36,7 +36,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 @@ get_vtable (lt_user_data loader_data) if (!vtable) { - vtable = lt__zalloc (sizeof *vtable); + vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable); } if (vtable && !vtable->name) @@ -259,7 +261,7 @@ add_symlist (const lt_dlsymlist *symlist) /* 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) { diff --git a/libltdl/loaders/shl_load.c b/libltdl/loaders/shl_load.c index bcdbc5632..e5d0e35f6 100644 --- a/libltdl/loaders/shl_load.c +++ b/libltdl/loaders/shl_load.c @@ -36,7 +36,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 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 diff --git a/libltdl/lt__alloc.c b/libltdl/lt__alloc.c index 019e5e386..7cb8553b0 100644 --- a/libltdl/lt__alloc.c +++ b/libltdl/lt__alloc.c @@ -97,5 +97,5 @@ lt__memdup (void const *mem, size_t n) char * lt__strdup (const char *string) { - return lt__memdup (string, strlen (string) +1); + return (char *) lt__memdup (string, strlen (string) +1); } diff --git a/libltdl/lt_dlloader.c b/libltdl/lt_dlloader.c index 411b5e010..d8317dfd4 100644 --- a/libltdl/lt_dlloader.c +++ b/libltdl/lt_dlloader.c @@ -46,8 +46,8 @@ static SList *loaders = 0; 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 @@ lt_dlloader_next (lt_dlloader loader) 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 @@ lt_dlloader_remove (char *name) } /* 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)); } diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 0e57473b1..46badfb3e 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -159,7 +159,8 @@ lt__alloc_die_callback (void) 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 @@ loader_init (lt_get_vtable *vtable_func, lt_user_data data) #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 @@ lt_dlexit (void) } /* 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 @@ tryall_dlopen (lt_dlhandle *phandle, const char *filename) goto done; } - handle = *phandle; + handle = (lt__handle *) *phandle; if (filename) { /* Comment out the check of file permissions using access. @@ -371,7 +374,7 @@ tryall_dlopen (lt_dlhandle *phandle, const char *filename) 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 @@ try_dlopen (lt_dlhandle *phandle, const char *filename) ((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 @@ typedef struct { 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. */ diff --git a/libltdl/slist.c b/libltdl/slist.c index 8cd855183..84af3f1d8 100644 --- a/libltdl/slist.c +++ b/libltdl/slist.c @@ -48,14 +48,14 @@ static SList * slist_sort_merge (SList *left, SList *right, ... */ 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_sort (SList *slist, SListCompare *compare, void *userdata) SList * slist_box (const void *userdata) { - SList *item = malloc (sizeof *item); + SList *item = (SList *) malloc (sizeof *item); if (item) { diff --git a/tests/f77demo/foo.h b/tests/f77demo/foo.h index 1468912b4..b39255a48 100644 --- a/tests/f77demo/foo.h +++ b/tests/f77demo/foo.h @@ -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 @@ extern int fwrapper(int); * 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 diff --git a/tests/fcdemo/foo.h b/tests/fcdemo/foo.h index e62e00493..9fd410351 100644 --- a/tests/fcdemo/foo.h +++ b/tests/fcdemo/foo.h @@ -41,7 +41,11 @@ extern int fwrapper(int); * 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 diff --git a/tests/mdemo/foo.h b/tests/mdemo/foo.h index 106f937b8..59eac5e23 100644 --- a/tests/mdemo/foo.h +++ b/tests/mdemo/foo.h @@ -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 @@ USA. */ #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 diff --git a/tests/mdemo/foo1.c b/tests/mdemo/foo1.c index c7300c0b7..0f960eb38 100644 --- a/tests/mdemo/foo1.c +++ b/tests/mdemo/foo1.c @@ -41,6 +41,7 @@ _foo1_helper() } /* exported functions */ +__BEGIN_DECLS int foo1() @@ -55,3 +56,5 @@ hello() printf ("** This is foolib 1 **\n"); return HELLO_RET; } + +__END_DECLS diff --git a/tests/mdemo/foo2.c b/tests/mdemo/foo2.c index d1d85d5eb..301e3cb10 100644 --- a/tests/mdemo/foo2.c +++ b/tests/mdemo/foo2.c @@ -41,6 +41,7 @@ _foo2_helper() } /* exported functions */ +__BEGIN_DECLS int foo2() @@ -55,3 +56,5 @@ hello() printf ("** This is foolib 2 **\n"); return HELLO_RET; } + +__END_DECLS diff --git a/tests/mdemo/main.c b/tests/mdemo/main.c index 38524f0ff..a73caac88 100644 --- a/tests/mdemo/main.c +++ b/tests/mdemo/main.c @@ -23,6 +23,10 @@ USA. */ #include #include +LT_BEGIN_C_DECLS +extern int myfunc (void); +LT_END_C_DECLS + int test_dl (char *filename) { diff --git a/tests/stresstest.at b/tests/stresstest.at index af06d251a..4f7abaf65 100644 --- a/tests/stresstest.at +++ b/tests/stresstest.at @@ -30,10 +30,17 @@ mkdir sub sub2 sub3 2>/dev/null 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 @@ typedef struct { int arr[1000]; } large; large v13; large v14 = { { 0 } }; large v15 = { { 1 } }; +#ifdef __cplusplus +} +#endif ]]) AT_DATA(asyms, @@ -73,7 +83,11 @@ int ab = 1; ]]) 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 v9(void); 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 @@ int main(void) ]]) 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 (*w10) (void); extern int (*w11) (void); extern int (*const w12) (void); extern large w13, w14, w15; +#ifdef __cplusplus +} +#endif int main(void) { @@ -131,6 +154,9 @@ int main(void) } +#ifdef __cplusplus +extern "C" { +#endif int w1; static int w2; int w3 = 0; @@ -146,6 +172,9 @@ int (*const w12) (void) = w9; large w13; large w14 = { { 0 } }; large w15 = { { 1 } }; +#ifdef __cplusplus +} +#endif ]]) AT_DATA(dlselfsyms, diff --git a/tests/testsuite.at b/tests/testsuite.at index ab11e5c68..da39d3171 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -167,7 +167,10 @@ AT_CHECK([test -n "[$]$1" || (exit 77)]) # 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!";