On Wed, Sep 05, 2007 at 07:13:27AM -0400, Michael Droettboom wrote:
> Jouni K. Seppänen wrote:
> > Paul Kienzle <[EMAIL PROTECTED]> writes:
> > 
> > [segfaults]
> >> Is there something in the last couple of weeks which might cause this?
> > 
> > Some changes in font handling caused segfaults for me, and it turned out
> > to be a bug in an old version of freetype:
> > 
> > http://article.gmane.org/gmane.comp.python.matplotlib.general/10062
> > 
> > Try running python under gdb, or using strace/truss/ktrace to see what
> > is happening right before the segfault.
> 
> I'm not able to reproduce anything amiss on my Linux box.

I'm able to eliminate the problem by setting image=NULL after deleting it.

I did some mods to the refcount handling so that it consistently uses
XINC/XDEC for images and INC/DEC for glyphs.

I added in INCREF to get_glyph(); you don't seem to call it so it didn't 
show up as an error without.

See attached patch.   Let me know if I should post it to svn.

        - Paul

Index: src/ft2font.cpp
===================================================================
--- src/ft2font.cpp     (revision 3785)
+++ src/ft2font.cpp     (working copy)
@@ -743,8 +743,7 @@
 {
   _VERBOSE("FT2Font::~FT2Font");
 
-  if(image)
-    Py::_XDECREF(image);
+  Py_XDECREF(image);
   FT_Done_Face    ( face );
 
   for (size_t i=0; i<glyphs.size(); i++) {
@@ -781,7 +780,7 @@
   _VERBOSE("FT2Font::clear");
   args.verify_length(0);
 
-  delete image;
+  Py_XDECREF(image);
   image = NULL;
 
   angle = 0.0;
@@ -1038,6 +1037,7 @@
     throw Py::ValueError("Glyph index out of range");
 
   //todo: refcount?
+  Py_INCREF(gms[num]);
   return Py::asObject(gms[num]);
 }
 
@@ -1152,7 +1152,6 @@
   size_t height = (string_bbox.yMax-string_bbox.yMin) / 64 + 2;
 
   Py_XDECREF(image);
-  image = NULL;
   image = new FT2Image(width, height);
 
   for ( size_t n = 0; n < glyphs.size(); n++ )
@@ -1667,7 +1666,8 @@
 Py::Object
 FT2Font::get_image (const Py::Tuple &args) {
   args.verify_length(0);
-  Py_INCREF(image);
+  // TODO: what happens if image is NULL?
+  Py_XINCREF(image);
   return Py::asObject(image);
 }
 
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to