Kai Blin wrote:
> Hi folks,
> 
> Some folks in #opensuse-buildservice told me that Jan Matejek had a "porting 
> C 
> applications to use python 2.5" guide. Is it possible to post it to the list? 
> I figure I'm not the only one besides Jan who currently has a problem with 
> that.

I guess darix ment this mail? I hope Jan won't mind if I post it here.



-------- Original Message --------
Subject: [packagers] how to solve invalid free() in python apps and modules
Date: Wed, 01 Nov 2006 15:29:55 +0100
From: Jan Matejek <[EMAIL PROTECTED]>

thought i'd share a bit of wisdom on the $subject, it appears not to be
too uncommon.

Suppose you have an app that embeds/extends Python. Suppose it often
(quite reliably) aborts on "invalid free() or pointer corruption", maybe
 right on startup.
Now let's look at the backtrace. At the top you'll see abort(), few
in-library calls, free(), and (things get interesting in here)
Something_dealloc. Or PySomething_remove, _del, something like that.
(If there's something else, then your problem is probably not solved in
this mail. But you can try it as well.)

Open up your $EDITOR on that function. What you see is a deallocator,
also known as destructor. A function that gets called when Python object
is being recycled. It receives a pointer to that object, cleans up after
whatever processing was doing with it, and then it deallocates the
object itself.
The latter should be done by a call to PyObject_Del(self), or maybe in
some special cases self->ob_type->tp_free((PyObject*)self)
I bet my shoes on that in your case, there's PyMem_DEL(self) instead.

And that's it!
PyMem_DEL (or PyMem_Del) is basically a polite way of saying free() to
Python. Nothing less, nothing (much) more.
PyObject_Del, on the other hand, performs fancy things - talks to the
Python memory allocator about what has to be done, cleans up after
PyObject remnats of your custom type and whatnot. Same as free() vs.
delete, you can't mix the two of them.
So, just replace your PyMem_DEL with PyObject_Del, and voila, another
bug fixed.

thanks for your attention,
jan matejek
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to