From ed44ee8e2c89d2969754bbe3d8f5642542e847b4 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Sat, 20 Sep 2014 17:39:03 +0900 Subject: [PATCH] Provide an informative error message if something goes wrong in setfont --- src/_macosx.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/_macosx.m b/src/_macosx.m index aa326ef02483..ac4ff6a9f424 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -2531,14 +2531,23 @@ static CGFloat _get_device_scale(CGContextRef cr) "CourierNewPS-Bold-ItalicMT"}, }; - if(!PyList_Check(family)) return 0; + if(!PyList_Check(family)) + { + PyErr_SetString(PyExc_ValueError, "family should be a list"); + return 0; + } n = PyList_GET_SIZE(family); for (i = 0; i < n; i++) { PyObject* item = PyList_GET_ITEM(family, i); ascii = PyUnicode_AsASCIIString(item); - if(!ascii) return 0; + if(!ascii) + { + PyErr_SetString(PyExc_ValueError, + "failed to convert font family name to ASCII"); + return 0; + } temp = PyBytes_AS_STRING(ascii); for (j = 0; j < NMAP; j++) { if (!strcmp(map[j].name, temp))