Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24b24b7

Browse files
committed
Fix some recent reference counting bugs in ft2font.cpp (Thanks to Paul Kienzle).
svn path=/trunk/matplotlib/; revision=3790
1 parent d2e5a04 commit 24b24b7

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/ft2font.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ FT2Font::~FT2Font()
743743
{
744744
_VERBOSE("FT2Font::~FT2Font");
745745

746-
if(image)
747-
Py::_XDECREF(image);
746+
Py_XDECREF(image);
748747
FT_Done_Face ( face );
749748

750749
for (size_t i=0; i<glyphs.size(); i++) {
@@ -781,7 +780,7 @@ FT2Font::clear(const Py::Tuple & args) {
781780
_VERBOSE("FT2Font::clear");
782781
args.verify_length(0);
783782

784-
delete image;
783+
Py_XDECREF(image);
785784
image = NULL;
786785

787786
angle = 0.0;
@@ -1037,7 +1036,7 @@ FT2Font::get_glyph(const Py::Tuple & args){
10371036
if ( (size_t)num >= gms.size())
10381037
throw Py::ValueError("Glyph index out of range");
10391038

1040-
//todo: refcount?
1039+
Py_INCREF(gms[num]);
10411040
return Py::asObject(gms[num]);
10421041
}
10431042

@@ -1667,8 +1666,11 @@ char FT2Font::get_image__doc__ [] =
16671666
Py::Object
16681667
FT2Font::get_image (const Py::Tuple &args) {
16691668
args.verify_length(0);
1670-
Py_INCREF(image);
1671-
return Py::asObject(image);
1669+
if (image) {
1670+
Py_XINCREF(image);
1671+
return Py::asObject(image);
1672+
}
1673+
throw Py::RuntimeError("You must call .set_text() before .get_image()");
16721674
}
16731675

16741676
char FT2Font::attach_file__doc__ [] =

0 commit comments

Comments
 (0)