Fix a crash on systems using musl as libc

Fixes #3395
This commit is contained in:
Kovid Goyal 2021-03-17 14:04:27 +05:30
parent 90722ecbe7
commit 37e3e29c8c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 32 additions and 9 deletions

View File

@ -97,6 +97,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Fix inactive tab closing causing active tab to change (:iss:`3398`)
- Fix a crash on systems using musl as libc (:iss:`3395`)
0.19.3 [2020-12-19]
-------------------

View File

@ -179,13 +179,12 @@ class Function:
)
def load(self) -> str:
ans = '*(void **) (&{name}_impl) = dlsym(handle, "{name}");'.format(
name=self.name
)
ans = f'*(void **) (&{self.name}_impl) = dlsym(handle, "{self.name}");'
ans += f'\n if ({self.name}_impl == NULL) '
if self.check_fail:
ans += '\n if ({name}_impl == NULL) fail("Failed to load glfw function {name} with error: %s", dlerror());'.format(
name=self.name
)
ans += f'fail("Failed to load glfw function {self.name} with error: %s", dlerror());'
else:
ans += 'dlerror(); // clear error indicator'
return ans

View File

@ -11,10 +11,12 @@
#define FUNC(name, restype, ...) typedef restype (*name##_func)(__VA_ARGS__); static name##_func name = NULL
#define LOAD_FUNC(handle, name) {\
*(void **) (&name) = dlsym(handle, #name); \
if (!name) { \
const char* error = dlerror(); \
if (error != NULL) { \
PyErr_Format(PyExc_OSError, "Failed to load the function %s with error: %s", #name, error); dlclose(handle); handle = NULL; return NULL; \
} \
} \
}
FUNC(sn_display_new, void*, void*, void*, void*);
@ -139,6 +141,7 @@ load_libcanberra(void) {
if (PyErr_Occurred()) {
PyErr_Print();
dlclose(libcanberra_handle); libcanberra_handle = NULL;
return;
}
if (ca_context_create(&canberra_ctx) != 0) {
fprintf(stderr, "Failed to create libcanberra context, cannot play beep sound\n");

19
kitty/glfw-wrapper.c generated
View File

@ -379,42 +379,61 @@ load_glfw(const char* path) {
if (glfwGetRequiredInstanceExtensions_impl == NULL) fail("Failed to load glfw function glfwGetRequiredInstanceExtensions with error: %s", dlerror());
*(void **) (&glfwGetCocoaWindow_impl) = dlsym(handle, "glfwGetCocoaWindow");
if (glfwGetCocoaWindow_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwHideCocoaTitlebar_impl) = dlsym(handle, "glfwHideCocoaTitlebar");
if (glfwHideCocoaTitlebar_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetNSGLContext_impl) = dlsym(handle, "glfwGetNSGLContext");
if (glfwGetNSGLContext_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetCocoaMonitor_impl) = dlsym(handle, "glfwGetCocoaMonitor");
if (glfwGetCocoaMonitor_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetCocoaTextInputFilter_impl) = dlsym(handle, "glfwSetCocoaTextInputFilter");
if (glfwSetCocoaTextInputFilter_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetCocoaFileOpenCallback_impl) = dlsym(handle, "glfwSetCocoaFileOpenCallback");
if (glfwSetCocoaFileOpenCallback_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetCocoaToggleFullscreenIntercept_impl) = dlsym(handle, "glfwSetCocoaToggleFullscreenIntercept");
if (glfwSetCocoaToggleFullscreenIntercept_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetApplicationShouldHandleReopen_impl) = dlsym(handle, "glfwSetApplicationShouldHandleReopen");
if (glfwSetApplicationShouldHandleReopen_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetApplicationWillFinishLaunching_impl) = dlsym(handle, "glfwSetApplicationWillFinishLaunching");
if (glfwSetApplicationWillFinishLaunching_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetCocoaKeyEquivalent_impl) = dlsym(handle, "glfwGetCocoaKeyEquivalent");
if (glfwGetCocoaKeyEquivalent_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwCocoaRequestRenderFrame_impl) = dlsym(handle, "glfwCocoaRequestRenderFrame");
if (glfwCocoaRequestRenderFrame_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetX11Display_impl) = dlsym(handle, "glfwGetX11Display");
if (glfwGetX11Display_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetX11Window_impl) = dlsym(handle, "glfwGetX11Window");
if (glfwGetX11Window_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwSetPrimarySelectionString_impl) = dlsym(handle, "glfwSetPrimarySelectionString");
if (glfwSetPrimarySelectionString_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetPrimarySelectionString_impl) = dlsym(handle, "glfwGetPrimarySelectionString");
if (glfwGetPrimarySelectionString_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwGetNativeKeyForName_impl) = dlsym(handle, "glfwGetNativeKeyForName");
if (glfwGetNativeKeyForName_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwRequestWaylandFrameEvent_impl) = dlsym(handle, "glfwRequestWaylandFrameEvent");
if (glfwRequestWaylandFrameEvent_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwDBusUserNotify_impl) = dlsym(handle, "glfwDBusUserNotify");
if (glfwDBusUserNotify_impl == NULL) dlerror(); // clear error indicator
*(void **) (&glfwDBusSetUserNotificationHandler_impl) = dlsym(handle, "glfwDBusSetUserNotificationHandler");
if (glfwDBusSetUserNotificationHandler_impl == NULL) dlerror(); // clear error indicator
return NULL;
}