Get rid of non-POSIX code for loading dynlibs on *nix
The alternative, (non-POSIX) shl_xxx() API is/was apparently available on HP-UX, but even there the POSIX dlxxx() functions have been the preferred way to load libraries since the past ~20 years.
This commit is contained in:
parent
c50784ba0b
commit
e289eb07e1
@ -50,9 +50,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_DLOPEN)
|
||||
#define USE_POSIX_DL_FUNCS
|
||||
#elif !defined(HAVE_SHL_LOAD)
|
||||
#ifndef HAVE_DLOPEN
|
||||
#error "Don't know how to load dynamic libraries on this platform!"
|
||||
#endif
|
||||
|
||||
@ -66,11 +64,7 @@
|
||||
|
||||
wxDllType wxDynamicLibrary::GetProgramHandle()
|
||||
{
|
||||
#ifdef USE_POSIX_DL_FUNCS
|
||||
return dlopen(0, RTLD_LAZY);
|
||||
#else
|
||||
return PROG_HANDLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -79,7 +73,6 @@ wxDllType wxDynamicLibrary::RawLoad(const wxString& libname, int flags)
|
||||
wxASSERT_MSG( !(flags & wxDL_NOW) || !(flags & wxDL_LAZY),
|
||||
wxT("wxDL_LAZY and wxDL_NOW are mutually exclusive.") );
|
||||
|
||||
#ifdef USE_POSIX_DL_FUNCS
|
||||
// we need to use either RTLD_NOW or RTLD_LAZY because if we call dlopen()
|
||||
// with flags == 0 recent versions of glibc just fail the call, so use
|
||||
// RTLD_NOW even if wxDL_NOW was not specified
|
||||
@ -89,54 +82,21 @@ wxDllType wxDynamicLibrary::RawLoad(const wxString& libname, int flags)
|
||||
rtldFlags |= RTLD_GLOBAL;
|
||||
|
||||
return dlopen(libname.fn_str(), rtldFlags);
|
||||
#else // !USE_POSIX_DL_FUNCS
|
||||
int shlFlags = 0;
|
||||
|
||||
if ( flags & wxDL_LAZY )
|
||||
{
|
||||
shlFlags |= BIND_DEFERRED;
|
||||
}
|
||||
else if ( flags & wxDL_NOW )
|
||||
{
|
||||
shlFlags |= BIND_IMMEDIATE;
|
||||
}
|
||||
|
||||
return shl_load(libname.fn_str(), shlFlags, 0);
|
||||
#endif // USE_POSIX_DL_FUNCS/!USE_POSIX_DL_FUNCS
|
||||
}
|
||||
|
||||
/* static */
|
||||
void wxDynamicLibrary::Unload(wxDllType handle)
|
||||
{
|
||||
#ifdef HAVE_DLERROR
|
||||
int rc =
|
||||
#endif
|
||||
int rc = dlclose(handle);
|
||||
|
||||
#ifdef USE_POSIX_DL_FUNCS
|
||||
dlclose(handle);
|
||||
#else // !USE_POSIX_DL_FUNCS
|
||||
shl_unload(handle);
|
||||
#endif // USE_POSIX_DL_FUNCS/!USE_POSIX_DL_FUNCS
|
||||
|
||||
#if defined(USE_POSIX_DL_FUNCS) && defined(HAVE_DLERROR)
|
||||
if ( rc != 0 )
|
||||
#endif
|
||||
ReportError(_("Failed to unload shared library"));
|
||||
}
|
||||
|
||||
/* static */
|
||||
void *wxDynamicLibrary::RawGetSymbol(wxDllType handle, const wxString& name)
|
||||
{
|
||||
void *symbol;
|
||||
|
||||
#ifdef USE_POSIX_DL_FUNCS
|
||||
symbol = dlsym(handle, name.fn_str());
|
||||
#else // !USE_POSIX_DL_FUNCS
|
||||
// note that shl_findsym modifies the handle argument to indicate where the
|
||||
// symbol was found, but it's ok to modify the local handle copy here
|
||||
if ( shl_findsym(&handle, name.fn_str(), TYPE_UNDEFINED, &symbol) != 0 )
|
||||
symbol = 0;
|
||||
#endif // USE_POSIX_DL_FUNCS/!USE_POSIX_DL_FUNCS
|
||||
void *symbol = dlsym(handle, name.fn_str());
|
||||
|
||||
return symbol;
|
||||
}
|
||||
@ -154,16 +114,13 @@ void wxDynamicLibrary::ReportError(const wxString& message,
|
||||
msg += "%s";
|
||||
// msg needs a %s for the name
|
||||
wxASSERT(msg.Find("%s") != wxNOT_FOUND);
|
||||
#ifdef HAVE_DLERROR
|
||||
|
||||
wxString err(dlerror());
|
||||
|
||||
if ( err.empty() )
|
||||
err = _("Unknown dynamic library error");
|
||||
|
||||
wxLogError(msg + wxT(": %s"), name, err);
|
||||
#else // !HAVE_DLERROR
|
||||
wxLogSysError(msg, name);
|
||||
#endif // HAVE_DLERROR
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user