diff options
| author | Neil <nyamatongwe@gmail.com> | 2019-12-13 12:09:32 +1100 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2019-12-13 12:09:32 +1100 |
| commit | 8eb134dbbd44002f3acd90d91550875f161136fa (patch) | |
| tree | f7384a0c7cd1c4cbc4f909afdba7a769b967d9b6 /cocoa/PlatCocoa.mm | |
| parent | c22da1b953a641c5f420d3d4ca9093a2f74d209a (diff) | |
| download | scintilla-mirror-8eb134dbbd44002f3acd90d91550875f161136fa.tar.gz | |
Backport: Implement DynamicLibrary on Cocoa.
Backport of changeset 7865:a5c2f8a3f171.
Diffstat (limited to 'cocoa/PlatCocoa.mm')
| -rw-r--r-- | cocoa/PlatCocoa.mm | 41 |
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)); } //-------------------------------------------------------------------------------------------------- |
