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 | 431daa97eb571282cdbc9c787098ad17f811e924 (patch) | |
tree | 65627c4c9bd08d9b322745b3c82d5c7ada041b73 | |
parent | 314bba00774e663ac6bf4c00e36393e2c191fbaf (diff) | |
download | scintilla-mirror-431daa97eb571282cdbc9c787098ad17f811e924.tar.gz |
Implement DynamicLibrary on Cocoa.
-rw-r--r-- | cocoa/PlatCocoa.mm | 52 | ||||
-rw-r--r-- | doc/ScintillaDoc.html | 7 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 11 | ||||
-rw-r--r-- | scripts/HeaderOrder.txt | 1 |
4 files changed, 61 insertions, 10 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index f33ca9d27..62d18273c 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -27,6 +27,7 @@ #include <memory> #include <numeric> +#include <dlfcn.h> #include <sys/time.h> #import <Foundation/NSGeometry.h> @@ -2132,14 +2133,51 @@ void Platform::Assert(const char *c, const char *file, int line) { //----------------- DynamicLibrary ----------------------------------------------------------------- /** - * Implements the platform specific part of library loading. - * - * @param modulePath The path to the module to load. - * @return A library instance or nullptr if the module could not be found or another problem occurred. + * Platform-specific module loading and access. + * Uses POSIX calls dlopen, dlsym, dlclose. */ -DynamicLibrary *DynamicLibrary::Load(const char * /* modulePath */) { - // Not implemented. - return nullptr; + +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. +* @return A library instance or nullptr if the module could not be found or another problem occurred. +*/ + +DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { + return static_cast<DynamicLibrary *>(new DynamicLibraryImpl(modulePath)); } //-------------------------------------------------------------------------------------------------- diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index d77536e5b..fa75790eb 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6857,9 +6857,10 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ styling and fold points for an unsupported language you can either do this in the container or better still, write your own lexer following the pattern of one of the existing ones.</p> - <p>Scintilla also supports external lexers. These are DLLs (on Windows) or .so modules (on GTK/Linux) that export three + <p>Scintilla also supports external lexers. These are DLLs (on Windows), .dylib modules (on macOS), + or .so modules (on GTK/Linux) that export three functions: <code>GetLexerCount</code>, <code>GetLexerName</code>, and - <code>GetLexerFactory</code>. See <code>externalLexer.cxx</code> for more.</p> + <code>GetLexerFactory</code>. See <code>ExternalLexer.cxx</code> for more information.</p> <a class="message" href="#SCI_SETLEXER">SCI_SETLEXER(int lexer)</a><br /> <a class="message" href="#SCI_GETLEXER">SCI_GETLEXER → int</a><br /> <a class="message" href="#SCI_SETLEXERLANGUAGE">SCI_SETLEXERLANGUAGE(<unused>, const char @@ -6922,7 +6923,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ <p><code>SCI_GETLEXERLANGUAGE</code> retrieves the name of the lexer.</p> <p><b id="SCI_LOADLEXERLIBRARY">SCI_LOADLEXERLIBRARY(<unused>, const char *path)</b><br /> - Load a lexer implemented in a shared library. This is a .so file on GTK/Linux or a .DLL file on Windows. + Load a lexer implemented in a shared library. This is a .so file on GTK/Linux, a .dylib file on macOS, or a .DLL file on Windows. </p> <p><b id="SCI_COLOURISE">SCI_COLOURISE(position start, position end)</b><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 27c6f70c7..9f729fb45 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -560,6 +560,17 @@ </li> </ul> <h3> + <a href="https://www.scintilla.org/scite430.zip">Release 4.3.0</a> + </h3> + <ul> + <li> + Released 11 December 2019. + </li> + <li> + SCI_LOADLEXERLIBRARY implemented on Cocoa. + </li> + </ul> + <h3> <a href="https://www.scintilla.org/scite423.zip">Release 4.2.3</a> </h3> <ul> diff --git a/scripts/HeaderOrder.txt b/scripts/HeaderOrder.txt index 73e20e7cb..63f9978d3 100644 --- a/scripts/HeaderOrder.txt +++ b/scripts/HeaderOrder.txt @@ -51,6 +51,7 @@ #include <sstream> // POSIX +#include <dlfcn.h> #include <sys/time.h> // GTK headers |