Merge duplicated ivl_dlfcn.h files.
The vvp/ivl_dlfcn.h and cadpli/ivl_dlfcn.h files are essentially the same, but have diverged a bit over the years. Merge them into a single shared file at the top level. Use the static prefix for all inline functins (currently only used in the cadpli version) as that will fix issue #1301. We now require the compiler to support at least C99, so can use "inline", not "__inline__".
This commit is contained in:
parent
b8de0499a9
commit
3f936d2d8b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
|
* Copyright (c) 2003-2026 Stephen Williams (steve@icarus.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -53,7 +53,7 @@ static void thunker_register(void)
|
||||||
strncpy(module, cp, bp-cp);
|
strncpy(module, cp, bp-cp);
|
||||||
module[bp-cp] = 0;
|
module[bp-cp] = 0;
|
||||||
|
|
||||||
mod = ivl_dlopen(module);
|
mod = ivl_dlopen(module, false);
|
||||||
if (mod == 0) {
|
if (mod == 0) {
|
||||||
vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror());
|
vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror());
|
||||||
free(module);
|
free(module);
|
||||||
|
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
#ifndef IVL_ivl_dlfcn_H
|
|
||||||
#define IVL_ivl_dlfcn_H
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
|
||||||
*
|
|
||||||
* This source code is free software; you can redistribute it
|
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
|
||||||
* General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option)
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
# include <windows.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
typedef void * ivl_dll_t;
|
|
||||||
#elif defined(HAVE_DLFCN_H)
|
|
||||||
# include <dlfcn.h>
|
|
||||||
typedef void* ivl_dll_t;
|
|
||||||
#elif defined(HAVE_DL_H)
|
|
||||||
# include <dl.h>
|
|
||||||
typedef shl_t ivl_dll_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
static __inline__ ivl_dll_t ivl_dlopen(const char *name)
|
|
||||||
{ return (void *)LoadLibrary(name); }
|
|
||||||
|
|
||||||
static __inline__ void *ivl_dlsym(ivl_dll_t dll, const char *nm)
|
|
||||||
{ return (void *)GetProcAddress((HINSTANCE)dll,nm);}
|
|
||||||
|
|
||||||
static __inline__ void ivl_dlclose(ivl_dll_t dll)
|
|
||||||
{ (void)FreeLibrary((HINSTANCE)dll);}
|
|
||||||
|
|
||||||
static __inline__ const char *dlerror(void)
|
|
||||||
{
|
|
||||||
static char msg[256];
|
|
||||||
unsigned long err = GetLastError();
|
|
||||||
FormatMessage(
|
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL,
|
|
||||||
err,
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
||||||
(LPTSTR) &msg,
|
|
||||||
sizeof(msg) - 1,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(HAVE_DLFCN_H)
|
|
||||||
static __inline__ ivl_dll_t ivl_dlopen(const char*name)
|
|
||||||
{ return dlopen(name,RTLD_LAZY); }
|
|
||||||
|
|
||||||
static __inline__ void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
|
||||||
{
|
|
||||||
void*sym = dlsym(dll, nm);
|
|
||||||
/* Not found? try without the leading _ */
|
|
||||||
if (sym == 0 && nm[0] == '_')
|
|
||||||
sym = dlsym(dll, nm+1);
|
|
||||||
return sym;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ void ivl_dlclose(ivl_dll_t dll)
|
|
||||||
{ dlclose(dll); }
|
|
||||||
|
|
||||||
#elif defined(HAVE_DL_H)
|
|
||||||
static __inline__ ivl_dll_t ivl_dlopen(const char*name)
|
|
||||||
{ return shl_load(name, BIND_IMMEDIATE, 0); }
|
|
||||||
|
|
||||||
static __inline__ void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
|
||||||
{
|
|
||||||
void*sym;
|
|
||||||
int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym);
|
|
||||||
return (rc == 0) ? sym : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ void ivl_dlclose(ivl_dll_t dll)
|
|
||||||
{ shl_unload(dll); }
|
|
||||||
|
|
||||||
static __inline__ const char*dlerror(void)
|
|
||||||
{ return strerror( errno ); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IVL_ivl_dlfcn_H */
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef IVL_ivl_dlfcn_H
|
#ifndef IVL_ivl_dlfcn_H
|
||||||
#define IVL_ivl_dlfcn_H
|
#define IVL_ivl_dlfcn_H
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
* Copyright (c) 2001-2026 Stephen Williams (steve@icarus.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -21,7 +21,11 @@
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
#if defined(__cplusplus)
|
||||||
# include <cstdio>
|
# include <cstdio>
|
||||||
|
#else
|
||||||
|
# include <stdio.h>
|
||||||
|
#endif
|
||||||
typedef void * ivl_dll_t;
|
typedef void * ivl_dll_t;
|
||||||
#elif defined(HAVE_DLFCN_H)
|
#elif defined(HAVE_DLFCN_H)
|
||||||
# include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
|
|
@ -32,7 +36,7 @@ typedef shl_t ivl_dll_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
inline ivl_dll_t ivl_dlopen(const char *name, bool)
|
static inline ivl_dll_t ivl_dlopen(const char *name, bool global_flag)
|
||||||
{
|
{
|
||||||
static char full_name[4096];
|
static char full_name[4096];
|
||||||
unsigned long length = GetFullPathName(name, sizeof(full_name),
|
unsigned long length = GetFullPathName(name, sizeof(full_name),
|
||||||
|
|
@ -40,16 +44,18 @@ inline ivl_dll_t ivl_dlopen(const char *name, bool)
|
||||||
if ((length == 0) || (length > sizeof(full_name)))
|
if ((length == 0) || (length > sizeof(full_name)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
(void)global_flag;
|
||||||
|
|
||||||
return (void *)LoadLibrary(full_name);
|
return (void *)LoadLibrary(full_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void *ivl_dlsym(ivl_dll_t dll, const char *nm)
|
static inline void *ivl_dlsym(ivl_dll_t dll, const char *nm)
|
||||||
{ return (void *)GetProcAddress((HINSTANCE)dll,nm);}
|
{ return (void *)GetProcAddress((HINSTANCE)dll,nm);}
|
||||||
|
|
||||||
inline void ivl_dlclose(ivl_dll_t dll)
|
static inline void ivl_dlclose(ivl_dll_t dll)
|
||||||
{ (void)FreeLibrary((HINSTANCE)dll);}
|
{ (void)FreeLibrary((HINSTANCE)dll);}
|
||||||
|
|
||||||
inline const char *dlerror(void)
|
static inline const char *dlerror(void)
|
||||||
{
|
{
|
||||||
static char msg[256];
|
static char msg[256];
|
||||||
unsigned long err = GetLastError();
|
unsigned long err = GetLastError();
|
||||||
|
|
@ -66,10 +72,10 @@ inline const char *dlerror(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_DLFCN_H)
|
#elif defined(HAVE_DLFCN_H)
|
||||||
inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag)
|
static inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag)
|
||||||
{ return dlopen(name,RTLD_LAZY|(global_flag?RTLD_GLOBAL:0)); }
|
{ return dlopen(name,RTLD_LAZY|(global_flag?RTLD_GLOBAL:0)); }
|
||||||
|
|
||||||
inline void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
static inline void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
||||||
{
|
{
|
||||||
void*sym = dlsym(dll, nm);
|
void*sym = dlsym(dll, nm);
|
||||||
/* Not found? try without the leading _ */
|
/* Not found? try without the leading _ */
|
||||||
|
|
@ -78,24 +84,28 @@ inline void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ivl_dlclose(ivl_dll_t dll)
|
static inline void ivl_dlclose(ivl_dll_t dll)
|
||||||
{ dlclose(dll); }
|
{ dlclose(dll); }
|
||||||
|
|
||||||
#elif defined(HAVE_DL_H)
|
#elif defined(HAVE_DL_H)
|
||||||
inline ivl_dll_t ivl_dlopen(const char*name)
|
static inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag)
|
||||||
{ return shl_load(name, BIND_IMMEDIATE, 0); }
|
{
|
||||||
|
(void)global_flag;
|
||||||
|
|
||||||
inline void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
return shl_load(name, BIND_IMMEDIATE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void* ivl_dlsym(ivl_dll_t dll, const char*nm)
|
||||||
{
|
{
|
||||||
void*sym;
|
void*sym;
|
||||||
int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym);
|
int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym);
|
||||||
return (rc == 0) ? sym : 0;
|
return (rc == 0) ? sym : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ivl_dlclose(ivl_dll_t dll)
|
static inline void ivl_dlclose(ivl_dll_t dll)
|
||||||
{ shl_unload(dll); }
|
{ shl_unload(dll); }
|
||||||
|
|
||||||
inline const char*dlerror(void)
|
static inline const char*dlerror(void)
|
||||||
{ return strerror( errno ); }
|
{ return strerror( errno ); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "vpi_user.h"
|
#include "vpi_user.h"
|
||||||
#include "sv_vpi_user.h"
|
#include "sv_vpi_user.h"
|
||||||
#include "vvp/ivl_dlfcn.h"
|
#include "ivl_dlfcn.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue