Changed QLibrary::resolve() to return a function pointer.
According to the C++ standard, there is no guarantee that you can cast between function pointers and void pointers without data loss (section 5.2.10-6). Change-Id: I27f4d835e4c8ca8ecca0d76cfea9ce34491956bd Reviewed-on: http://codereview.qt.nokia.com/1995 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>bb10
parent
8d762c9cae
commit
b949b17c3c
|
|
@ -17,6 +17,9 @@ information about a particular change.
|
|||
- Unite clipping support has been removed from QPainter. The alternative is
|
||||
to unite QRegion's and using the result on QPainter.
|
||||
|
||||
- QLibrary::resolve() now returns a function pointer instead of a void
|
||||
pointer.
|
||||
|
||||
****************************************************************************
|
||||
* General *
|
||||
****************************************************************************
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ HB_CharCategory HB_GetUnicodeCharCategory(HB_UChar32 ch);
|
|||
int HB_GetUnicodeCharCombiningClass(HB_UChar32 ch);
|
||||
HB_UChar16 HB_GetMirroredChar(HB_UChar16 ch);
|
||||
|
||||
void *HB_Library_Resolve(const char *library, int version, const char *symbol);
|
||||
void (*HB_Library_Resolve(const char *library, int version, const char *symbol))();
|
||||
|
||||
HB_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ void HB_GetGraphemeAndLineBreakClass(HB_UChar32 ch, HB_GraphemeClass *grapheme,
|
|||
*lineBreak = (HB_LineBreakClass) prop->line_break_class;
|
||||
}
|
||||
|
||||
void *HB_Library_Resolve(const char *library, int version, const char *symbol)
|
||||
void (*HB_Library_Resolve(const char *library, int version, const char *symbol))()
|
||||
{
|
||||
return QLibrary::resolve(library, version, symbol);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -718,6 +718,13 @@ QT_BEGIN_NAMESPACE
|
|||
\sa QtMsgHandler, qInstallMsgHandler()
|
||||
*/
|
||||
|
||||
/*! \typedef QFunctionPointer
|
||||
\relates <QtGlobal>
|
||||
|
||||
This is a typedef for \c{void (*)()}, a pointer to a function that takes
|
||||
no arguments and returns void.
|
||||
*/
|
||||
|
||||
/*! \macro qint64 Q_INT64_C(literal)
|
||||
\relates <QtGlobal>
|
||||
|
||||
|
|
|
|||
|
|
@ -1807,6 +1807,8 @@ Q_CORE_EXPORT void qt_message_output(QtMsgType, const char *buf);
|
|||
typedef void (*QtMsgHandler)(QtMsgType, const char *);
|
||||
Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler);
|
||||
|
||||
typedef void (*QFunctionPointer)();
|
||||
|
||||
#if !defined(Q_UNIMPLEMENTED)
|
||||
# define Q_UNIMPLEMENTED() qWarning("%s:%d: %s: Unimplemented code.", __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ QLibraryPrivate::~QLibraryPrivate()
|
|||
}
|
||||
}
|
||||
|
||||
void *QLibraryPrivate::resolve(const char *symbol)
|
||||
QFunctionPointer QLibraryPrivate::resolve(const char *symbol)
|
||||
{
|
||||
if (!pHnd)
|
||||
return 0;
|
||||
|
|
@ -1129,7 +1129,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver
|
|||
Note: In Symbian resolving with symbol names works only if the loaded
|
||||
library was built as STDDLL. Otherwise, the ordinals must be used.
|
||||
*/
|
||||
void *QLibrary::resolve(const char *symbol)
|
||||
QFunctionPointer QLibrary::resolve(const char *symbol)
|
||||
{
|
||||
if (!isLoaded() && !load())
|
||||
return 0;
|
||||
|
|
@ -1152,7 +1152,7 @@ void *QLibrary::resolve(const char *symbol)
|
|||
|
||||
\sa resolve()
|
||||
*/
|
||||
void *QLibrary::resolve(const QString &fileName, const char *symbol)
|
||||
QFunctionPointer QLibrary::resolve(const QString &fileName, const char *symbol)
|
||||
{
|
||||
QLibrary library(fileName);
|
||||
return library.resolve(symbol);
|
||||
|
|
@ -1175,7 +1175,7 @@ void *QLibrary::resolve(const QString &fileName, const char *symbol)
|
|||
|
||||
\sa resolve()
|
||||
*/
|
||||
void *QLibrary::resolve(const QString &fileName, int verNum, const char *symbol)
|
||||
QFunctionPointer QLibrary::resolve(const QString &fileName, int verNum, const char *symbol)
|
||||
{
|
||||
QLibrary library(fileName, verNum);
|
||||
return library.resolve(symbol);
|
||||
|
|
@ -1199,7 +1199,7 @@ void *QLibrary::resolve(const QString &fileName, int verNum, const char *symbol)
|
|||
|
||||
\sa resolve()
|
||||
*/
|
||||
void *QLibrary::resolve(const QString &fileName, const QString &version, const char *symbol)
|
||||
QFunctionPointer QLibrary::resolve(const QString &fileName, const QString &version, const char *symbol)
|
||||
{
|
||||
QLibrary library(fileName, version);
|
||||
return library.resolve(symbol);
|
||||
|
|
|
|||
|
|
@ -79,10 +79,10 @@ public:
|
|||
explicit QLibrary(const QString& fileName, const QString &version, QObject *parent = 0);
|
||||
~QLibrary();
|
||||
|
||||
void *resolve(const char *symbol);
|
||||
static void *resolve(const QString &fileName, const char *symbol);
|
||||
static void *resolve(const QString &fileName, int verNum, const char *symbol);
|
||||
static void *resolve(const QString &fileName, const QString &version, const char *symbol);
|
||||
QFunctionPointer resolve(const char *symbol);
|
||||
static QFunctionPointer resolve(const QString &fileName, const char *symbol);
|
||||
static QFunctionPointer resolve(const QString &fileName, int verNum, const char *symbol);
|
||||
static QFunctionPointer resolve(const QString &fileName, const QString &version, const char *symbol);
|
||||
|
||||
bool load();
|
||||
bool unload();
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
bool loadPlugin(); // loads and resolves instance
|
||||
bool unload();
|
||||
void release();
|
||||
void *resolve(const char *);
|
||||
QFunctionPointer resolve(const char *);
|
||||
|
||||
static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString());
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ private:
|
|||
|
||||
bool load_sys();
|
||||
bool unload_sys();
|
||||
void *resolve_sys(const char *);
|
||||
QFunctionPointer resolve_sys(const char *);
|
||||
|
||||
QAtomicInt libraryRefCount;
|
||||
QAtomicInt libraryUnloadCount;
|
||||
|
|
|
|||
|
|
@ -267,29 +267,29 @@ bool QLibraryPrivate::unload_sys()
|
|||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
Q_CORE_EXPORT void *qt_mac_resolve_sys(void *handle, const char *symbol)
|
||||
Q_CORE_EXPORT QFunctionPointer qt_mac_resolve_sys(void *handle, const char *symbol)
|
||||
{
|
||||
return dlsym(handle, symbol);
|
||||
return QFunctionPointer(dlsym(handle, symbol));
|
||||
}
|
||||
#endif
|
||||
|
||||
void* QLibraryPrivate::resolve_sys(const char* symbol)
|
||||
QFunctionPointer QLibraryPrivate::resolve_sys(const char* symbol)
|
||||
{
|
||||
#if defined(QT_AOUT_UNDERSCORE)
|
||||
// older a.out systems add an underscore in front of symbols
|
||||
char* undrscr_symbol = new char[strlen(symbol)+2];
|
||||
undrscr_symbol[0] = '_';
|
||||
strcpy(undrscr_symbol+1, symbol);
|
||||
void* address = dlsym(pHnd, undrscr_symbol);
|
||||
QFunctionPointer address = QFunctionPointer(dlsym(pHnd, undrscr_symbol));
|
||||
delete [] undrscr_symbol;
|
||||
#elif defined(QT_HPUX_LD)
|
||||
void* address = 0;
|
||||
QFunctionPointer address = 0;
|
||||
if (shl_findsym((shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address) < 0)
|
||||
address = 0;
|
||||
#elif defined (QT_NO_DYNAMIC_LIBRARY)
|
||||
void *address = 0;
|
||||
QFunctionPointer address = 0;
|
||||
#else
|
||||
void* address = dlsym(pHnd, symbol);
|
||||
QFunctionPointer address = QFunctionPointer(dlsym(pHnd, symbol));
|
||||
#endif
|
||||
if (!address) {
|
||||
errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
|
||||
|
|
|
|||
|
|
@ -113,12 +113,12 @@ bool QLibraryPrivate::unload_sys()
|
|||
return true;
|
||||
}
|
||||
|
||||
void* QLibraryPrivate::resolve_sys(const char* symbol)
|
||||
QFunctionPointer QLibraryPrivate::resolve_sys(const char* symbol)
|
||||
{
|
||||
#ifdef Q_OS_WINCE
|
||||
void* address = (void*)GetProcAddress(pHnd, (const wchar_t*)QString::fromLatin1(symbol).utf16());
|
||||
FARPROC address = GetProcAddress(pHnd, (const wchar_t*)QString::fromLatin1(symbol).utf16());
|
||||
#else
|
||||
void* address = (void*)GetProcAddress(pHnd, symbol);
|
||||
FARPROC address = GetProcAddress(pHnd, symbol);
|
||||
#endif
|
||||
if (!address) {
|
||||
errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
|
||||
|
|
@ -126,6 +126,6 @@ void* QLibraryPrivate::resolve_sys(const char* symbol)
|
|||
} else {
|
||||
errorString.clear();
|
||||
}
|
||||
return address;
|
||||
return QFunctionPointer(address);
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -78,20 +78,20 @@ public:
|
|||
return (m_handle != 0);
|
||||
}
|
||||
|
||||
void *resolve(const char *symbol)
|
||||
QFunctionPointer resolve(const char *symbol)
|
||||
{
|
||||
if (!m_didLoad)
|
||||
load();
|
||||
if (!m_handle)
|
||||
return 0;
|
||||
#ifdef Q_OS_WINCE
|
||||
return (void*)GetProcAddress(m_handle, (const wchar_t*)QString::fromLatin1(symbol).utf16());
|
||||
return QFunctionPointer(GetProcAddress(m_handle, (const wchar_t*)QString::fromLatin1(symbol).utf16()));
|
||||
#else
|
||||
return (void*)GetProcAddress(m_handle, symbol);
|
||||
return QFunctionPointer(GetProcAddress(m_handle, symbol));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *resolve(const QString &libraryName, const char *symbol)
|
||||
static QFunctionPointer resolve(const QString &libraryName, const char *symbol)
|
||||
{
|
||||
return QSystemLibrary(libraryName).resolve(symbol);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ HB_UChar16 HB_GetMirroredChar(HB_UChar16 ch)
|
|||
return QChar::mirroredChar(ch);
|
||||
}
|
||||
|
||||
void *HB_Library_Resolve(const char *library, int version, const char *symbol)
|
||||
void (*HB_Library_Resolve(const char *library, int version, const char *symbol))()
|
||||
{
|
||||
#ifdef QT_NO_LIBRARY
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
void *qdbus_resolve_me(const char *name);
|
||||
void (*qdbus_resolve_me(const char *name))();
|
||||
|
||||
#if !defined QT_LINKED_LIBDBUS
|
||||
|
||||
|
|
@ -95,20 +95,19 @@ bool qdbus_loadLibDBus()
|
|||
return false;
|
||||
}
|
||||
|
||||
void *qdbus_resolve_conditionally(const char *name)
|
||||
void (*qdbus_resolve_conditionally(const char *name))()
|
||||
{
|
||||
if (qdbus_loadLibDBus())
|
||||
return qdbus_libdbus->resolve(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *qdbus_resolve_me(const char *name)
|
||||
void (*qdbus_resolve_me(const char *name))()
|
||||
{
|
||||
void *ptr = 0;
|
||||
if (!qdbus_loadLibDBus())
|
||||
qFatal("Cannot find libdbus-1 in your system to resolve symbol '%s'.", name);
|
||||
|
||||
ptr = qdbus_libdbus->resolve(name);
|
||||
QFunctionPointer ptr = qdbus_libdbus->resolve(name);
|
||||
if (!ptr)
|
||||
qFatal("Cannot resolve '%s' in your libdbus-1.", name);
|
||||
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
#if !defined QT_LINKED_LIBDBUS
|
||||
|
||||
void *qdbus_resolve_conditionally(const char *name); // doesn't print a warning
|
||||
void *qdbus_resolve_me(const char *name); // prints a warning
|
||||
void (*qdbus_resolve_conditionally(const char *name))(); // doesn't print a warning
|
||||
void (*qdbus_resolve_me(const char *name))(); // prints a warning
|
||||
bool qdbus_loadLibDBus();
|
||||
|
||||
# define DEFINEFUNC(ret, func, args, argcall, funcret) \
|
||||
|
|
|
|||
|
|
@ -467,8 +467,8 @@ extern bool qt_is_gui_used;
|
|||
\c XFIXES_MAJOR - it is a part of soname and may differ from the Xfixes
|
||||
version.
|
||||
*/
|
||||
static void* qt_load_library_runtime(const char *library, int vernum,
|
||||
int highestVernum, const char *symbol)
|
||||
static QFunctionPointer qt_load_library_runtime(const char *library, int vernum,
|
||||
int highestVernum, const char *symbol)
|
||||
{
|
||||
QList<int> versions;
|
||||
// we try to load in the following order:
|
||||
|
|
@ -483,7 +483,7 @@ static void* qt_load_library_runtime(const char *library, int vernum,
|
|||
Q_FOREACH(int version, versions) {
|
||||
QLatin1String libName(library);
|
||||
QLibrary xfixesLib(libName, version);
|
||||
void *ptr = xfixesLib.resolve(symbol);
|
||||
QFunctionPointer ptr = xfixesLib.resolve(symbol);
|
||||
if (ptr)
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -529,7 +529,8 @@ void QRawFontPrivate::platformCleanUp()
|
|||
{
|
||||
if (fontHandle != NULL) {
|
||||
if (ptrRemoveFontMemResourceEx == NULL) {
|
||||
void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
|
||||
QFunctionPointer func =
|
||||
QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
|
||||
ptrRemoveFontMemResourceEx =
|
||||
reinterpret_cast<QRawFontPrivate::PtrRemoveFontMemResourceEx>(func);
|
||||
}
|
||||
|
|
@ -572,7 +573,8 @@ void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData,
|
|||
}
|
||||
|
||||
if (ptrAddFontMemResourceEx == NULL || ptrRemoveFontMemResourceEx == NULL) {
|
||||
void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
|
||||
QFunctionPointer func =
|
||||
QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
|
||||
ptrRemoveFontMemResourceEx =
|
||||
reinterpret_cast<QRawFontPrivate::PtrRemoveFontMemResourceEx>(func);
|
||||
|
||||
|
|
|
|||
|
|
@ -347,13 +347,13 @@ static void find_trans_colors()
|
|||
QGLFormat UNIX/GLX-specific code
|
||||
*****************************************************************************/
|
||||
|
||||
void* qglx_getProcAddress(const char* procName)
|
||||
void (*qglx_getProcAddress(const char* procName))()
|
||||
{
|
||||
// On systems where the GL driver is pluggable (like Mesa), we have to use
|
||||
// the glXGetProcAddressARB extension to resolve other function pointers as
|
||||
// the symbols wont be in the GL library, but rather in a plugin loaded by
|
||||
// the GL library.
|
||||
typedef void* (*qt_glXGetProcAddressARB)(const char *);
|
||||
typedef void (*(*qt_glXGetProcAddressARB)(const char *))();
|
||||
static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
|
||||
static bool triedResolvingGlxGetProcAddress = false;
|
||||
if (!triedResolvingGlxGetProcAddress) {
|
||||
|
|
@ -378,7 +378,7 @@ void* qglx_getProcAddress(const char* procName)
|
|||
}
|
||||
}
|
||||
|
||||
void *procAddress = 0;
|
||||
void (*procAddress)() = 0;
|
||||
if (glXGetProcAddressARB)
|
||||
procAddress = glXGetProcAddressARB(procName);
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ void* qglx_getProcAddress(const char* procName)
|
|||
if (!procAddress) {
|
||||
void *handle = dlopen(NULL, RTLD_LAZY);
|
||||
if (handle) {
|
||||
procAddress = dlsym(handle, procName);
|
||||
procAddress = (void (*)())dlsym(handle, procName);
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ static _glXMakeContextCurrent qt_glXMakeContextCurrent = 0;
|
|||
#define glXGetFBConfigAttrib qt_glXGetFBConfigAttrib
|
||||
#define glXMakeContextCurrent qt_glXMakeContextCurrent
|
||||
|
||||
extern void* qglx_getProcAddress(const char* procName); // in qgl_x11.cpp
|
||||
extern void (*qglx_getProcAddress(const char* procName))(); // in qgl_x11.cpp
|
||||
|
||||
static bool qt_resolve_pbuffer_extensions()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ static const char * x11_atomnames = {
|
|||
\c XFIXES_MAJOR - it is a part of soname and may differ from the Xfixes
|
||||
version.
|
||||
*/
|
||||
static void* qt_load_library_runtime(const char *library, int vernum,
|
||||
int highestVernum, const char *symbol)
|
||||
static QFunctionPointer qt_load_library_runtime(const char *library, int vernum,
|
||||
int highestVernum, const char *symbol)
|
||||
{
|
||||
QList<int> versions;
|
||||
// we try to load in the following order:
|
||||
|
|
@ -234,7 +234,7 @@ static void* qt_load_library_runtime(const char *library, int vernum,
|
|||
Q_FOREACH(int version, versions) {
|
||||
QLatin1String libName(library);
|
||||
QLibrary xfixesLib(libName, version);
|
||||
void *ptr = xfixesLib.resolve(symbol);
|
||||
QFunctionPointer ptr = xfixesLib.resolve(symbol);
|
||||
if (ptr)
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ void tst_QLibrary::unload_after_implicit_load()
|
|||
#endif
|
||||
|
||||
QLibrary library( "./mylib" );
|
||||
void *p = library.resolve("mylibversion");
|
||||
QFunctionPointer p = library.resolve("mylibversion");
|
||||
QVERIFY(p); // Check if it was loaded
|
||||
QVERIFY(library.isLoaded());
|
||||
QVERIFY(library.unload());
|
||||
|
|
|
|||
Loading…
Reference in New Issue