Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/qlibrary.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Copyright (C) 2013 Intel Corporation | - | ||||||||||||||||||
5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
6 | ** | - | ||||||||||||||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
8 | ** | - | ||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
17 | ** | - | ||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
26 | ** | - | ||||||||||||||||||
27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
30 | ** | - | ||||||||||||||||||
31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
32 | ** | - | ||||||||||||||||||
33 | ****************************************************************************/ | - | ||||||||||||||||||
34 | #include "qplatformdefs.h" | - | ||||||||||||||||||
35 | #include "qlibrary.h" | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | #include "qlibrary_p.h" | - | ||||||||||||||||||
40 | #include <qstringlist.h> | - | ||||||||||||||||||
41 | #include <qfile.h> | - | ||||||||||||||||||
42 | #include <qfileinfo.h> | - | ||||||||||||||||||
43 | #include <qmutex.h> | - | ||||||||||||||||||
44 | #include <qmap.h> | - | ||||||||||||||||||
45 | #include <private/qcoreapplication_p.h> | - | ||||||||||||||||||
46 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
47 | # include <private/qcore_mac_p.h> | - | ||||||||||||||||||
48 | #endif | - | ||||||||||||||||||
49 | #ifndef NO_ERRNO_H | - | ||||||||||||||||||
50 | #include <errno.h> | - | ||||||||||||||||||
51 | #endif // NO_ERROR_H | - | ||||||||||||||||||
52 | #include <qdebug.h> | - | ||||||||||||||||||
53 | #include <qvector.h> | - | ||||||||||||||||||
54 | #include <qdir.h> | - | ||||||||||||||||||
55 | #include <qendian.h> | - | ||||||||||||||||||
56 | #include <qjsondocument.h> | - | ||||||||||||||||||
57 | #include <qjsonvalue.h> | - | ||||||||||||||||||
58 | #include "qelfparser_p.h" | - | ||||||||||||||||||
59 | #include "qmachparser_p.h" | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | #ifdef QT_NO_DEBUG | - | ||||||||||||||||||
64 | # define QLIBRARY_AS_DEBUG false | - | ||||||||||||||||||
65 | #else | - | ||||||||||||||||||
66 | # define QLIBRARY_AS_DEBUG true | - | ||||||||||||||||||
67 | #endif | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||
70 | // We don't use separate debug and release libs on UNIX, so we want | - | ||||||||||||||||||
71 | // to allow loading plugins, regardless of how they were built. | - | ||||||||||||||||||
72 | # define QT_NO_DEBUG_PLUGIN_CHECK | - | ||||||||||||||||||
73 | #endif | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | /*! | - | ||||||||||||||||||
76 | \class QLibrary | - | ||||||||||||||||||
77 | \inmodule QtCore | - | ||||||||||||||||||
78 | \reentrant | - | ||||||||||||||||||
79 | \brief The QLibrary class loads shared libraries at runtime. | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | - | |||||||||||||||||||
82 | \ingroup plugins | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | An instance of a QLibrary object operates on a single shared | - | ||||||||||||||||||
85 | object file (which we call a "library", but is also known as a | - | ||||||||||||||||||
86 | "DLL"). A QLibrary provides access to the functionality in the | - | ||||||||||||||||||
87 | library in a platform independent way. You can either pass a file | - | ||||||||||||||||||
88 | name in the constructor, or set it explicitly with setFileName(). | - | ||||||||||||||||||
89 | When loading the library, QLibrary searches in all the | - | ||||||||||||||||||
90 | system-specific library locations (e.g. \c LD_LIBRARY_PATH on | - | ||||||||||||||||||
91 | Unix), unless the file name has an absolute path. | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | If the file name is an absolute path then an attempt is made to | - | ||||||||||||||||||
94 | load this path first. If the file cannot be found, QLibrary tries | - | ||||||||||||||||||
95 | the name with different platform-specific file prefixes, like | - | ||||||||||||||||||
96 | "lib" on Unix and Mac, and suffixes, like ".so" on Unix, ".dylib" | - | ||||||||||||||||||
97 | on the Mac, or ".dll" on Windows. | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | If the file path is not absolute then QLibrary modifies the search | - | ||||||||||||||||||
100 | order to try the system-specific prefixes and suffixes first, | - | ||||||||||||||||||
101 | followed by the file path specified. | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | This makes it possible to specify shared libraries that are only | - | ||||||||||||||||||
104 | identified by their basename (i.e. without their suffix), so the | - | ||||||||||||||||||
105 | same code will work on different operating systems yet still | - | ||||||||||||||||||
106 | minimise the number of attempts to find the library. | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | The most important functions are load() to dynamically load the | - | ||||||||||||||||||
109 | library file, isLoaded() to check whether loading was successful, | - | ||||||||||||||||||
110 | and resolve() to resolve a symbol in the library. The resolve() | - | ||||||||||||||||||
111 | function implicitly tries to load the library if it has not been | - | ||||||||||||||||||
112 | loaded yet. Multiple instances of QLibrary can be used to access | - | ||||||||||||||||||
113 | the same physical library. Once loaded, libraries remain in memory | - | ||||||||||||||||||
114 | until the application terminates. You can attempt to unload a | - | ||||||||||||||||||
115 | library using unload(), but if other instances of QLibrary are | - | ||||||||||||||||||
116 | using the same library, the call will fail, and unloading will | - | ||||||||||||||||||
117 | only happen when every instance has called unload(). | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | A typical use of QLibrary is to resolve an exported symbol in a | - | ||||||||||||||||||
120 | library, and to call the C function that this symbol represents. | - | ||||||||||||||||||
121 | This is called "explicit linking" in contrast to "implicit | - | ||||||||||||||||||
122 | linking", which is done by the link step in the build process when | - | ||||||||||||||||||
123 | linking an executable against a library. | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | The following code snippet loads a library, resolves the symbol | - | ||||||||||||||||||
126 | "mysymbol", and calls the function if everything succeeded. If | - | ||||||||||||||||||
127 | something goes wrong, e.g. the library file does not exist or the | - | ||||||||||||||||||
128 | symbol is not defined, the function pointer will be 0 and won't be | - | ||||||||||||||||||
129 | called. | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | \snippet code/src_corelib_plugin_qlibrary.cpp 0 | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | The symbol must be exported as a C function from the library for | - | ||||||||||||||||||
134 | resolve() to work. This means that the function must be wrapped in | - | ||||||||||||||||||
135 | an \c{extern "C"} block if the library is compiled with a C++ | - | ||||||||||||||||||
136 | compiler. On Windows, this also requires the use of a \c dllexport | - | ||||||||||||||||||
137 | macro; see resolve() for the details of how this is done. For | - | ||||||||||||||||||
138 | convenience, there is a static resolve() function which you can | - | ||||||||||||||||||
139 | use if you just want to call a function in a library without | - | ||||||||||||||||||
140 | explicitly loading the library first: | - | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | \snippet code/src_corelib_plugin_qlibrary.cpp 1 | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | \sa QPluginLoader | - | ||||||||||||||||||
145 | */ | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | /*! | - | ||||||||||||||||||
148 | \enum QLibrary::LoadHint | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | This enum describes the possible hints that can be used to change the way | - | ||||||||||||||||||
151 | libraries are handled when they are loaded. These values indicate how | - | ||||||||||||||||||
152 | symbols are resolved when libraries are loaded, and are specified using | - | ||||||||||||||||||
153 | the setLoadHints() function. | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | \value ResolveAllSymbolsHint | - | ||||||||||||||||||
156 | Causes all symbols in a library to be resolved when it is loaded, not | - | ||||||||||||||||||
157 | simply when resolve() is called. | - | ||||||||||||||||||
158 | \value ExportExternalSymbolsHint | - | ||||||||||||||||||
159 | Exports unresolved and external symbols in the library so that they can be | - | ||||||||||||||||||
160 | resolved in other dynamically-loaded libraries loaded later. | - | ||||||||||||||||||
161 | \value LoadArchiveMemberHint | - | ||||||||||||||||||
162 | Allows the file name of the library to specify a particular object file | - | ||||||||||||||||||
163 | within an archive file. | - | ||||||||||||||||||
164 | If this hint is given, the filename of the library consists of | - | ||||||||||||||||||
165 | a path, which is a reference to an archive file, followed by | - | ||||||||||||||||||
166 | a reference to the archive member. | - | ||||||||||||||||||
167 | \value PreventUnloadHint | - | ||||||||||||||||||
168 | Prevents the library from being unloaded from the address space if close() | - | ||||||||||||||||||
169 | is called. The library's static variables are not reinitialized if open() | - | ||||||||||||||||||
170 | is called at a later time. | - | ||||||||||||||||||
171 | \value DeepBindHint | - | ||||||||||||||||||
172 | Instructs the linker to prefer definitions in the loaded library | - | ||||||||||||||||||
173 | over exported definitions in the loading application when resolving | - | ||||||||||||||||||
174 | external symbols in the loaded library. This option is only supported | - | ||||||||||||||||||
175 | on Linux. | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | \sa loadHints | - | ||||||||||||||||||
178 | */ | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | - | |||||||||||||||||||
181 | static long qt_find_pattern(const char *s, ulong s_len, | - | ||||||||||||||||||
182 | const char *pattern, ulong p_len) | - | ||||||||||||||||||
183 | { | - | ||||||||||||||||||
184 | /* | - | ||||||||||||||||||
185 | we search from the end of the file because on the supported | - | ||||||||||||||||||
186 | systems, the read-only data/text segments are placed at the end | - | ||||||||||||||||||
187 | of the file. HOWEVER, when building with debugging enabled, all | - | ||||||||||||||||||
188 | the debug symbols are placed AFTER the data/text segments. | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | what does this mean? when building in release mode, the search | - | ||||||||||||||||||
191 | is fast because the data we are looking for is at the end of the | - | ||||||||||||||||||
192 | file... when building in debug mode, the search is slower | - | ||||||||||||||||||
193 | because we have to skip over all the debugging symbols first | - | ||||||||||||||||||
194 | */ | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | if (! s || ! pattern || p_len > s_len) return -1; never executed: return -1;
| 0-651 | ||||||||||||||||||
197 | ulong i, hs = 0, hp = 0, delta = s_len - p_len; | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | for (i = 0; i < p_len; ++i) {
| 651-7812 | ||||||||||||||||||
200 | hs += s[delta + i]; | - | ||||||||||||||||||
201 | hp += pattern[i]; | - | ||||||||||||||||||
202 | } executed 7812 times by 110 tests: end of block Executed by:
| 7812 | ||||||||||||||||||
203 | i = delta; | - | ||||||||||||||||||
204 | for (;;) { | - | ||||||||||||||||||
205 | if (hs == hp && qstrncmp(s + i, pattern, p_len) == 0)
| 13-174960 | ||||||||||||||||||
206 | return i; executed 651 times by 110 tests: return i; Executed by:
| 651 | ||||||||||||||||||
207 | if (i == 0)
| 0-174973 | ||||||||||||||||||
208 | break; never executed: break; | 0 | ||||||||||||||||||
209 | --i; | - | ||||||||||||||||||
210 | hs -= s[i + p_len]; | - | ||||||||||||||||||
211 | hs += s[i]; | - | ||||||||||||||||||
212 | } executed 174973 times by 110 tests: end of block Executed by:
| 174973 | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | /* | - | ||||||||||||||||||
218 | This opens the specified library, mmaps it into memory, and searches | - | ||||||||||||||||||
219 | for the QT_PLUGIN_VERIFICATION_DATA. The advantage of this approach is that | - | ||||||||||||||||||
220 | we can get the verification data without have to actually load the library. | - | ||||||||||||||||||
221 | This lets us detect mismatches more safely. | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | Returns \c false if version information is not present, or if the | - | ||||||||||||||||||
224 | information could not be read. | - | ||||||||||||||||||
225 | Returns true if version information is present and successfully read. | - | ||||||||||||||||||
226 | */ | - | ||||||||||||||||||
227 | static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib) | - | ||||||||||||||||||
228 | { | - | ||||||||||||||||||
229 | QFile file(library); | - | ||||||||||||||||||
230 | if (!file.open(QIODevice::ReadOnly)) {
| 0-1346 | ||||||||||||||||||
231 | if (lib)
| 0 | ||||||||||||||||||
232 | lib->errorString = file.errorString(); never executed: lib->errorString = file.errorString(); | 0 | ||||||||||||||||||
233 | if (qt_debug_component()) {
| 0 | ||||||||||||||||||
234 | qWarning("%s: %s", (const char*) QFile::encodeName(library), | - | ||||||||||||||||||
235 | qPrintable(qt_error_string(errno))); | - | ||||||||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||||||||
237 | return false; never executed: return false; | 0 | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | QByteArray data; | - | ||||||||||||||||||
241 | const char *filedata = 0; | - | ||||||||||||||||||
242 | ulong fdlen = file.size(); | - | ||||||||||||||||||
243 | filedata = (char *) file.map(0, fdlen); | - | ||||||||||||||||||
244 | if (filedata == 0) {
| 0-1346 | ||||||||||||||||||
245 | // try reading the data into memory instead | - | ||||||||||||||||||
246 | data = file.readAll(); | - | ||||||||||||||||||
247 | filedata = data.constData(); | - | ||||||||||||||||||
248 | fdlen = data.size(); | - | ||||||||||||||||||
249 | } never executed: end of block | 0 | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | /* | - | ||||||||||||||||||
252 | ELF and Mach-O binaries with GCC have .qplugin sections. | - | ||||||||||||||||||
253 | */ | - | ||||||||||||||||||
254 | bool hasMetaData = false; | - | ||||||||||||||||||
255 | long pos = 0; | - | ||||||||||||||||||
256 | char pattern[] = "qTMETADATA "; | - | ||||||||||||||||||
257 | pattern[0] = 'Q'; // Ensure the pattern "QTMETADATA" is not found in this library should QPluginLoader ever encounter it. | - | ||||||||||||||||||
258 | const ulong plen = qstrlen(pattern); | - | ||||||||||||||||||
259 | #if defined (Q_OF_ELF) && defined(Q_CC_GNU) | - | ||||||||||||||||||
260 | int r = QElfParser().parse(filedata, fdlen, library, lib, &pos, &fdlen); | - | ||||||||||||||||||
261 | if (r == QElfParser::Corrupt || r == QElfParser::NotElf) {
| 3-1343 | ||||||||||||||||||
262 | if (lib && qt_debug_component()) {
| 0-694 | ||||||||||||||||||
263 | qWarning("QElfParser: %s",qPrintable(lib->errorString)); | - | ||||||||||||||||||
264 | } never executed: end of block | 0 | ||||||||||||||||||
265 | return false; executed 694 times by 111 tests: return false; Executed by:
| 694 | ||||||||||||||||||
266 | } else if (r == QElfParser::QtMetaDataSection) {
| 1-651 | ||||||||||||||||||
267 | long rel = qt_find_pattern(filedata + pos, fdlen, pattern, plen); | - | ||||||||||||||||||
268 | if (rel < 0)
| 0-651 | ||||||||||||||||||
269 | pos = -1; never executed: pos = -1; | 0 | ||||||||||||||||||
270 | else | - | ||||||||||||||||||
271 | pos += rel; executed 651 times by 110 tests: pos += rel; Executed by:
| 651 | ||||||||||||||||||
272 | hasMetaData = true; | - | ||||||||||||||||||
273 | } executed 651 times by 110 tests: end of block Executed by:
| 651 | ||||||||||||||||||
274 | #elif defined (Q_OF_MACH_O) | - | ||||||||||||||||||
275 | { | - | ||||||||||||||||||
276 | QString errorString; | - | ||||||||||||||||||
277 | int r = QMachOParser::parse(filedata, fdlen, library, &errorString, &pos, &fdlen); | - | ||||||||||||||||||
278 | if (r == QMachOParser::NotSuitable) { | - | ||||||||||||||||||
279 | if (qt_debug_component()) | - | ||||||||||||||||||
280 | qWarning("QMachOParser: %s", qPrintable(errorString)); | - | ||||||||||||||||||
281 | if (lib) | - | ||||||||||||||||||
282 | lib->errorString = errorString; | - | ||||||||||||||||||
283 | return false; | - | ||||||||||||||||||
284 | } | - | ||||||||||||||||||
285 | // even if the metadata section was not found, the Mach-O parser will | - | ||||||||||||||||||
286 | // at least return the boundaries of the right architecture | - | ||||||||||||||||||
287 | long rel = qt_find_pattern(filedata + pos, fdlen, pattern, plen); | - | ||||||||||||||||||
288 | if (rel < 0) | - | ||||||||||||||||||
289 | pos = -1; | - | ||||||||||||||||||
290 | else | - | ||||||||||||||||||
291 | pos += rel; | - | ||||||||||||||||||
292 | hasMetaData = true; | - | ||||||||||||||||||
293 | } | - | ||||||||||||||||||
294 | #else | - | ||||||||||||||||||
295 | pos = qt_find_pattern(filedata, fdlen, pattern, plen); | - | ||||||||||||||||||
296 | if (pos > 0) | - | ||||||||||||||||||
297 | hasMetaData = true; | - | ||||||||||||||||||
298 | #endif // defined(Q_OF_ELF) && defined(Q_CC_GNU) | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | bool ret = false; | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | if (pos >= 0) {
| 0-652 | ||||||||||||||||||
303 | if (hasMetaData) {
| 1-651 | ||||||||||||||||||
304 | const char *data = filedata + pos; | - | ||||||||||||||||||
305 | QJsonDocument doc = QLibraryPrivate::fromRawMetaData(data); | - | ||||||||||||||||||
306 | lib->metaData = doc.object(); | - | ||||||||||||||||||
307 | if (qt_debug_component())
| 0-651 | ||||||||||||||||||
308 | qWarning("Found metadata in lib %s, metadata=\n%s\n", never executed: QMessageLogger(__FILE__, 308, __PRETTY_FUNCTION__).warning("Found metadata in lib %s, metadata=\n%s\n", library.toLocal8Bit().constData(), doc.toJson().constData()); | 0 | ||||||||||||||||||
309 | library.toLocal8Bit().constData(), doc.toJson().constData()); never executed: QMessageLogger(__FILE__, 308, __PRETTY_FUNCTION__).warning("Found metadata in lib %s, metadata=\n%s\n", library.toLocal8Bit().constData(), doc.toJson().constData()); | 0 | ||||||||||||||||||
310 | ret = !doc.isNull(); | - | ||||||||||||||||||
311 | } executed 651 times by 110 tests: end of block Executed by:
| 651 | ||||||||||||||||||
312 | } executed 652 times by 110 tests: end of block Executed by:
| 652 | ||||||||||||||||||
313 | - | |||||||||||||||||||
314 | if (!ret && lib)
| 0-651 | ||||||||||||||||||
315 | lib->errorString = QLibrary::tr("Failed to extract plugin meta data from '%1'").arg(library); executed 1 time by 1 test: lib->errorString = QLibrary::tr("Failed to extract plugin meta data from '%1'").arg(library); Executed by:
| 1 | ||||||||||||||||||
316 | file.close(); | - | ||||||||||||||||||
317 | return ret; executed 652 times by 110 tests: return ret; Executed by:
| 652 | ||||||||||||||||||
318 | } | - | ||||||||||||||||||
319 | - | |||||||||||||||||||
320 | static void installCoverageTool(QLibraryPrivate *libPrivate) | - | ||||||||||||||||||
321 | { | - | ||||||||||||||||||
322 | #ifdef __COVERAGESCANNER__ | - | ||||||||||||||||||
323 | /* | - | ||||||||||||||||||
324 | __COVERAGESCANNER__ is defined when Qt has been instrumented for code | - | ||||||||||||||||||
325 | coverage by TestCocoon. CoverageScanner is the name of the tool that | - | ||||||||||||||||||
326 | generates the code instrumentation. | - | ||||||||||||||||||
327 | This code is required here when code coverage analysis with TestCocoon | - | ||||||||||||||||||
328 | is enabled in order to allow the loading application to register the plugin | - | ||||||||||||||||||
329 | and then store its execution report. The execution report gathers information | - | ||||||||||||||||||
330 | about each part of the plugin's code that has been used when | - | ||||||||||||||||||
331 | the plugin was loaded by the launching application. | - | ||||||||||||||||||
332 | The execution report for the plugin will go to the same execution report | - | ||||||||||||||||||
333 | as the one defined for the application loading it. | - | ||||||||||||||||||
334 | */ | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | int ret = __coveragescanner_register_library(libPrivate->fileName.toLocal8Bit()); | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | if (qt_debug_component()) {
| 0-514 | ||||||||||||||||||
339 | if (ret >= 0) {
| 0 | ||||||||||||||||||
340 | qDebug("coverage data for %s registered", | - | ||||||||||||||||||
341 | qPrintable(libPrivate->fileName)); | - | ||||||||||||||||||
342 | } else { never executed: end of block | 0 | ||||||||||||||||||
343 | qWarning("could not register %s: error %d; coverage data may be incomplete", | - | ||||||||||||||||||
344 | qPrintable(libPrivate->fileName), | - | ||||||||||||||||||
345 | ret); | - | ||||||||||||||||||
346 | } never executed: end of block | 0 | ||||||||||||||||||
347 | } | - | ||||||||||||||||||
348 | #else | - | ||||||||||||||||||
349 | Q_UNUSED(libPrivate); | - | ||||||||||||||||||
350 | #endif | - | ||||||||||||||||||
351 | } executed 514 times by 134 tests: end of block Executed by:
| 514 | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | class QLibraryStore | - | ||||||||||||||||||
354 | { | - | ||||||||||||||||||
355 | public: | - | ||||||||||||||||||
356 | inline ~QLibraryStore(); | - | ||||||||||||||||||
357 | static inline QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version, QLibrary::LoadHints loadHints); | - | ||||||||||||||||||
358 | static inline void releaseLibrary(QLibraryPrivate *lib); | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | static inline void cleanup(); | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | private: | - | ||||||||||||||||||
363 | static inline QLibraryStore *instance(); | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | // all members and instance() are protected by qt_library_mutex | - | ||||||||||||||||||
366 | typedef QMap<QString, QLibraryPrivate*> LibraryMap; | - | ||||||||||||||||||
367 | LibraryMap libraryMap; | - | ||||||||||||||||||
368 | }; | - | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | static QBasicMutex qt_library_mutex; | - | ||||||||||||||||||
371 | static QLibraryStore *qt_library_data = 0; | - | ||||||||||||||||||
372 | static bool qt_library_data_once; | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | QLibraryStore::~QLibraryStore() | - | ||||||||||||||||||
375 | { | - | ||||||||||||||||||
376 | qt_library_data = 0; | - | ||||||||||||||||||
377 | } never executed: end of block | 0 | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | inline void QLibraryStore::cleanup() | - | ||||||||||||||||||
380 | { | - | ||||||||||||||||||
381 | QLibraryStore *data = qt_library_data; | - | ||||||||||||||||||
382 | if (!data)
| 0 | ||||||||||||||||||
383 | return; never executed: return; | 0 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | // find any libraries that are still loaded but have a no one attached to them | - | ||||||||||||||||||
386 | LibraryMap::Iterator it = data->libraryMap.begin(); | - | ||||||||||||||||||
387 | for (; it != data->libraryMap.end(); ++it) {
| 0 | ||||||||||||||||||
388 | QLibraryPrivate *lib = it.value(); | - | ||||||||||||||||||
389 | if (lib->libraryRefCount.load() == 1) {
| 0 | ||||||||||||||||||
390 | if (lib->libraryUnloadCount.load() > 0) {
| 0 | ||||||||||||||||||
391 | Q_ASSERT(lib->pHnd); | - | ||||||||||||||||||
392 | lib->libraryUnloadCount.store(1); | - | ||||||||||||||||||
393 | #ifdef __GLIBC__ | - | ||||||||||||||||||
394 | // glibc has a bug in unloading from global destructors | - | ||||||||||||||||||
395 | // see https://bugzilla.novell.com/show_bug.cgi?id=622977 | - | ||||||||||||||||||
396 | // and http://sourceware.org/bugzilla/show_bug.cgi?id=11941 | - | ||||||||||||||||||
397 | lib->unload(QLibraryPrivate::NoUnloadSys); | - | ||||||||||||||||||
398 | #else | - | ||||||||||||||||||
399 | lib->unload(); | - | ||||||||||||||||||
400 | #endif | - | ||||||||||||||||||
401 | } never executed: end of block | 0 | ||||||||||||||||||
402 | delete lib; | - | ||||||||||||||||||
403 | it.value() = 0; | - | ||||||||||||||||||
404 | } never executed: end of block | 0 | ||||||||||||||||||
405 | } never executed: end of block | 0 | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | if (qt_debug_component()) {
| 0 | ||||||||||||||||||
408 | // dump all objects that remain | - | ||||||||||||||||||
409 | foreach (QLibraryPrivate *lib, data->libraryMap) { | - | ||||||||||||||||||
410 | if (lib)
| 0 | ||||||||||||||||||
411 | qDebug() << "On QtCore unload," << lib->fileName << "was leaked, with" never executed: QMessageLogger(__FILE__, 411, __PRETTY_FUNCTION__).debug() << "On QtCore unload," << lib->fileName << "was leaked, with" << lib->libraryRefCount.load() << "users"; | 0 | ||||||||||||||||||
412 | << lib->libraryRefCount.load() << "users"; never executed: QMessageLogger(__FILE__, 411, __PRETTY_FUNCTION__).debug() << "On QtCore unload," << lib->fileName << "was leaked, with" << lib->libraryRefCount.load() << "users"; | 0 | ||||||||||||||||||
413 | } never executed: end of block | 0 | ||||||||||||||||||
414 | } never executed: end of block | 0 | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | delete data; | - | ||||||||||||||||||
417 | } never executed: end of block | 0 | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | static void qlibraryCleanup() | - | ||||||||||||||||||
420 | { | - | ||||||||||||||||||
421 | QLibraryStore::cleanup(); | - | ||||||||||||||||||
422 | } never executed: end of block | 0 | ||||||||||||||||||
423 | Q_DESTRUCTOR_FUNCTION(qlibraryCleanup) never executed: end of block | 0 | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | // must be called with a locked mutex | - | ||||||||||||||||||
426 | QLibraryStore *QLibraryStore::instance() | - | ||||||||||||||||||
427 | { | - | ||||||||||||||||||
428 | if (Q_UNLIKELY(!qt_library_data_once && !qt_library_data)) {
| 72-5998 | ||||||||||||||||||
429 | // only create once per process lifetime | - | ||||||||||||||||||
430 | qt_library_data = new QLibraryStore; | - | ||||||||||||||||||
431 | qt_library_data_once = true; | - | ||||||||||||||||||
432 | } executed 72 times by 48 tests: end of block Executed by:
| 72 | ||||||||||||||||||
433 | return qt_library_data; executed 6070 times by 378 tests: return qt_library_data; Executed by:
| 6070 | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | inline QLibraryPrivate *QLibraryStore::findOrCreate(const QString &fileName, const QString &version, | - | ||||||||||||||||||
437 | QLibrary::LoadHints loadHints) | - | ||||||||||||||||||
438 | { | - | ||||||||||||||||||
439 | QMutexLocker locker(&qt_library_mutex); | - | ||||||||||||||||||
440 | QLibraryStore *data = instance(); | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | // check if this library is already loaded | - | ||||||||||||||||||
443 | QLibraryPrivate *lib = 0; | - | ||||||||||||||||||
444 | if (Q_LIKELY(data)) {
| 0-1855 | ||||||||||||||||||
445 | lib = data->libraryMap.value(fileName); | - | ||||||||||||||||||
446 | if (lib)
| 359-1496 | ||||||||||||||||||
447 | lib->mergeLoadHints(loadHints); executed 359 times by 23 tests: lib->mergeLoadHints(loadHints); Executed by:
| 359 | ||||||||||||||||||
448 | } executed 1855 times by 136 tests: end of block Executed by:
| 1855 | ||||||||||||||||||
449 | if (!lib)
| 359-1496 | ||||||||||||||||||
450 | lib = new QLibraryPrivate(fileName, version, loadHints); executed 1496 times by 136 tests: lib = new QLibraryPrivate(fileName, version, loadHints); Executed by:
| 1496 | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | // track this library | - | ||||||||||||||||||
453 | if (Q_LIKELY(data) && !fileName.isEmpty())
| 0-1855 | ||||||||||||||||||
454 | data->libraryMap.insert(fileName, lib); executed 1849 times by 136 tests: data->libraryMap.insert(fileName, lib); Executed by:
| 1849 | ||||||||||||||||||
455 | - | |||||||||||||||||||
456 | lib->libraryRefCount.ref(); | - | ||||||||||||||||||
457 | return lib; executed 1855 times by 136 tests: return lib; Executed by:
| 1855 | ||||||||||||||||||
458 | } | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | inline void QLibraryStore::releaseLibrary(QLibraryPrivate *lib) | - | ||||||||||||||||||
461 | { | - | ||||||||||||||||||
462 | QMutexLocker locker(&qt_library_mutex); | - | ||||||||||||||||||
463 | QLibraryStore *data = instance(); | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | if (lib->libraryRefCount.deref()) {
| 463-3752 | ||||||||||||||||||
466 | // still in use | - | ||||||||||||||||||
467 | return; executed 463 times by 61 tests: return; Executed by:
| 463 | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | // no one else is using | - | ||||||||||||||||||
471 | Q_ASSERT(lib->libraryUnloadCount.load() == 0); | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | if (Q_LIKELY(data) && !lib->fileName.isEmpty()) {
| 0-3752 | ||||||||||||||||||
474 | QLibraryPrivate *that = data->libraryMap.take(lib->fileName); | - | ||||||||||||||||||
475 | Q_ASSERT(lib == that); | - | ||||||||||||||||||
476 | Q_UNUSED(that); | - | ||||||||||||||||||
477 | } executed 3746 times by 355 tests: end of block Executed by:
| 3746 | ||||||||||||||||||
478 | delete lib; | - | ||||||||||||||||||
479 | } executed 3752 times by 355 tests: end of block Executed by:
| 3752 | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | QLibraryPrivate::QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints) | - | ||||||||||||||||||
482 | : pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0), | - | ||||||||||||||||||
483 | libraryRefCount(0), libraryUnloadCount(0), pluginState(MightBeAPlugin) | - | ||||||||||||||||||
484 | { | - | ||||||||||||||||||
485 | loadHintsInt.store(loadHints); | - | ||||||||||||||||||
486 | if (canonicalFileName.isEmpty())
| 6-1490 | ||||||||||||||||||
487 | errorString = QLibrary::tr("The shared library was not found."); executed 6 times by 2 tests: errorString = QLibrary::tr("The shared library was not found."); Executed by:
| 6 | ||||||||||||||||||
488 | } executed 1496 times by 136 tests: end of block Executed by:
| 1496 | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | QLibraryPrivate *QLibraryPrivate::findOrCreate(const QString &fileName, const QString &version, | - | ||||||||||||||||||
491 | QLibrary::LoadHints loadHints) | - | ||||||||||||||||||
492 | { | - | ||||||||||||||||||
493 | return QLibraryStore::findOrCreate(fileName, version, loadHints); executed 1855 times by 136 tests: return QLibraryStore::findOrCreate(fileName, version, loadHints); Executed by:
| 1855 | ||||||||||||||||||
494 | } | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | QLibraryPrivate::~QLibraryPrivate() | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | } | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | void QLibraryPrivate::mergeLoadHints(QLibrary::LoadHints lh) | - | ||||||||||||||||||
501 | { | - | ||||||||||||||||||
502 | // if the library is already loaded, we can't change the load hints | - | ||||||||||||||||||
503 | if (pHnd)
| 407-664 | ||||||||||||||||||
504 | return; executed 407 times by 23 tests: return; Executed by:
| 407 | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | loadHintsInt.store(lh); | - | ||||||||||||||||||
507 | } executed 664 times by 111 tests: end of block Executed by:
| 664 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | QFunctionPointer QLibraryPrivate::resolve(const char *symbol) | - | ||||||||||||||||||
510 | { | - | ||||||||||||||||||
511 | if (!pHnd)
| 0-12867 | ||||||||||||||||||
512 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
513 | return resolve_sys(symbol); executed 12867 times by 134 tests: return resolve_sys(symbol); Executed by:
| 12867 | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | void QLibraryPrivate::setLoadHints(QLibrary::LoadHints lh) | - | ||||||||||||||||||
517 | { | - | ||||||||||||||||||
518 | // this locks a global mutex | - | ||||||||||||||||||
519 | QMutexLocker lock(&qt_library_mutex); | - | ||||||||||||||||||
520 | mergeLoadHints(lh); | - | ||||||||||||||||||
521 | } executed 712 times by 113 tests: end of block Executed by:
| 712 | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | bool QLibraryPrivate::load() | - | ||||||||||||||||||
524 | { | - | ||||||||||||||||||
525 | if (pHnd) {
| 2-520 | ||||||||||||||||||
526 | libraryUnloadCount.ref(); | - | ||||||||||||||||||
527 | return true; executed 2 times by 2 tests: return true; Executed by:
| 2 | ||||||||||||||||||
528 | } | - | ||||||||||||||||||
529 | if (fileName.isEmpty())
| 0-520 | ||||||||||||||||||
530 | return false; never executed: return false; | 0 | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | bool ret = load_sys(); | - | ||||||||||||||||||
533 | if (qt_debug_component())
| 0-520 | ||||||||||||||||||
534 | qDebug() << "loaded library" << fileName; never executed: QMessageLogger(__FILE__, 534, __PRETTY_FUNCTION__).debug() << "loaded library" << fileName; | 0 | ||||||||||||||||||
535 | if (ret) {
| 6-514 | ||||||||||||||||||
536 | //when loading a library we add a reference to it so that the QLibraryPrivate won't get deleted | - | ||||||||||||||||||
537 | //this allows to unload the library at a later time | - | ||||||||||||||||||
538 | libraryUnloadCount.ref(); | - | ||||||||||||||||||
539 | libraryRefCount.ref(); | - | ||||||||||||||||||
540 | installCoverageTool(this); | - | ||||||||||||||||||
541 | } executed 514 times by 134 tests: end of block Executed by:
| 514 | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | return ret; executed 520 times by 134 tests: return ret; Executed by:
| 520 | ||||||||||||||||||
544 | } | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | bool QLibraryPrivate::unload(UnloadFlag flag) | - | ||||||||||||||||||
547 | { | - | ||||||||||||||||||
548 | if (!pHnd)
| 1065-2013 | ||||||||||||||||||
549 | return false; executed 2013 times by 228 tests: return false; Executed by:
| 2013 | ||||||||||||||||||
550 | if (libraryUnloadCount.load() > 0 && !libraryUnloadCount.deref()) { // only unload if ALL QLibrary instance wanted to
| 0-1065 | ||||||||||||||||||
551 | delete inst.data(); | - | ||||||||||||||||||
552 | if (flag == NoUnloadSys || unload_sys()) {
| 0-1062 | ||||||||||||||||||
553 | if (qt_debug_component())
| 0-1062 | ||||||||||||||||||
554 | qWarning() << "QLibraryPrivate::unload succeeded on" << fileName never executed: QMessageLogger(__FILE__, 554, __PRETTY_FUNCTION__).warning() << "QLibraryPrivate::unload succeeded on" << fileName << (flag == NoUnloadSys ? "(faked)" : ""); | 0 | ||||||||||||||||||
555 | << (flag == NoUnloadSys ? "(faked)" : ""); never executed: QMessageLogger(__FILE__, 554, __PRETTY_FUNCTION__).warning() << "QLibraryPrivate::unload succeeded on" << fileName << (flag == NoUnloadSys ? "(faked)" : ""); | 0 | ||||||||||||||||||
556 | //when the library is unloaded, we release the reference on it so that 'this' | - | ||||||||||||||||||
557 | //can get deleted | - | ||||||||||||||||||
558 | libraryRefCount.deref(); | - | ||||||||||||||||||
559 | pHnd = 0; | - | ||||||||||||||||||
560 | instance = 0; | - | ||||||||||||||||||
561 | } executed 1062 times by 249 tests: end of block Executed by:
| 1062 | ||||||||||||||||||
562 | } executed 1062 times by 249 tests: end of block Executed by:
| 1062 | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | return (pHnd == 0); executed 1065 times by 249 tests: return (pHnd == 0); Executed by:
| 1065 | ||||||||||||||||||
565 | } | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | void QLibraryPrivate::release() | - | ||||||||||||||||||
568 | { | - | ||||||||||||||||||
569 | QLibraryStore::releaseLibrary(this); | - | ||||||||||||||||||
570 | } executed 4215 times by 378 tests: end of block Executed by:
| 4215 | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | bool QLibraryPrivate::loadPlugin() | - | ||||||||||||||||||
573 | { | - | ||||||||||||||||||
574 | if (instance) {
| 1-390 | ||||||||||||||||||
575 | libraryUnloadCount.ref(); | - | ||||||||||||||||||
576 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
577 | } | - | ||||||||||||||||||
578 | if (pluginState == IsNotAPlugin)
| 0-390 | ||||||||||||||||||
579 | return false; never executed: return false; | 0 | ||||||||||||||||||
580 | if (load()) {
| 0-390 | ||||||||||||||||||
581 | instance = (QtPluginInstanceFunction)resolve("qt_plugin_instance"); | - | ||||||||||||||||||
582 | return instance; executed 390 times by 110 tests: return instance; Executed by:
| 390 | ||||||||||||||||||
583 | } | - | ||||||||||||||||||
584 | if (qt_debug_component())
| 0 | ||||||||||||||||||
585 | qWarning() << "QLibraryPrivate::loadPlugin failed on" << fileName << ":" << errorString; never executed: QMessageLogger(__FILE__, 585, __PRETTY_FUNCTION__).warning() << "QLibraryPrivate::loadPlugin failed on" << fileName << ":" << errorString; | 0 | ||||||||||||||||||
586 | pluginState = IsNotAPlugin; | - | ||||||||||||||||||
587 | return false; never executed: return false; | 0 | ||||||||||||||||||
588 | } | - | ||||||||||||||||||
589 | - | |||||||||||||||||||
590 | /*! | - | ||||||||||||||||||
591 | Returns \c true if \a fileName has a valid suffix for a loadable | - | ||||||||||||||||||
592 | library; otherwise returns \c false. | - | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | \table | - | ||||||||||||||||||
595 | \header \li Platform \li Valid suffixes | - | ||||||||||||||||||
596 | \row \li Windows \li \c .dll, \c .DLL | - | ||||||||||||||||||
597 | \row \li Unix/Linux \li \c .so | - | ||||||||||||||||||
598 | \row \li AIX \li \c .a | - | ||||||||||||||||||
599 | \row \li HP-UX \li \c .sl, \c .so (HP-UXi) | - | ||||||||||||||||||
600 | \row \li \macos and iOS \li \c .dylib, \c .bundle, \c .so | - | ||||||||||||||||||
601 | \endtable | - | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | Trailing versioning numbers on Unix are ignored. | - | ||||||||||||||||||
604 | */ | - | ||||||||||||||||||
605 | bool QLibrary::isLibrary(const QString &fileName) | - | ||||||||||||||||||
606 | { | - | ||||||||||||||||||
607 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
608 | return fileName.endsWith(QLatin1String(".dll"), Qt::CaseInsensitive); | - | ||||||||||||||||||
609 | #else | - | ||||||||||||||||||
610 | QString completeSuffix = QFileInfo(fileName).completeSuffix(); | - | ||||||||||||||||||
611 | if (completeSuffix.isEmpty())
| 0-16 | ||||||||||||||||||
612 | return false; never executed: return false; | 0 | ||||||||||||||||||
613 | QStringList suffixes = completeSuffix.split(QLatin1Char('.')); | - | ||||||||||||||||||
614 | # if defined(Q_OS_DARWIN) | - | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | // On Mac, libs look like libmylib.1.0.0.dylib | - | ||||||||||||||||||
617 | const QString lastSuffix = suffixes.at(suffixes.count() - 1); | - | ||||||||||||||||||
618 | const QString firstSuffix = suffixes.at(0); | - | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | bool valid = (lastSuffix == QLatin1String("dylib") | - | ||||||||||||||||||
621 | || firstSuffix == QLatin1String("so") | - | ||||||||||||||||||
622 | || firstSuffix == QLatin1String("bundle")); | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | return valid; | - | ||||||||||||||||||
625 | # else // Generic Unix | - | ||||||||||||||||||
626 | QStringList validSuffixList; | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | # if defined(Q_OS_HPUX) | - | ||||||||||||||||||
629 | /* | - | ||||||||||||||||||
630 | See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF": | - | ||||||||||||||||||
631 | "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), | - | ||||||||||||||||||
632 | the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." | - | ||||||||||||||||||
633 | */ | - | ||||||||||||||||||
634 | validSuffixList << QLatin1String("sl"); | - | ||||||||||||||||||
635 | # if defined __ia64 | - | ||||||||||||||||||
636 | validSuffixList << QLatin1String("so"); | - | ||||||||||||||||||
637 | # endif | - | ||||||||||||||||||
638 | # elif defined(Q_OS_AIX) | - | ||||||||||||||||||
639 | validSuffixList << QLatin1String("a") << QLatin1String("so"); | - | ||||||||||||||||||
640 | # elif defined(Q_OS_UNIX) | - | ||||||||||||||||||
641 | validSuffixList << QLatin1String("so"); | - | ||||||||||||||||||
642 | # endif | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | // Examples of valid library names: | - | ||||||||||||||||||
645 | // libfoo.so | - | ||||||||||||||||||
646 | // libfoo.so.0 | - | ||||||||||||||||||
647 | // libfoo.so.0.3 | - | ||||||||||||||||||
648 | // libfoo-0.3.so | - | ||||||||||||||||||
649 | // libfoo-0.3.so.0.3.0 | - | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | int suffix; | - | ||||||||||||||||||
652 | int suffixPos = -1; | - | ||||||||||||||||||
653 | for (suffix = 0; suffix < validSuffixList.count() && suffixPos == -1; ++suffix)
| 0-16 | ||||||||||||||||||
654 | suffixPos = suffixes.indexOf(validSuffixList.at(suffix)); executed 16 times by 2 tests: suffixPos = suffixes.indexOf(validSuffixList.at(suffix)); Executed by:
| 16 | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | bool valid = suffixPos != -1; | - | ||||||||||||||||||
657 | for (int i = suffixPos + 1; i < suffixes.count() && valid; ++i)
| 6-14 | ||||||||||||||||||
658 | if (i != suffixPos)
| 0-6 | ||||||||||||||||||
659 | suffixes.at(i).toInt(&valid); executed 6 times by 2 tests: suffixes.at(i).toInt(&valid); Executed by:
| 6 | ||||||||||||||||||
660 | return valid; executed 16 times by 2 tests: return valid; Executed by:
| 16 | ||||||||||||||||||
661 | # endif | - | ||||||||||||||||||
662 | #endif | - | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | } | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | typedef const char * (*QtPluginQueryVerificationDataFunction)(); | - | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | static bool qt_get_metadata(QtPluginQueryVerificationDataFunction pfn, QLibraryPrivate *priv) | - | ||||||||||||||||||
669 | { | - | ||||||||||||||||||
670 | const char *szData = 0; | - | ||||||||||||||||||
671 | if (!pfn)
| 2 | ||||||||||||||||||
672 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | szData = pfn(); | - | ||||||||||||||||||
675 | if (!szData)
| 0-2 | ||||||||||||||||||
676 | return false; never executed: return false; | 0 | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | QJsonDocument doc = QLibraryPrivate::fromRawMetaData(szData); | - | ||||||||||||||||||
679 | if (doc.isNull())
| 0-2 | ||||||||||||||||||
680 | return false; never executed: return false; | 0 | ||||||||||||||||||
681 | priv->metaData = doc.object(); | - | ||||||||||||||||||
682 | return true; executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||||||||
683 | } | - | ||||||||||||||||||
684 | - | |||||||||||||||||||
685 | bool QLibraryPrivate::isPlugin() | - | ||||||||||||||||||
686 | { | - | ||||||||||||||||||
687 | if (pluginState == MightBeAPlugin)
| 66-1327 | ||||||||||||||||||
688 | updatePluginState(); executed 1327 times by 110 tests: updatePluginState(); Executed by:
| 1327 | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | return pluginState == IsAPlugin; executed 1393 times by 112 tests: return pluginState == IsAPlugin; Executed by:
| 1393 | ||||||||||||||||||
691 | } | - | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | void QLibraryPrivate::updatePluginState() | - | ||||||||||||||||||
694 | { | - | ||||||||||||||||||
695 | errorString.clear(); | - | ||||||||||||||||||
696 | if (pluginState != MightBeAPlugin)
| 2-1350 | ||||||||||||||||||
697 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | bool success = false; | - | ||||||||||||||||||
700 | - | |||||||||||||||||||
701 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) | - | ||||||||||||||||||
702 | if (fileName.endsWith(QLatin1String(".debug"))) {
| 0-1350 | ||||||||||||||||||
703 | // refuse to load a file that ends in .debug | - | ||||||||||||||||||
704 | // these are the debug symbols from the libraries | - | ||||||||||||||||||
705 | // the problem is that they are valid shared library files | - | ||||||||||||||||||
706 | // and dlopen is known to crash while opening them | - | ||||||||||||||||||
707 | - | |||||||||||||||||||
708 | // pretend we didn't see the file | - | ||||||||||||||||||
709 | errorString = QLibrary::tr("The shared library was not found."); | - | ||||||||||||||||||
710 | pluginState = IsNotAPlugin; | - | ||||||||||||||||||
711 | return; never executed: return; | 0 | ||||||||||||||||||
712 | } | - | ||||||||||||||||||
713 | #endif | - | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | if (!pHnd) {
| 4-1346 | ||||||||||||||||||
716 | // scan for the plugin metadata without loading | - | ||||||||||||||||||
717 | success = findPatternUnloaded(fileName, this); | - | ||||||||||||||||||
718 | } else { executed 1346 times by 112 tests: end of block Executed by:
| 1346 | ||||||||||||||||||
719 | // library is already loaded (probably via QLibrary) | - | ||||||||||||||||||
720 | // simply get the target function and call it. | - | ||||||||||||||||||
721 | QtPluginQueryVerificationDataFunction getMetaData = NULL; | - | ||||||||||||||||||
722 | getMetaData = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_metadata"); | - | ||||||||||||||||||
723 | success = qt_get_metadata(getMetaData, this); | - | ||||||||||||||||||
724 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | if (!success) {
| 653-697 | ||||||||||||||||||
727 | if (errorString.isEmpty()){
| 0-697 | ||||||||||||||||||
728 | if (fileName.isEmpty())
| 0 | ||||||||||||||||||
729 | errorString = QLibrary::tr("The shared library was not found."); never executed: errorString = QLibrary::tr("The shared library was not found."); | 0 | ||||||||||||||||||
730 | else | - | ||||||||||||||||||
731 | errorString = QLibrary::tr("The file '%1' is not a valid Qt plugin.").arg(fileName); never executed: errorString = QLibrary::tr("The file '%1' is not a valid Qt plugin.").arg(fileName); | 0 | ||||||||||||||||||
732 | } | - | ||||||||||||||||||
733 | pluginState = IsNotAPlugin; | - | ||||||||||||||||||
734 | return; executed 697 times by 111 tests: return; Executed by:
| 697 | ||||||||||||||||||
735 | } | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | pluginState = IsNotAPlugin; // be pessimistic | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | uint qt_version = (uint)metaData.value(QLatin1String("version")).toDouble(); | - | ||||||||||||||||||
740 | bool debug = metaData.value(QLatin1String("debug")).toBool(); | - | ||||||||||||||||||
741 | if ((qt_version & 0x00ff00) > (QT_VERSION & 0x00ff00) || (qt_version & 0xff0000) != (QT_VERSION & 0xff0000)) {
| 0-653 | ||||||||||||||||||
742 | if (qt_debug_component()) {
| 0 | ||||||||||||||||||
743 | qWarning("In %s:\n" | - | ||||||||||||||||||
744 | " Plugin uses incompatible Qt library (%d.%d.%d) [%s]", | - | ||||||||||||||||||
745 | (const char*) QFile::encodeName(fileName), | - | ||||||||||||||||||
746 | (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff, | - | ||||||||||||||||||
747 | debug ? "debug" : "release"); | - | ||||||||||||||||||
748 | } never executed: end of block | 0 | ||||||||||||||||||
749 | errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library. (%2.%3.%4) [%5]") | - | ||||||||||||||||||
750 | .arg(fileName) | - | ||||||||||||||||||
751 | .arg((qt_version&0xff0000) >> 16) | - | ||||||||||||||||||
752 | .arg((qt_version&0xff00) >> 8) | - | ||||||||||||||||||
753 | .arg(qt_version&0xff) | - | ||||||||||||||||||
754 | .arg(debug ? QLatin1String("debug") : QLatin1String("release")); | - | ||||||||||||||||||
755 | #ifndef QT_NO_DEBUG_PLUGIN_CHECK | - | ||||||||||||||||||
756 | } else if(debug != QLIBRARY_AS_DEBUG) { | - | ||||||||||||||||||
757 | //don't issue a qWarning since we will hopefully find a non-debug? --Sam | - | ||||||||||||||||||
758 | errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library." | - | ||||||||||||||||||
759 | " (Cannot mix debug and release libraries.)").arg(fileName); | - | ||||||||||||||||||
760 | #endif | - | ||||||||||||||||||
761 | } else { never executed: end of block | 0 | ||||||||||||||||||
762 | pluginState = IsAPlugin; | - | ||||||||||||||||||
763 | } executed 653 times by 110 tests: end of block Executed by:
| 653 | ||||||||||||||||||
764 | } | - | ||||||||||||||||||
765 | - | |||||||||||||||||||
766 | /*! | - | ||||||||||||||||||
767 | Loads the library and returns \c true if the library was loaded | - | ||||||||||||||||||
768 | successfully; otherwise returns \c false. Since resolve() always | - | ||||||||||||||||||
769 | calls this function before resolving any symbols it is not | - | ||||||||||||||||||
770 | necessary to call it explicitly. In some situations you might want | - | ||||||||||||||||||
771 | the library loaded in advance, in which case you would use this | - | ||||||||||||||||||
772 | function. | - | ||||||||||||||||||
773 | - | |||||||||||||||||||
774 | \sa unload() | - | ||||||||||||||||||
775 | */ | - | ||||||||||||||||||
776 | bool QLibrary::load() | - | ||||||||||||||||||
777 | { | - | ||||||||||||||||||
778 | if (!d)
| 1-132 | ||||||||||||||||||
779 | return false; executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
780 | if (did_load)
| 0-132 | ||||||||||||||||||
781 | return d->pHnd; never executed: return d->pHnd; | 0 | ||||||||||||||||||
782 | did_load = true; | - | ||||||||||||||||||
783 | return d->load(); executed 132 times by 46 tests: return d->load(); Executed by:
| 132 | ||||||||||||||||||
784 | } | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | /*! | - | ||||||||||||||||||
787 | Unloads the library and returns \c true if the library could be | - | ||||||||||||||||||
788 | unloaded; otherwise returns \c false. | - | ||||||||||||||||||
789 | - | |||||||||||||||||||
790 | This happens automatically on application termination, so you | - | ||||||||||||||||||
791 | shouldn't normally need to call this function. | - | ||||||||||||||||||
792 | - | |||||||||||||||||||
793 | If other instances of QLibrary are using the same library, the | - | ||||||||||||||||||
794 | call will fail, and unloading will only happen when every instance | - | ||||||||||||||||||
795 | has called unload(). | - | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | Note that on Mac OS X 10.3 (Panther), dynamic libraries cannot be unloaded. | - | ||||||||||||||||||
798 | - | |||||||||||||||||||
799 | \sa resolve(), load() | - | ||||||||||||||||||
800 | */ | - | ||||||||||||||||||
801 | bool QLibrary::unload() | - | ||||||||||||||||||
802 | { | - | ||||||||||||||||||
803 | if (did_load) {
| 1-26 | ||||||||||||||||||
804 | did_load = false; | - | ||||||||||||||||||
805 | return d->unload(); executed 26 times by 3 tests: return d->unload(); Executed by:
| 26 | ||||||||||||||||||
806 | } | - | ||||||||||||||||||
807 | return false; executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
808 | } | - | ||||||||||||||||||
809 | - | |||||||||||||||||||
810 | /*! | - | ||||||||||||||||||
811 | Returns \c true if the library is loaded; otherwise returns \c false. | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | \sa load() | - | ||||||||||||||||||
814 | */ | - | ||||||||||||||||||
815 | bool QLibrary::isLoaded() const | - | ||||||||||||||||||
816 | { | - | ||||||||||||||||||
817 | return d && d->pHnd; executed 12514 times by 46 tests: return d && d->pHnd; Executed by:
| 1-12514 | ||||||||||||||||||
818 | } | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | - | |||||||||||||||||||
821 | /*! | - | ||||||||||||||||||
822 | Constructs a library with the given \a parent. | - | ||||||||||||||||||
823 | */ | - | ||||||||||||||||||
824 | QLibrary::QLibrary(QObject *parent) | - | ||||||||||||||||||
825 | :QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
826 | { | - | ||||||||||||||||||
827 | } executed 68 times by 32 tests: end of block Executed by:
| 68 | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | - | |||||||||||||||||||
830 | /*! | - | ||||||||||||||||||
831 | Constructs a library object with the given \a parent that will | - | ||||||||||||||||||
832 | load the library specified by \a fileName. | - | ||||||||||||||||||
833 | - | |||||||||||||||||||
834 | We recommend omitting the file's suffix in \a fileName, since | - | ||||||||||||||||||
835 | QLibrary will automatically look for the file with the appropriate | - | ||||||||||||||||||
836 | suffix in accordance with the platform, e.g. ".so" on Unix, | - | ||||||||||||||||||
837 | ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) | - | ||||||||||||||||||
838 | */ | - | ||||||||||||||||||
839 | QLibrary::QLibrary(const QString& fileName, QObject *parent) | - | ||||||||||||||||||
840 | :QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
841 | { | - | ||||||||||||||||||
842 | setFileName(fileName); | - | ||||||||||||||||||
843 | } executed 38 times by 3 tests: end of block Executed by:
| 38 | ||||||||||||||||||
844 | - | |||||||||||||||||||
845 | - | |||||||||||||||||||
846 | /*! | - | ||||||||||||||||||
847 | Constructs a library object with the given \a parent that will | - | ||||||||||||||||||
848 | load the library specified by \a fileName and major version number \a verNum. | - | ||||||||||||||||||
849 | Currently, the version number is ignored on Windows. | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | We recommend omitting the file's suffix in \a fileName, since | - | ||||||||||||||||||
852 | QLibrary will automatically look for the file with the appropriate | - | ||||||||||||||||||
853 | suffix in accordance with the platform, e.g. ".so" on Unix, | - | ||||||||||||||||||
854 | ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) | - | ||||||||||||||||||
855 | */ | - | ||||||||||||||||||
856 | QLibrary::QLibrary(const QString& fileName, int verNum, QObject *parent) | - | ||||||||||||||||||
857 | :QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
858 | { | - | ||||||||||||||||||
859 | setFileNameAndVersion(fileName, verNum); | - | ||||||||||||||||||
860 | } executed 352 times by 14 tests: end of block Executed by:
| 352 | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | /*! | - | ||||||||||||||||||
863 | Constructs a library object with the given \a parent that will | - | ||||||||||||||||||
864 | load the library specified by \a fileName and full version number \a version. | - | ||||||||||||||||||
865 | Currently, the version number is ignored on Windows. | - | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | We recommend omitting the file's suffix in \a fileName, since | - | ||||||||||||||||||
868 | QLibrary will automatically look for the file with the appropriate | - | ||||||||||||||||||
869 | suffix in accordance with the platform, e.g. ".so" on Unix, | - | ||||||||||||||||||
870 | ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) | - | ||||||||||||||||||
871 | */ | - | ||||||||||||||||||
872 | QLibrary::QLibrary(const QString& fileName, const QString &version, QObject *parent) | - | ||||||||||||||||||
873 | :QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
874 | { | - | ||||||||||||||||||
875 | setFileNameAndVersion(fileName, version); | - | ||||||||||||||||||
876 | } never executed: end of block | 0 | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | /*! | - | ||||||||||||||||||
879 | Destroys the QLibrary object. | - | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | Unless unload() was called explicitly, the library stays in memory | - | ||||||||||||||||||
882 | until the application terminates. | - | ||||||||||||||||||
883 | - | |||||||||||||||||||
884 | \sa isLoaded(), unload() | - | ||||||||||||||||||
885 | */ | - | ||||||||||||||||||
886 | QLibrary::~QLibrary() | - | ||||||||||||||||||
887 | { | - | ||||||||||||||||||
888 | if (d)
| 4-454 | ||||||||||||||||||
889 | d->release(); executed 454 times by 46 tests: d->release(); Executed by:
| 454 | ||||||||||||||||||
890 | } executed 458 times by 46 tests: end of block Executed by:
| 458 | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | - | |||||||||||||||||||
893 | /*! | - | ||||||||||||||||||
894 | \property QLibrary::fileName | - | ||||||||||||||||||
895 | \brief the file name of the library | - | ||||||||||||||||||
896 | - | |||||||||||||||||||
897 | We recommend omitting the file's suffix in the file name, since | - | ||||||||||||||||||
898 | QLibrary will automatically look for the file with the appropriate | - | ||||||||||||||||||
899 | suffix (see isLibrary()). | - | ||||||||||||||||||
900 | - | |||||||||||||||||||
901 | When loading the library, QLibrary searches in all system-specific | - | ||||||||||||||||||
902 | library locations (for example, \c LD_LIBRARY_PATH on Unix), unless the | - | ||||||||||||||||||
903 | file name has an absolute path. After loading the library | - | ||||||||||||||||||
904 | successfully, fileName() returns the fully-qualified file name of | - | ||||||||||||||||||
905 | the library, including the full path to the library if one was given | - | ||||||||||||||||||
906 | in the constructor or passed to setFileName(). | - | ||||||||||||||||||
907 | - | |||||||||||||||||||
908 | For example, after successfully loading the "GL" library on Unix | - | ||||||||||||||||||
909 | platforms, fileName() will return "libGL.so". If the file name was | - | ||||||||||||||||||
910 | originally passed as "/usr/lib/libGL", fileName() will return | - | ||||||||||||||||||
911 | "/usr/lib/libGL.so". | - | ||||||||||||||||||
912 | */ | - | ||||||||||||||||||
913 | - | |||||||||||||||||||
914 | void QLibrary::setFileName(const QString &fileName) | - | ||||||||||||||||||
915 | { | - | ||||||||||||||||||
916 | QLibrary::LoadHints lh; | - | ||||||||||||||||||
917 | if (d) {
| 3-67 | ||||||||||||||||||
918 | lh = d->loadHints(); | - | ||||||||||||||||||
919 | d->release(); | - | ||||||||||||||||||
920 | d = 0; | - | ||||||||||||||||||
921 | did_load = false; | - | ||||||||||||||||||
922 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
923 | d = QLibraryPrivate::findOrCreate(fileName, QString(), lh); | - | ||||||||||||||||||
924 | } executed 70 times by 28 tests: end of block Executed by:
| 70 | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | QString QLibrary::fileName() const | - | ||||||||||||||||||
927 | { | - | ||||||||||||||||||
928 | if (d)
| 0-1 | ||||||||||||||||||
929 | return d->qualifiedFileName.isEmpty() ? d->fileName : d->qualifiedFileName; executed 1 time by 1 test: return d->qualifiedFileName.isEmpty() ? d->fileName : d->qualifiedFileName; Executed by:
| 0-1 | ||||||||||||||||||
930 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
931 | } | - | ||||||||||||||||||
932 | - | |||||||||||||||||||
933 | /*! | - | ||||||||||||||||||
934 | \fn void QLibrary::setFileNameAndVersion(const QString &fileName, int versionNumber) | - | ||||||||||||||||||
935 | - | |||||||||||||||||||
936 | Sets the fileName property and major version number to \a fileName | - | ||||||||||||||||||
937 | and \a versionNumber respectively. | - | ||||||||||||||||||
938 | The \a versionNumber is ignored on Windows. | - | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | \sa setFileName() | - | ||||||||||||||||||
941 | */ | - | ||||||||||||||||||
942 | void QLibrary::setFileNameAndVersion(const QString &fileName, int verNum) | - | ||||||||||||||||||
943 | { | - | ||||||||||||||||||
944 | QLibrary::LoadHints lh; | - | ||||||||||||||||||
945 | if (d) {
| 0-352 | ||||||||||||||||||
946 | lh = d->loadHints(); | - | ||||||||||||||||||
947 | d->release(); | - | ||||||||||||||||||
948 | d = 0; | - | ||||||||||||||||||
949 | did_load = false; | - | ||||||||||||||||||
950 | } never executed: end of block | 0 | ||||||||||||||||||
951 | d = QLibraryPrivate::findOrCreate(fileName, verNum >= 0 ? QString::number(verNum) : QString(), lh); | - | ||||||||||||||||||
952 | } executed 352 times by 14 tests: end of block Executed by:
| 352 | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | /*! | - | ||||||||||||||||||
955 | \since 4.4 | - | ||||||||||||||||||
956 | - | |||||||||||||||||||
957 | Sets the fileName property and full version number to \a fileName | - | ||||||||||||||||||
958 | and \a version respectively. | - | ||||||||||||||||||
959 | The \a version parameter is ignored on Windows. | - | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | \sa setFileName() | - | ||||||||||||||||||
962 | */ | - | ||||||||||||||||||
963 | void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &version) | - | ||||||||||||||||||
964 | { | - | ||||||||||||||||||
965 | QLibrary::LoadHints lh; | - | ||||||||||||||||||
966 | if (d) {
| 0-32 | ||||||||||||||||||
967 | lh = d->loadHints(); | - | ||||||||||||||||||
968 | d->release(); | - | ||||||||||||||||||
969 | d = 0; | - | ||||||||||||||||||
970 | did_load = false; | - | ||||||||||||||||||
971 | } never executed: end of block | 0 | ||||||||||||||||||
972 | d = QLibraryPrivate::findOrCreate(fileName, version, lh); | - | ||||||||||||||||||
973 | } executed 32 times by 16 tests: end of block Executed by:
| 32 | ||||||||||||||||||
974 | - | |||||||||||||||||||
975 | /*! | - | ||||||||||||||||||
976 | Returns the address of the exported symbol \a symbol. The library is | - | ||||||||||||||||||
977 | loaded if necessary. The function returns 0 if the symbol could | - | ||||||||||||||||||
978 | not be resolved or if the library could not be loaded. | - | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | Example: | - | ||||||||||||||||||
981 | \snippet code/src_corelib_plugin_qlibrary.cpp 2 | - | ||||||||||||||||||
982 | - | |||||||||||||||||||
983 | The symbol must be exported as a C function from the library. This | - | ||||||||||||||||||
984 | means that the function must be wrapped in an \c{extern "C"} if | - | ||||||||||||||||||
985 | the library is compiled with a C++ compiler. On Windows you must | - | ||||||||||||||||||
986 | also explicitly export the function from the DLL using the | - | ||||||||||||||||||
987 | \c{__declspec(dllexport)} compiler directive, for example: | - | ||||||||||||||||||
988 | - | |||||||||||||||||||
989 | \snippet code/src_corelib_plugin_qlibrary.cpp 3 | - | ||||||||||||||||||
990 | - | |||||||||||||||||||
991 | with \c MY_EXPORT defined as | - | ||||||||||||||||||
992 | - | |||||||||||||||||||
993 | \snippet code/src_corelib_plugin_qlibrary.cpp 4 | - | ||||||||||||||||||
994 | */ | - | ||||||||||||||||||
995 | QFunctionPointer QLibrary::resolve(const char *symbol) | - | ||||||||||||||||||
996 | { | - | ||||||||||||||||||
997 | if (!isLoaded() && !load())
| 1-12454 | ||||||||||||||||||
998 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
999 | return d->resolve(symbol); executed 12473 times by 46 tests: return d->resolve(symbol); Executed by:
| 12473 | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | /*! | - | ||||||||||||||||||
1003 | \overload | - | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | Loads the library \a fileName and returns the address of the | - | ||||||||||||||||||
1006 | exported symbol \a symbol. Note that \a fileName should not | - | ||||||||||||||||||
1007 | include the platform-specific file suffix; (see \l{fileName}). The | - | ||||||||||||||||||
1008 | library remains loaded until the application exits. | - | ||||||||||||||||||
1009 | - | |||||||||||||||||||
1010 | The function returns 0 if the symbol could not be resolved or if | - | ||||||||||||||||||
1011 | the library could not be loaded. | - | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | \sa resolve() | - | ||||||||||||||||||
1014 | */ | - | ||||||||||||||||||
1015 | QFunctionPointer QLibrary::resolve(const QString &fileName, const char *symbol) | - | ||||||||||||||||||
1016 | { | - | ||||||||||||||||||
1017 | QLibrary library(fileName); | - | ||||||||||||||||||
1018 | return library.resolve(symbol); never executed: return library.resolve(symbol); | 0 | ||||||||||||||||||
1019 | } | - | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | /*! | - | ||||||||||||||||||
1022 | \overload | - | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | Loads the library \a fileName with major version number \a verNum and | - | ||||||||||||||||||
1025 | returns the address of the exported symbol \a symbol. | - | ||||||||||||||||||
1026 | Note that \a fileName should not include the platform-specific file suffix; | - | ||||||||||||||||||
1027 | (see \l{fileName}). The library remains loaded until the application exits. | - | ||||||||||||||||||
1028 | \a verNum is ignored on Windows. | - | ||||||||||||||||||
1029 | - | |||||||||||||||||||
1030 | The function returns 0 if the symbol could not be resolved or if | - | ||||||||||||||||||
1031 | the library could not be loaded. | - | ||||||||||||||||||
1032 | - | |||||||||||||||||||
1033 | \sa resolve() | - | ||||||||||||||||||
1034 | */ | - | ||||||||||||||||||
1035 | QFunctionPointer QLibrary::resolve(const QString &fileName, int verNum, const char *symbol) | - | ||||||||||||||||||
1036 | { | - | ||||||||||||||||||
1037 | QLibrary library(fileName, verNum); | - | ||||||||||||||||||
1038 | return library.resolve(symbol); executed 216 times by 7 tests: return library.resolve(symbol); Executed by:
| 216 | ||||||||||||||||||
1039 | } | - | ||||||||||||||||||
1040 | - | |||||||||||||||||||
1041 | /*! | - | ||||||||||||||||||
1042 | \overload | - | ||||||||||||||||||
1043 | \since 4.4 | - | ||||||||||||||||||
1044 | - | |||||||||||||||||||
1045 | Loads the library \a fileName with full version number \a version and | - | ||||||||||||||||||
1046 | returns the address of the exported symbol \a symbol. | - | ||||||||||||||||||
1047 | Note that \a fileName should not include the platform-specific file suffix; | - | ||||||||||||||||||
1048 | (see \l{fileName}). The library remains loaded until the application exits. | - | ||||||||||||||||||
1049 | \a version is ignored on Windows. | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | The function returns 0 if the symbol could not be resolved or if | - | ||||||||||||||||||
1052 | the library could not be loaded. | - | ||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | \sa resolve() | - | ||||||||||||||||||
1055 | */ | - | ||||||||||||||||||
1056 | QFunctionPointer QLibrary::resolve(const QString &fileName, const QString &version, const char *symbol) | - | ||||||||||||||||||
1057 | { | - | ||||||||||||||||||
1058 | QLibrary library(fileName, version); | - | ||||||||||||||||||
1059 | return library.resolve(symbol); never executed: return library.resolve(symbol); | 0 | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | /*! | - | ||||||||||||||||||
1063 | \since 4.2 | - | ||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | Returns a text string with the description of the last error that occurred. | - | ||||||||||||||||||
1066 | Currently, errorString will only be set if load(), unload() or resolve() for some reason fails. | - | ||||||||||||||||||
1067 | */ | - | ||||||||||||||||||
1068 | QString QLibrary::errorString() const | - | ||||||||||||||||||
1069 | { | - | ||||||||||||||||||
1070 | return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; executed 21 times by 2 tests: return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; Executed by:
| 1-21 | ||||||||||||||||||
1071 | } | - | ||||||||||||||||||
1072 | - | |||||||||||||||||||
1073 | /*! | - | ||||||||||||||||||
1074 | \property QLibrary::loadHints | - | ||||||||||||||||||
1075 | \brief Give the load() function some hints on how it should behave. | - | ||||||||||||||||||
1076 | - | |||||||||||||||||||
1077 | You can give some hints on how the symbols are resolved. Usually, | - | ||||||||||||||||||
1078 | the symbols are not resolved at load time, but resolved lazily, | - | ||||||||||||||||||
1079 | (that is, when resolve() is called). If you set the loadHints to | - | ||||||||||||||||||
1080 | ResolveAllSymbolsHint, then all symbols will be resolved at load time | - | ||||||||||||||||||
1081 | if the platform supports it. | - | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | Setting ExportExternalSymbolsHint will make the external symbols in the | - | ||||||||||||||||||
1084 | library available for resolution in subsequent loaded libraries. | - | ||||||||||||||||||
1085 | - | |||||||||||||||||||
1086 | If LoadArchiveMemberHint is set, the file name | - | ||||||||||||||||||
1087 | is composed of two components: A path which is a reference to an | - | ||||||||||||||||||
1088 | archive file followed by the second component which is the reference to | - | ||||||||||||||||||
1089 | the archive member. For instance, the fileName \c libGL.a(shr_64.o) will refer | - | ||||||||||||||||||
1090 | to the library \c shr_64.o in the archive file named \c libGL.a. This | - | ||||||||||||||||||
1091 | is only supported on the AIX platform. | - | ||||||||||||||||||
1092 | - | |||||||||||||||||||
1093 | Setting PreventUnloadHint will only apply on Unix platforms. | - | ||||||||||||||||||
1094 | - | |||||||||||||||||||
1095 | The interpretation of the load hints is platform dependent, and if | - | ||||||||||||||||||
1096 | you use it you are probably making some assumptions on which platform | - | ||||||||||||||||||
1097 | you are compiling for, so use them only if you understand the consequences | - | ||||||||||||||||||
1098 | of them. | - | ||||||||||||||||||
1099 | - | |||||||||||||||||||
1100 | By default, none of these flags are set, so libraries will be loaded with | - | ||||||||||||||||||
1101 | lazy symbol resolution, and will not export external symbols for resolution | - | ||||||||||||||||||
1102 | in other dynamically-loaded libraries. | - | ||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | \note Setting this property after the library has been loaded has no effect | - | ||||||||||||||||||
1105 | and loadHints() will not reflect those changes. | - | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | \note This property is shared among all QLibrary instances that refer to | - | ||||||||||||||||||
1108 | the same library. | - | ||||||||||||||||||
1109 | */ | - | ||||||||||||||||||
1110 | void QLibrary::setLoadHints(LoadHints hints) | - | ||||||||||||||||||
1111 | { | - | ||||||||||||||||||
1112 | if (!d) {
| 3 | ||||||||||||||||||
1113 | d = QLibraryPrivate::findOrCreate(QString()); // ugly, but we need a d-ptr | - | ||||||||||||||||||
1114 | d->errorString.clear(); | - | ||||||||||||||||||
1115 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1116 | d->setLoadHints(hints); | - | ||||||||||||||||||
1117 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
1118 | - | |||||||||||||||||||
1119 | QLibrary::LoadHints QLibrary::loadHints() const | - | ||||||||||||||||||
1120 | { | - | ||||||||||||||||||
1121 | return d ? d->loadHints() : QLibrary::LoadHints(); executed 15 times by 1 test: return d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
| 6-15 | ||||||||||||||||||
1122 | } | - | ||||||||||||||||||
1123 | - | |||||||||||||||||||
1124 | /* Internal, for debugging */ | - | ||||||||||||||||||
1125 | bool qt_debug_component() | - | ||||||||||||||||||
1126 | { | - | ||||||||||||||||||
1127 | static int debug_env = QT_PREPEND_NAMESPACE(qEnvironmentVariableIntValue)("QT_DEBUG_PLUGINS"); | - | ||||||||||||||||||
1128 | return debug_env != 0; executed 6961 times by 413 tests: return debug_env != 0; Executed by:
| 6961 | ||||||||||||||||||
1129 | } | - | ||||||||||||||||||
1130 | - | |||||||||||||||||||
1131 | QT_END_NAMESPACE | - | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | #endif // QT_NO_LIBRARY | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |