Merge pull request #2788 from wiredfool/issue_2783

Fix for return without none set
This commit is contained in:
Hugo 2017-10-04 15:53:15 +03:00 committed by GitHub
commit 8a4a1e0338
3 changed files with 33 additions and 19 deletions

View File

@ -380,7 +380,6 @@ class TestImageDraw(PillowTestCase):
self.assert_image_equal(
im, Image.open("Tests/images/imagedraw_floodfill2.png"))
def test_floodfill_thresh(self):
# floodfill() is experimental
@ -560,6 +559,19 @@ class TestImageDraw(PillowTestCase):
# Assert
self.assert_image_similar(im, Image.open(expected), 1)
def test_textsize_empty_string(self):
# https://github.com/python-pillow/Pillow/issues/2783
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)
# Act
# Should not cause 'SystemError: <built-in method getsize of
# ImagingFont object at 0x...> returned NULL without setting an error'
draw.textsize("")
draw.textsize("\n")
draw.textsize("test\n")
if __name__ == '__main__':
unittest.main()

View File

@ -2212,7 +2212,6 @@ void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){
PyBytes_AsStringAndSize(encoded_string, &buffer, &len);
}
if (len) {
*text = calloc(len,1);
if (*text) {
memcpy(*text, buffer, len);
@ -2220,8 +2219,8 @@ void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){
if(bytes) {
Py_DECREF(bytes);
}
return;
}
#if PY_VERSION_HEX < 0x03000000
@ -2261,12 +2260,14 @@ _font_getmask(ImagingFontObject* self, PyObject* args)
_font_text_asBytes(encoded_string, &text);
if (!text) {
ImagingError_MemoryError();
return NULL;
}
im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize);
if (!im) {
free(text);
ImagingError_MemoryError();
return NULL;
}
@ -2298,7 +2299,7 @@ _font_getmask(ImagingFontObject* self, PyObject* args)
failed:
free(text);
ImagingDelete(im);
return NULL;
Py_RETURN_NONE;
}
static PyObject*
@ -2313,6 +2314,7 @@ _font_getsize(ImagingFontObject* self, PyObject* args)
_font_text_asBytes(encoded_string, &text);
if (!text) {
ImagingError_MemoryError();
return NULL;
}