2006-09-04 George Bosilca <bosilca@cs.utk.edu>
and Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+ 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++
#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
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);
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);
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
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
if (!vtable)
{
- vtable = lt__zalloc (sizeof *vtable);
+ vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
}
if (vtable && !vtable->name)
/* 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 <peter@pogma.com>
NOTE: The canonical source of this file is maintained with the
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
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
/* 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 <tanner@ffii.org>
NOTE: The canonical source of this file is maintained with the
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
if (!vtable)
{
- vtable = lt__zalloc (sizeof *vtable);
+ vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
iface_id = lt_dlinterface_register ("ltdl loadlibrary", NULL);
}
{
int errors = 0;
- if (FreeLibrary(module) == 0)
+ if (FreeLibrary((HMODULE) module) == 0)
{
LT__SETERROR (CANNOT_CLOSE);
++errors;
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)
{
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
if (!vtable)
{
- vtable = lt__zalloc (sizeof *vtable);
+ vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
}
if (vtable && !vtable->name)
/* 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)
{
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
char *
lt__strdup (const char *string)
{
- return lt__memdup (string, strlen (string) +1);
+ return (char *) lt__memdup (string, strlen (string) +1);
}
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);
const lt_dlvtable *
lt_dlloader_get (lt_dlloader loader)
{
- return loader ? ((SList *) loader)->userdata : 0;
+ return (const lt_dlvtable *) (loader ? ((SList *) loader)->userdata : 0);
}
}
/* 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));
}
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 */
#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
}
/* 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)))
goto done;
}
- handle = *phandle;
+ handle = (lt__handle *) *phandle;
if (filename)
{
/* Comment out the check of file permissions using access.
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,
((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;
}
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. */
...
*/
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;
}
SList *
slist_box (const void *userdata)
{
- SList *item = malloc (sizeof *item);
+ SList *item = (SList *) malloc (sizeof *item);
if (item)
{
/* 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
* 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
* 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
/* 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 <tanner@ffii.org>
This file is part of GNU Libtool.
#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
}
/* exported functions */
+__BEGIN_DECLS
int
foo1()
printf ("** This is foolib 1 **\n");
return HELLO_RET;
}
+
+__END_DECLS
}
/* exported functions */
+__BEGIN_DECLS
int
foo2()
printf ("** This is foolib 2 **\n");
return HELLO_RET;
}
+
+__END_DECLS
#include <stdio.h>
#include <string.h>
+LT_BEGIN_C_DECLS
+extern int myfunc (void);
+LT_END_C_DECLS
+
int
test_dl (char *filename)
{
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";
large v13;
large v14 = { { 0 } };
large v15 = { { 1 } };
+#ifdef __cplusplus
+}
+#endif
]])
AT_DATA(asyms,
]])
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;
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;
]])
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;
extern int (*w11) (void);
extern int (*const w12) (void);
extern large w13, w14, w15;
+#ifdef __cplusplus
+}
+#endif
int main(void)
{
}
+#ifdef __cplusplus
+extern "C" {
+#endif
int w1;
static int w2;
int w3 = 0;
large w13;
large w14 = { { 0 } };
large w15 = { { 1 } };
+#ifdef __cplusplus
+}
+#endif
]])
AT_DATA(dlselfsyms,
# 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!";