From 8eb134dbbd44002f3acd90d91550875f161136fa Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 13 Dec 2019 12:09:32 +1100 Subject: Backport: Implement DynamicLibrary on Cocoa. Backport of changeset 7865:a5c2f8a3f171. --- cocoa/PlatCocoa.mm | 41 +++++++++++++++++++++++++++++++++++++++-- doc/ScintillaDoc.html | 7 ++++--- doc/ScintillaHistory.html | 11 +++++++++++ scripts/HeaderOrder.txt | 1 + 4 files changed, 55 insertions(+), 5 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 #include +#include #include #import @@ -2096,6 +2097,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. * @@ -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(new DynamicLibraryImpl(modulePath)); } //-------------------------------------------------------------------------------------------------- diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 3efb7257f..fa247b35e 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6830,9 +6830,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.

-

Scintilla also supports external lexers. These are DLLs (on Windows) or .so modules (on GTK/Linux) that export three +

Scintilla also supports external lexers. These are DLLs (on Windows), .dylib modules (on macOS), + or .so modules (on GTK/Linux) that export three functions: GetLexerCount, GetLexerName, and - GetLexerFactory. See externalLexer.cxx for more.

+ GetLexerFactory. See ExternalLexer.cxx for more information.

SCI_SETLEXER(int lexer)
SCI_GETLEXER → int
SCI_SETLEXERLANGUAGE(<unused>, const char @@ -6895,7 +6896,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){

SCI_GETLEXERLANGUAGE retrieves the name of the lexer.

SCI_LOADLEXERLIBRARY(<unused>, const char *path)
- 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.

SCI_COLOURISE(position start, position end)
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index d3e2094c5..ea72b9ecb 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -553,6 +553,17 @@ Icons
Copyright(C) 1998 by Dean S. Jones
+

+ Release 3.12.0 +

+
    +
  • + Released 07 December 2019. +
  • +
  • + SCI_LOADLEXERLIBRARY implemented on Cocoa. +
  • +

Release 3.11.2

diff --git a/scripts/HeaderOrder.txt b/scripts/HeaderOrder.txt index 6f749579e..2242558ec 100644 --- a/scripts/HeaderOrder.txt +++ b/scripts/HeaderOrder.txt @@ -50,6 +50,7 @@ #include // POSIX +#include #include // GTK headers -- cgit v1.2.3