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 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | QPluginLoader::QPluginLoader(QObject *parent) | - | ||||||||||||||||||
7 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
8 | { | - | ||||||||||||||||||
9 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
10 | QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent) | - | ||||||||||||||||||
11 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
12 | { | - | ||||||||||||||||||
13 | setFileName(fileName); | - | ||||||||||||||||||
14 | setLoadHints(QLibrary::PreventUnloadHint); | - | ||||||||||||||||||
15 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||||||||
16 | QPluginLoader::~QPluginLoader() | - | ||||||||||||||||||
17 | { | - | ||||||||||||||||||
18 | if (d
| 1-27 | ||||||||||||||||||
19 | d->release(); executed 27 times by 2 tests: d->release(); Executed by:
| 27 | ||||||||||||||||||
20 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||
21 | QObject *QPluginLoader::instance() | - | ||||||||||||||||||
22 | { | - | ||||||||||||||||||
23 | if (!isLoaded()
| 1-16 | ||||||||||||||||||
24 | return executed 4 times by 1 test: 0;return 0; Executed by:
executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||||||||
25 | if (!d->inst
| 0-9 | ||||||||||||||||||
26 | d->inst = d->instance(); executed 9 times by 2 tests: d->inst = d->instance(); Executed by:
| 9 | ||||||||||||||||||
27 | 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 | ||||||||||||||||||
28 | } | - | ||||||||||||||||||
29 | QJsonObject QPluginLoader::metaData() const | - | ||||||||||||||||||
30 | { | - | ||||||||||||||||||
31 | if (!d
| 0 | ||||||||||||||||||
32 | return never executed: QJsonObject();return QJsonObject(); never executed: return QJsonObject(); | 0 | ||||||||||||||||||
33 | return never executed: d->metaData;return d->metaData; never executed: return d->metaData; | 0 | ||||||||||||||||||
34 | } | - | ||||||||||||||||||
35 | bool QPluginLoader::load() | - | ||||||||||||||||||
36 | { | - | ||||||||||||||||||
37 | if (!d
| 2-27 | ||||||||||||||||||
38 | return executed 6 times by 1 test: false;return false; Executed by:
executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||||||||
39 | if (did_load
| 0-23 | ||||||||||||||||||
40 | return never executed: d->pHndreturn d->pHnd && d->instance;
never executed: return d->pHnd && d->instance; | 0 | ||||||||||||||||||
41 | if (!d->isPlugin()
| 11-12 | ||||||||||||||||||
42 | return executed 12 times by 1 test: false;return false; Executed by:
executed 12 times by 1 test: return false; Executed by:
| 12 | ||||||||||||||||||
43 | did_load = true; | - | ||||||||||||||||||
44 | 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 | ||||||||||||||||||
45 | } | - | ||||||||||||||||||
46 | bool QPluginLoader::unload() | - | ||||||||||||||||||
47 | { | - | ||||||||||||||||||
48 | if (did_load
| 4-9 | ||||||||||||||||||
49 | did_load = false; | - | ||||||||||||||||||
50 | 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 | ||||||||||||||||||
51 | } | - | ||||||||||||||||||
52 | if (d
| 1-3 | ||||||||||||||||||
53 | 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 | ||||||||||||||||||
54 | return executed 4 times by 1 test: false;return false; Executed by:
executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||
55 | } | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | - | |||||||||||||||||||
60 | - | |||||||||||||||||||
61 | - | |||||||||||||||||||
62 | bool QPluginLoader::isLoaded() const | - | ||||||||||||||||||
63 | { | - | ||||||||||||||||||
64 | return executed 22 times by 2 tests: dreturn d && d->pHnd && d->instance; Executed by:
executed 22 times by 2 tests: return d && d->pHnd && d->instance; Executed by:
| 0-22 | ||||||||||||||||||
65 | } | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | static QString locatePlugin(const QString& fileName) | - | ||||||||||||||||||
69 | { | - | ||||||||||||||||||
70 | const bool isAbsolute = QDir::isAbsolutePath(fileName); | - | ||||||||||||||||||
71 | if (isAbsolute
| 3-24 | ||||||||||||||||||
72 | QFileInfo fi(fileName); | - | ||||||||||||||||||
73 | if (fi.isFile()
| 1-23 | ||||||||||||||||||
74 | 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 | ||||||||||||||||||
75 | } | - | ||||||||||||||||||
76 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
77 | QStringList prefixes = QLibraryPrivate::prefixes_sys(); | - | ||||||||||||||||||
78 | prefixes.prepend(QString()); | - | ||||||||||||||||||
79 | QStringList suffixes = QLibraryPrivate::suffixes_sys(QString()); | - | ||||||||||||||||||
80 | suffixes.prepend(QString()); | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | - | |||||||||||||||||||
83 | const int slash = fileName.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
84 | const QStringRef baseName = fileName.midRef(slash + 1); | - | ||||||||||||||||||
85 | const QStringRef basePath = isAbsolute
| 1-3 | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | const bool debug = qt_debug_component(); | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | QStringList paths; | - | ||||||||||||||||||
90 | if (isAbsolute
| 1-3 | ||||||||||||||||||
91 | paths.append(fileName.left(slash)); | - | ||||||||||||||||||
92 | } executed 1 time by 1 test: else {end of block Executed by:
| 1 | ||||||||||||||||||
93 | paths = QCoreApplication::libraryPaths(); | - | ||||||||||||||||||
94 | 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 | ||||||||||||||||||
95 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(paths)>::type> _container_((paths)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &path = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
98 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(prefixes)>::type> _container_((prefixes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &prefix = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
99 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(suffixes)>::type> _container_((suffixes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &suffix = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
100 | const QString fn = path + QLatin1Char('/') + basePath + prefix + baseName + suffix; | - | ||||||||||||||||||
101 | if (debug
| 0-36 | ||||||||||||||||||
102 | QMessageLogger(__FILE__, 309, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; never executed: QMessageLogger(__FILE__, 309, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; | 0 | ||||||||||||||||||
103 | if (QFileInfo(fn).isFile()
| 2-34 | ||||||||||||||||||
104 | return executed 2 times by 1 test: fn;return fn; Executed by:
executed 2 times by 1 test: return fn; Executed by:
| 2 | ||||||||||||||||||
105 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
106 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
107 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
108 | if (debug
| 0-2 | ||||||||||||||||||
109 | QMessageLogger(__FILE__, 316, __PRETTY_FUNCTION__).debug() << fileName << "not found"; never executed: QMessageLogger(__FILE__, 316, __PRETTY_FUNCTION__).debug() << fileName << "not found"; | 0 | ||||||||||||||||||
110 | return executed 2 times by 1 test: QString();return QString(); Executed by:
executed 2 times by 1 test: return QString(); Executed by:
| 2 | ||||||||||||||||||
111 | } | - | ||||||||||||||||||
112 | void QPluginLoader::setFileName(const QString &fileName) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | QLibrary::LoadHints lh = QLibrary::PreventUnloadHint; | - | ||||||||||||||||||
116 | if (d
| 1-26 | ||||||||||||||||||
117 | lh = d->loadHints(); | - | ||||||||||||||||||
118 | d->release(); | - | ||||||||||||||||||
119 | d = 0; | - | ||||||||||||||||||
120 | did_load = false; | - | ||||||||||||||||||
121 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | const QString fn = locatePlugin(fileName); | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | d = QLibraryPrivate::findOrCreate(fn, QString(), lh); | - | ||||||||||||||||||
126 | if (!fn.isEmpty()
| 2-25 | ||||||||||||||||||
127 | d->updatePluginState(); executed 25 times by 2 tests: d->updatePluginState(); Executed by:
| 25 | ||||||||||||||||||
128 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | QString QPluginLoader::fileName() const | - | ||||||||||||||||||
131 | { | - | ||||||||||||||||||
132 | if (d
| 0 | ||||||||||||||||||
133 | return never executed: d->fileName;return d->fileName; never executed: return d->fileName; | 0 | ||||||||||||||||||
134 | return never executed: QString();return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
135 | } | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | - | |||||||||||||||||||
138 | - | |||||||||||||||||||
139 | - | |||||||||||||||||||
140 | - | |||||||||||||||||||
141 | - | |||||||||||||||||||
142 | QString QPluginLoader::errorString() const | - | ||||||||||||||||||
143 | { | - | ||||||||||||||||||
144 | return executed 26 times by 1 test: (!dreturn (!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:
| 3-26 | ||||||||||||||||||
145 | } | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | typedef QVector<QStaticPlugin> StaticPluginList; | - | ||||||||||||||||||
148 | 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 267 times by 245 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 267 times by 245 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 40167 times by 146 tests: &holder.value;return &holder.value; Executed by:
executed 40167 times by 146 tests: } } } static QGlobalStatic<StaticPluginList, Q_QGS_staticPluginList::innerFunction, Q_QGS_staticPluginList::guard> staticPluginList;return &holder.value; Executed by:
| 0-40167 | ||||||||||||||||||
149 | void QPluginLoader::setLoadHints(QLibrary::LoadHints loadHints) | - | ||||||||||||||||||
150 | { | - | ||||||||||||||||||
151 | if (!d
| 1-22 | ||||||||||||||||||
152 | d = QLibraryPrivate::findOrCreate(QString()); | - | ||||||||||||||||||
153 | d->errorString.clear(); | - | ||||||||||||||||||
154 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
155 | d->setLoadHints(loadHints); | - | ||||||||||||||||||
156 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | QLibrary::LoadHints QPluginLoader::loadHints() const | - | ||||||||||||||||||
159 | { | - | ||||||||||||||||||
160 | return executed 2 times by 1 test: dreturn d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
executed 2 times by 1 test: return d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
| 1-2 | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
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-40166 | ||||||||||||||||||
188 | return executed 40166 times by 146 tests: *plugins;return *plugins; Executed by:
executed 40166 times by 146 tests: return *plugins; Executed by:
| 40166 | ||||||||||||||||||
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: QLibraryPrivate::fromRawMetaData(rawMetaData()).object();return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); Executed by:
executed 26 times by 1 test: return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); Executed by:
| 26 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |