Harden Scintilla shim on macOS

ober

229984bb7eb20efc55b0cfb60030127df390c1b9

diff --git a/Makefile b/Makefile
index 40dfa30..2d44d7d 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ CC ?= cc
 UNAME_S := $(shell uname -s)
 ifeq ($(UNAME_S),Darwin)
   SHARED_FLAG  = -dynamiclib
-  SO_EXT       = .so
+  SO_EXT       = .dylib
   LD_VAR       = DYLD_LIBRARY_PATH
   WHOLE_ARCHIVE_OPEN  = -Wl,-force_load,
   WHOLE_ARCHIVE_CLOSE =
diff --git a/jerboa_scintilla_shim.c b/jerboa_scintilla_shim.c
index 52a7034..c6a5f88 100644
--- a/jerboa_scintilla_shim.c
+++ b/jerboa_scintilla_shim.c
@@ -168,10 +168,14 @@ long jerboa_scintilla_send_message_string(void *handle, unsigned int msg,
 
 /* Receive string: call msg twice (get length, then fill buffer) */
 #define RECV_BUF_SIZE 65536
-static char recv_buf[RECV_BUF_SIZE];
+static __thread char recv_buf[RECV_BUF_SIZE];
 
 const char *jerboa_scintilla_receive_string(void *handle, unsigned int msg,
                                           unsigned long wparam) {
+    if (!handle) {
+        recv_buf[0] = '\0';
+        return recv_buf;
+    }
     long len = (long)scintilla_send_message((Scintilla *)handle, msg,
                                             (uptr_t)wparam, (sptr_t)NULL);
     if (len <= 0) {
@@ -226,6 +230,7 @@ void jerboa_scintilla_move(void *handle, int x, int y) {
    Clipboard
    ================================================================ */
 const char *jerboa_scintilla_get_clipboard(void *handle) {
+    if (!handle) return "";
     int len = 0;
     char *buf = scintilla_get_clipboard((Scintilla *)handle, &len);
     if (!buf) return "";
@@ -243,7 +248,9 @@ const char *jerboa_scintilla_get_clipboard(void *handle) {
 #define SCI_SETILEXER_MSG 4033
 
 void jerboa_scintilla_set_lexer_language(void *handle, const char *lang) {
+    if (!handle || !lang) return;
     ILexer5 *lexer = CreateLexer(lang);
+    if (!lexer) return;
     scintilla_send_message((Scintilla *)handle, SCI_SETILEXER_MSG,
                            0, (sptr_t)lexer);
 }