mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
Set the cocoa uncaught exception handler during glfw init not at module import time
This commit is contained in:
@@ -906,6 +906,17 @@ cocoa_system_beep(const char *path) {
|
|||||||
else NSBeep();
|
else NSBeep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
uncaughtExceptionHandler(NSException *exception) {
|
||||||
|
log_error("Unhandled exception in Cocoa: %s", [[exception description] UTF8String]);
|
||||||
|
log_error("Stack trace:\n%s", [[exception.callStackSymbols description] UTF8String]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cocoa_set_uncaught_exception_handler(void) {
|
||||||
|
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef module_methods[] = {
|
static PyMethodDef module_methods[] = {
|
||||||
{"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""},
|
{"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""},
|
||||||
{"cocoa_set_global_shortcut", (PyCFunction)cocoa_set_global_shortcut, METH_VARARGS, ""},
|
{"cocoa_set_global_shortcut", (PyCFunction)cocoa_set_global_shortcut, METH_VARARGS, ""},
|
||||||
@@ -915,17 +926,10 @@ static PyMethodDef module_methods[] = {
|
|||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
uncaughtExceptionHandler(NSException *exception) {
|
|
||||||
log_error("Unhandled exception in Cocoa: %s", [[exception description] UTF8String]);
|
|
||||||
log_error("Stack trace:\n%s", [[exception.callStackSymbols description] UTF8String]);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
init_cocoa(PyObject *module) {
|
init_cocoa(PyObject *module) {
|
||||||
memset(&global_shortcuts, 0, sizeof(global_shortcuts));
|
memset(&global_shortcuts, 0, sizeof(global_shortcuts));
|
||||||
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
|
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
|
||||||
register_at_exit_cleanup_func(COCOA_CLEANUP_FUNC, cleanup);
|
register_at_exit_cleanup_func(COCOA_CLEANUP_FUNC, cleanup);
|
||||||
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ extern void cocoa_set_titlebar_appearance(void *w, unsigned int theme);
|
|||||||
extern void cocoa_set_titlebar_color(void *w, color_type color);
|
extern void cocoa_set_titlebar_color(void *w, color_type color);
|
||||||
extern bool cocoa_alt_option_key_pressed(unsigned long);
|
extern bool cocoa_alt_option_key_pressed(unsigned long);
|
||||||
extern void cocoa_toggle_secure_keyboard_entry(void);
|
extern void cocoa_toggle_secure_keyboard_entry(void);
|
||||||
|
extern void cocoa_set_uncaught_exception_handler(void);
|
||||||
extern void cocoa_update_menu_bar_title(PyObject*);
|
extern void cocoa_update_menu_bar_title(PyObject*);
|
||||||
extern size_t cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz);
|
extern size_t cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz);
|
||||||
extern monotonic_t cocoa_cursor_blink_interval(void);
|
extern monotonic_t cocoa_cursor_blink_interval(void);
|
||||||
@@ -1037,6 +1038,9 @@ glfw_init(PyObject UNUSED *self, PyObject *args) {
|
|||||||
const char* path;
|
const char* path;
|
||||||
int debug_keyboard = 0, debug_rendering = 0;
|
int debug_keyboard = 0, debug_rendering = 0;
|
||||||
if (!PyArg_ParseTuple(args, "s|pp", &path, &debug_keyboard, &debug_rendering)) return NULL;
|
if (!PyArg_ParseTuple(args, "s|pp", &path, &debug_keyboard, &debug_rendering)) return NULL;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
cocoa_set_uncaught_exception_handler();
|
||||||
|
#endif
|
||||||
const char* err = load_glfw(path);
|
const char* err = load_glfw(path);
|
||||||
if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; }
|
if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; }
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|||||||
Reference in New Issue
Block a user