summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/plugin-support.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-09-22 10:43:15 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-09-22 10:43:15 +0200
commite0322730ab08421113e5538c5202cfcb64b59ce6 (patch)
tree87834449ecfd304f7458553a630d16fbe1f74d4b /facetracknoir/plugin-support.cpp
parentb8009a72fa4aa9cee227e6323bf674b056dafbe8 (diff)
core: clean up dll logic
Diffstat (limited to 'facetracknoir/plugin-support.cpp')
-rw-r--r--facetracknoir/plugin-support.cpp69
1 files changed, 54 insertions, 15 deletions
diff --git a/facetracknoir/plugin-support.cpp b/facetracknoir/plugin-support.cpp
index 2e80c5e4..50b8ad1a 100644
--- a/facetracknoir/plugin-support.cpp
+++ b/facetracknoir/plugin-support.cpp
@@ -76,19 +76,44 @@ SelectedLibraries::SelectedLibraries(IDynamicLibraryProvider* mainApp) :
correct = true;
}
-DynamicLibrary::DynamicLibrary(const QString& filename)
+DynamicLibrary::DynamicLibrary(const QString& filename) :
+ handle(nullptr),
+ Dialog(nullptr),
+ Constructor(nullptr),
+ Metadata(nullptr)
{
this->filename = filename;
#if defined(_WIN32)
QString fullPath = QCoreApplication::applicationDirPath() + "/" + this->filename;
handle = new QLibrary(fullPath);
- qDebug() << handle->errorString();
+
+ struct _foo {
+ static bool die(QLibrary*& l, bool failp)
+ {
+ if (failp)
+ {
+ qDebug() << "failed" << l->errorString();
+ delete l;
+ l = nullptr;
+ }
+ return failp;
+ }
+ };
+
+ if (_foo::die(handle, !handle->load()))
+ return;
+
Dialog = (DIALOG_FUNPTR) handle->resolve(MAYBE_STDCALL_UNDERSCORE "GetDialog" CALLING_CONVENTION_SUFFIX_VOID_FUNCTION);
- qDebug() << handle->errorString();
+ if (_foo::die(handle, !Dialog))
+ return;
+
Constructor = (CTOR_FUNPTR) handle->resolve(MAYBE_STDCALL_UNDERSCORE "GetConstructor" CALLING_CONVENTION_SUFFIX_VOID_FUNCTION);
- qDebug() << handle->errorString();
+ if (_foo::die(handle, !Constructor))
+ return;
+
Metadata = (METADATA_FUNPTR) handle->resolve(MAYBE_STDCALL_UNDERSCORE "GetMetadata" CALLING_CONVENTION_SUFFIX_VOID_FUNCTION);
- qDebug() << handle->errorString();
+ if (_foo::die(handle, !Metadata))
+ return;
#else
QByteArray latin1 = QFile::encodeName(filename);
handle = dlopen(latin1.constData(), RTLD_NOW |
@@ -102,20 +127,34 @@ DynamicLibrary::DynamicLibrary(const QString& filename)
);
if (handle)
{
- fprintf(stderr, "Error, if any: %s\n", dlerror());
- fflush(stderr);
+ struct _foo {
+ static bool err(void*& handle)
+ {
+ const char* err = dlerror();
+ if (err)
+ {
+ fprintf(stderr, "Error, ignoring: %s\n", err);
+ fflush(stderr);
+ dlclose(handle);
+ handle = nullptr;
+ return true;
+ }
+ false;
+ }
+ };
+ if (_foo::err(handle))
+ return;
Dialog = (DIALOG_FUNPTR) dlsym(handle, "GetDialog");
- fprintf(stderr, "Error, if any: %s\n", dlerror());
- fflush(stderr);
+ if (_foo::err(handle))
+ return;
Constructor = (CTOR_FUNPTR) dlsym(handle, "GetConstructor");
- fprintf(stderr, "Error, if any: %s\n", dlerror());
- fflush(stderr);
+ if (_foo::err(handle))
+ return;
Metadata = (METADATA_FUNPTR) dlsym(handle, "GetMetadata");
- fprintf(stderr, "Error, if any: %s\n", dlerror());
- fflush(stderr);
+ if (_foo::err(handle))
+ return;
} else {
- fprintf(stderr, "Error, if any: %s\n", dlerror());
- fflush(stderr);
+ (void) _foo::err(handle);
}
#endif
}