mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-05 06:00:58 +03:00
Merge pull request #2788 from wiredfool/issue_2783
Fix for return without none set
This commit is contained in:
commit
8a4a1e0338
|
@ -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()
|
||||
|
|
22
_imaging.c
22
_imaging.c
|
@ -2212,16 +2212,15 @@ 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);
|
||||
}
|
||||
if(bytes) {
|
||||
Py_DECREF(bytes);
|
||||
}
|
||||
return;
|
||||
*text = calloc(len,1);
|
||||
if (*text) {
|
||||
memcpy(*text, buffer, len);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
16
_imagingft.c
16
_imagingft.c
|
@ -225,11 +225,11 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
|
|||
if (PyUnicode_Check(string)) {
|
||||
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
|
||||
Py_ssize_t size = PyUnicode_GET_SIZE(string);
|
||||
if (! size) {
|
||||
/* return 0 and clean up, no glyphs==no size,
|
||||
and raqm fails with empty strings */
|
||||
goto failed;
|
||||
}
|
||||
if (! size) {
|
||||
/* return 0 and clean up, no glyphs==no size,
|
||||
and raqm fails with empty strings */
|
||||
goto failed;
|
||||
}
|
||||
if (!raqm_set_text(rq, (const uint32_t *)(text), size)) {
|
||||
PyErr_SetString(PyExc_ValueError, "raqm_set_text() failed");
|
||||
goto failed;
|
||||
|
@ -239,9 +239,9 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
|
|||
else if (PyString_Check(string)) {
|
||||
char *text = PyString_AS_STRING(string);
|
||||
int size = PyString_GET_SIZE(string);
|
||||
if (! size) {
|
||||
goto failed;
|
||||
}
|
||||
if (! size) {
|
||||
goto failed;
|
||||
}
|
||||
if (!raqm_set_text_utf8(rq, text, size)) {
|
||||
PyErr_SetString(PyExc_ValueError, "raqm_set_text_utf8() failed");
|
||||
goto failed;
|
||||
|
|
Loading…
Reference in New Issue
Block a user