From 99ff92a5a77a5db96be46bc9f8918822a52638da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 Apr 2018 20:29:46 +0530 Subject: [PATCH] Don't fail to start if the user deletes the hintstyle key from their fontconfig configuration. Fixes #480 --- kitty/freetype.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kitty/freetype.c b/kitty/freetype.c index ce23b22b5..38337ddf5 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -214,15 +214,21 @@ ft_face_from_path_and_psname(PyObject* path, const char* psname, void *extra_dat PyObject* face_from_descriptor(PyObject *descriptor) { -#define D(key, conv) { PyObject *t = PyDict_GetItemString(descriptor, #key); if (t == NULL) { PyErr_SetString(PyExc_KeyError, "font descriptor is missing the key: " #key); return NULL; } key = conv(t); t = NULL; } +#define D(key, conv, missing_ok, defval) { \ + PyObject *t = PyDict_GetItemString(descriptor, #key); \ + if (t == NULL) { \ + if (!missing_ok) { PyErr_SetString(PyExc_KeyError, "font descriptor is missing the key: " #key); return NULL; } \ + else key = defval; \ + } else key = conv(t); \ +} char *path; long index; bool hinting; long hint_style; - D(path, PyUnicode_AsUTF8); - D(index, PyLong_AsLong); - D(hinting, PyObject_IsTrue); - D(hint_style, PyLong_AsLong); + D(path, PyUnicode_AsUTF8, false, ""); + D(index, PyLong_AsLong, true, 0); + D(hinting, PyObject_IsTrue, true, 1); + D(hint_style, PyLong_AsLong, true, 1); #undef D Face *self = (Face *)Face_Type.tp_alloc(&Face_Type, 0); if (self != NULL) {