From b949b17c3cb7b6752bc8daf2834415163792a76c Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Thu, 21 Jul 2011 18:47:26 +0200 Subject: Changed QLibrary::resolve() to return a function pointer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: João Abecasis --- src/corelib/plugin/qlibrary.cpp | 10 +++++----- src/corelib/plugin/qlibrary.h | 8 ++++---- src/corelib/plugin/qlibrary_p.h | 4 ++-- src/corelib/plugin/qlibrary_unix.cpp | 14 +++++++------- src/corelib/plugin/qlibrary_win.cpp | 8 ++++---- src/corelib/plugin/qsystemlibrary_p.h | 8 ++++---- 6 files changed, 26 insertions(+), 26 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 314ccd7861..45515f32e1 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -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); diff --git a/src/corelib/plugin/qlibrary.h b/src/corelib/plugin/qlibrary.h index 0154e949b3..e3f557dd7d 100644 --- a/src/corelib/plugin/qlibrary.h +++ b/src/corelib/plugin/qlibrary.h @@ -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(); diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index 44860f4b23..12d625050f 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -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; diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 0a7e841519..d3b08e1acf 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -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( diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index 667d9cca45..4eeb2fc441 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -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 diff --git a/src/corelib/plugin/qsystemlibrary_p.h b/src/corelib/plugin/qsystemlibrary_p.h index f20d0b6b9d..3298f05b8f 100644 --- a/src/corelib/plugin/qsystemlibrary_p.h +++ b/src/corelib/plugin/qsystemlibrary_p.h @@ -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); } -- cgit v1.2.3