aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/PlatCocoa.mm
diff options
context:
space:
mode:
Diffstat (limited to 'cocoa/PlatCocoa.mm')
-rw-r--r--cocoa/PlatCocoa.mm41
1 files changed, 39 insertions, 2 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 52e5399a9..8f49d5eed 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -24,6 +24,7 @@
#include <map>
#include <memory>
+#include <dlfcn.h>
#include <sys/time.h>
#import <Foundation/NSGeometry.h>
@@ -2097,6 +2098,43 @@ void Platform::Assert(const char *c, const char *file, int line)
//----------------- DynamicLibrary -----------------------------------------------------------------
/**
+ * Platform-specific module loading and access.
+ * Uses POSIX calls dlopen, dlsym, dlclose.
+ */
+
+class DynamicLibraryImpl : public DynamicLibrary {
+protected:
+ void *m;
+public:
+ explicit DynamicLibraryImpl(const char *modulePath) noexcept {
+ m = dlopen(modulePath, RTLD_LAZY);
+ }
+ // Deleted so DynamicLibraryImpl objects can not be copied.
+ DynamicLibraryImpl(const DynamicLibraryImpl&) = delete;
+ DynamicLibraryImpl(DynamicLibraryImpl&&) = delete;
+ DynamicLibraryImpl&operator=(const DynamicLibraryImpl&) = delete;
+ DynamicLibraryImpl&operator=(DynamicLibraryImpl&&) = delete;
+
+ ~DynamicLibraryImpl() override {
+ if (m)
+ dlclose(m);
+ }
+
+ // Use dlsym to get a pointer to the relevant function.
+ Function FindFunction(const char *name) override {
+ if (m) {
+ return dlsym(m, name);
+ } else {
+ return nullptr;
+ }
+ }
+
+ bool IsValid() override {
+ return m != nullptr;
+ }
+};
+
+/**
* Implements the platform specific part of library loading.
*
* @param modulePath The path to the module to load.
@@ -2104,8 +2142,7 @@ void Platform::Assert(const char *c, const char *file, int line)
*/
DynamicLibrary* DynamicLibrary::Load(const char* /* modulePath */)
{
- // Not implemented.
- return nullptr;
+ return static_cast<DynamicLibrary *>(new DynamicLibraryImpl(modulePath));
}
//--------------------------------------------------------------------------------------------------