Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/qpluginloader.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | QPluginLoader::QPluginLoader(QObject *parent) | - | ||||||||||||
5 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
8 | QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent) | - | ||||||||||||
9 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||
10 | { | - | ||||||||||||
11 | setFileName(fileName); | - | ||||||||||||
12 | setLoadHints(QLibrary::PreventUnloadHint); | - | ||||||||||||
13 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||
14 | QPluginLoader::~QPluginLoader() | - | ||||||||||||
15 | { | - | ||||||||||||
16 | if (d
| 1-27 | ||||||||||||
17 | d->release(); executed 27 times by 2 tests: d->release(); Executed by:
| 27 | ||||||||||||
18 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||
19 | QObject *QPluginLoader::instance() | - | ||||||||||||
20 | { | - | ||||||||||||
21 | if (!isLoaded()
| 1-16 | ||||||||||||
22 | return executed 4 times by 1 test: 0;return 0; Executed by:
executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||
23 | if (!d->inst
| 0-9 | ||||||||||||
24 | d->inst = d->instance(); executed 9 times by 2 tests: d->inst = d->instance(); Executed by:
| 9 | ||||||||||||
25 | return executed 17 times by 2 tests: d->inst.data();return d->inst.data(); Executed by:
executed 17 times by 2 tests: return d->inst.data(); Executed by:
| 17 | ||||||||||||
26 | } | - | ||||||||||||
27 | QJsonObject QPluginLoader::metaData() const | - | ||||||||||||
28 | { | - | ||||||||||||
29 | if (!d
| 0 | ||||||||||||
30 | return never executed: QJsonObject();return QJsonObject(); never executed: return QJsonObject(); | 0 | ||||||||||||
31 | return never executed: d->metaData;return d->metaData; never executed: return d->metaData; | 0 | ||||||||||||
32 | } | - | ||||||||||||
33 | bool QPluginLoader::load() | - | ||||||||||||
34 | { | - | ||||||||||||
35 | if (!d
| 2-27 | ||||||||||||
36 | return executed 6 times by 1 test: false;return false; Executed by:
executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||
37 | if (did_load
| 0-23 | ||||||||||||
38 | return never executed: d->pHnd && d->instance;return d->pHnd && d->instance; never executed: return d->pHnd && d->instance; | 0 | ||||||||||||
39 | if (!d->isPlugin()
| 11-12 | ||||||||||||
40 | return executed 12 times by 1 test: false;return false; Executed by:
executed 12 times by 1 test: return false; Executed by:
| 12 | ||||||||||||
41 | did_load = true; | - | ||||||||||||
42 | return executed 11 times by 2 tests: d->loadPlugin();return d->loadPlugin(); Executed by:
executed 11 times by 2 tests: return d->loadPlugin(); Executed by:
| 11 | ||||||||||||
43 | } | - | ||||||||||||
44 | bool QPluginLoader::unload() | - | ||||||||||||
45 | { | - | ||||||||||||
46 | if (did_load
| 4-9 | ||||||||||||
47 | did_load = false; | - | ||||||||||||
48 | return executed 9 times by 1 test: d->unload();return d->unload(); Executed by:
executed 9 times by 1 test: return d->unload(); Executed by:
| 9 | ||||||||||||
49 | } | - | ||||||||||||
50 | if (d
| 1-3 | ||||||||||||
51 | d->errorString = tr("The plugin was not loaded."); executed 3 times by 1 test: d->errorString = tr("The plugin was not loaded."); Executed by:
| 3 | ||||||||||||
52 | return executed 4 times by 1 test: false;return false; Executed by:
executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | - | |||||||||||||
56 | - | |||||||||||||
57 | - | |||||||||||||
58 | - | |||||||||||||
59 | - | |||||||||||||
60 | bool QPluginLoader::isLoaded() const | - | ||||||||||||
61 | { | - | ||||||||||||
62 | return executed 22 times by 2 tests: d && d->pHnd && d->instance;return d && d->pHnd && d->instance; Executed by:
executed 22 times by 2 tests: return d && d->pHnd && d->instance; Executed by:
| 22 | ||||||||||||
63 | } | - | ||||||||||||
64 | - | |||||||||||||
65 | - | |||||||||||||
66 | static QString locatePlugin(const QString& fileName) | - | ||||||||||||
67 | { | - | ||||||||||||
68 | const bool isAbsolute = QDir::isAbsolutePath(fileName); | - | ||||||||||||
69 | if (isAbsolute
| 3-24 | ||||||||||||
70 | QFileInfo fi(fileName); | - | ||||||||||||
71 | if (fi.isFile()
| 1-23 | ||||||||||||
72 | return executed 23 times by 2 tests: fi.canonicalFilePath();return fi.canonicalFilePath(); Executed by:
executed 23 times by 2 tests: return fi.canonicalFilePath(); Executed by:
| 23 | ||||||||||||
73 | } | - | ||||||||||||
74 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
75 | QStringList prefixes = QLibraryPrivate::prefixes_sys(); | - | ||||||||||||
76 | prefixes.prepend(QString()); | - | ||||||||||||
77 | QStringList suffixes = QLibraryPrivate::suffixes_sys(QString()); | - | ||||||||||||
78 | suffixes.prepend(QString()); | - | ||||||||||||
79 | - | |||||||||||||
80 | - | |||||||||||||
81 | const int slash = fileName.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||
82 | const QStringRef baseName = fileName.midRef(slash + 1); | - | ||||||||||||
83 | const QStringRef basePath = isAbsolute
| 1-3 | ||||||||||||
84 | - | |||||||||||||
85 | const bool debug = qt_debug_component(); | - | ||||||||||||
86 | - | |||||||||||||
87 | QStringList paths; | - | ||||||||||||
88 | if (isAbsolute
| 1-3 | ||||||||||||
89 | paths.append(fileName.left(slash)); | - | ||||||||||||
90 | } executed 1 time by 1 test: else {end of block Executed by:
| 1 | ||||||||||||
91 | paths = QCoreApplication::libraryPaths(); | - | ||||||||||||
92 | paths.prepend(([]() -> QString { enum { Size = sizeof(u"" ".")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "." }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 3 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 3 times by 1 test: }()));return qstring_literal_temp; Executed by:
| 3 | ||||||||||||
93 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
94 | - | |||||||||||||
95 | for (const QString &path : qAsConst(paths)) { | - | ||||||||||||
96 | for (const QString &prefix : qAsConst(prefixes)) { | - | ||||||||||||
97 | for (const QString &suffix : qAsConst(suffixes)) { | - | ||||||||||||
98 | const QString fn = path + QLatin1Char('/') + basePath + prefix + baseName + suffix; | - | ||||||||||||
99 | if (debug
| 0-36 | ||||||||||||
100 | QMessageLogger(__FILE__, 315, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; never executed: QMessageLogger(__FILE__, 315, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; | 0 | ||||||||||||
101 | if (QFileInfo(fn).isFile()
| 2-34 | ||||||||||||
102 | return executed 2 times by 1 test: fn;return fn; Executed by:
executed 2 times by 1 test: return fn; Executed by:
| 2 | ||||||||||||
103 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||
104 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
105 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
106 | if (debug
| 0-2 | ||||||||||||
107 | QMessageLogger(__FILE__, 322, __PRETTY_FUNCTION__).debug() << fileName << "not found"; never executed: QMessageLogger(__FILE__, 322, __PRETTY_FUNCTION__).debug() << fileName << "not found"; | 0 | ||||||||||||
108 | return executed 2 times by 1 test: QString();return QString(); Executed by:
executed 2 times by 1 test: return QString(); Executed by:
| 2 | ||||||||||||
109 | } | - | ||||||||||||
110 | void QPluginLoader::setFileName(const QString &fileName) | - | ||||||||||||
111 | { | - | ||||||||||||
112 | - | |||||||||||||
113 | QLibrary::LoadHints lh = QLibrary::PreventUnloadHint; | - | ||||||||||||
114 | if (d
| 1-26 | ||||||||||||
115 | lh = d->loadHints(); | - | ||||||||||||
116 | d->release(); | - | ||||||||||||
117 | d = 0; | - | ||||||||||||
118 | did_load = false; | - | ||||||||||||
119 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
120 | - | |||||||||||||
121 | const QString fn = locatePlugin(fileName); | - | ||||||||||||
122 | - | |||||||||||||
123 | d = QLibraryPrivate::findOrCreate(fn, QString(), lh); | - | ||||||||||||
124 | if (!fn.isEmpty()
| 2-25 | ||||||||||||
125 | d->updatePluginState(); executed 25 times by 2 tests: d->updatePluginState(); Executed by:
| 25 | ||||||||||||
126 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||
127 | - | |||||||||||||
128 | QString QPluginLoader::fileName() const | - | ||||||||||||
129 | { | - | ||||||||||||
130 | if (d
| 0 | ||||||||||||
131 | return never executed: d->fileName;return d->fileName; never executed: return d->fileName; | 0 | ||||||||||||
132 | return never executed: QString();return QString(); never executed: return QString(); | 0 | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | - | |||||||||||||
140 | QString QPluginLoader::errorString() const | - | ||||||||||||
141 | { | - | ||||||||||||
142 | return executed 26 times by 1 test: (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString;return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; Executed by:
executed 26 times by 1 test: return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; Executed by:
| 26 | ||||||||||||
143 | } | - | ||||||||||||
144 | void QPluginLoader::setLoadHints(QLibrary::LoadHints loadHints) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | if (!d
| 1-22 | ||||||||||||
147 | d = QLibraryPrivate::findOrCreate(QString()); | - | ||||||||||||
148 | d->errorString.clear(); | - | ||||||||||||
149 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
150 | d->setLoadHints(loadHints); | - | ||||||||||||
151 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||
152 | - | |||||||||||||
153 | QLibrary::LoadHints QPluginLoader::loadHints() const | - | ||||||||||||
154 | { | - | ||||||||||||
155 | return executed 2 times by 1 test: d ? d->loadHints() : QLibrary::LoadHints();return d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
executed 2 times by 1 test: return d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
| 2 | ||||||||||||
156 | } | - | ||||||||||||
157 | - | |||||||||||||
158 | - | |||||||||||||
159 | - | |||||||||||||
160 | typedef QVector<QStaticPlugin> StaticPluginList; | - | ||||||||||||
161 | namespace { namespace Q_QGS_staticPluginList { typedef StaticPluginList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 270 times by 244 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 270 times by 244 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 42699 times by 147 tests: &holder.value;return &holder.value; Executed by:
executed 42699 times by 147 tests: } } } static QGlobalStatic<StaticPluginList, Q_QGS_staticPluginList::innerFunction, Q_QGS_staticPluginList::guard> staticPluginList;return &holder.value; Executed by:
| 0-42699 | ||||||||||||
162 | void __attribute__((visibility("default"))) qRegisterStaticPluginFunction(QStaticPlugin plugin) | - | ||||||||||||
163 | { | - | ||||||||||||
164 | staticPluginList()->append(plugin); | - | ||||||||||||
165 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
166 | - | |||||||||||||
167 | - | |||||||||||||
168 | - | |||||||||||||
169 | - | |||||||||||||
170 | - | |||||||||||||
171 | - | |||||||||||||
172 | QObjectList QPluginLoader::staticInstances() | - | ||||||||||||
173 | { | - | ||||||||||||
174 | QObjectList instances; | - | ||||||||||||
175 | const StaticPluginList *plugins = staticPluginList(); | - | ||||||||||||
176 | if (plugins
| 0 | ||||||||||||
177 | const int numPlugins = plugins->size(); | - | ||||||||||||
178 | instances.reserve(numPlugins); | - | ||||||||||||
179 | for (int i = 0; i < numPlugins
| 0 | ||||||||||||
180 | instances += plugins->at(i).instance(); never executed: instances += plugins->at(i).instance(); | 0 | ||||||||||||
181 | } never executed: end of block | 0 | ||||||||||||
182 | return never executed: instances;return instances; never executed: return instances; | 0 | ||||||||||||
183 | } | - | ||||||||||||
184 | QVector<QStaticPlugin> QPluginLoader::staticPlugins() | - | ||||||||||||
185 | { | - | ||||||||||||
186 | StaticPluginList *plugins = staticPluginList(); | - | ||||||||||||
187 | if (plugins
| 0-42698 | ||||||||||||
188 | return executed 42698 times by 147 tests: *plugins;return *plugins; Executed by:
executed 42698 times by 147 tests: return *plugins; Executed by:
| 42698 | ||||||||||||
189 | return never executed: QVector<QStaticPlugin>();return QVector<QStaticPlugin>(); never executed: return QVector<QStaticPlugin>(); | 0 | ||||||||||||
190 | } | - | ||||||||||||
191 | - | |||||||||||||
192 | - | |||||||||||||
193 | - | |||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
196 | - | |||||||||||||
197 | QJsonObject QStaticPlugin::metaData() const | - | ||||||||||||
198 | { | - | ||||||||||||
199 | return executed 26 times by 1 test: qJsonFromRawLibraryMetaData(rawMetaData()).object();return qJsonFromRawLibraryMetaData(rawMetaData()).object(); Executed by:
executed 26 times by 1 test: return qJsonFromRawLibraryMetaData(rawMetaData()).object(); Executed by:
| 26 | ||||||||||||
200 | } | - | ||||||||||||
201 | - | |||||||||||||
202 | - | |||||||||||||
Switch to Source code | Preprocessed file |