[Pyrex] callback working, but memory leak?
Bryan Weingarten
bryan.weingarten at pobox.com
Sat Aug 23 07:54:27 CEST 2003
i finally got my program working. i debugged the generated pyrex c code and
i saw that incrementing and decrementing wasn't in sync, just as you all
suggested. i had added the Py_INCREF in the wrong place before. so now in
the pyrex c code, the status_callback does 2 INCS and 1 DEC which prevents
the callback from being garbage collected, and the callback_wrapper does 1
INC and 1 DEC. i suppose this means that everytime status_callback is
called, there will be a memory leak, right? should i save the callback and
do two DECS in __del__? is this really not a problem and i should ignore
this?
bryan
--- pyrex
class Play:
def status_callback(self, callback):
Py_INCREF(callback)
mpgedit_play_set_status_callback(self.ctx, _callback_wrapper,
<void*>callback)
cdef int _callback_wrapper(void *callback, long sec, long msec) except 0:
return (<object>callback)(sec, msec)
--- this python code now works
class MyPlay:
def status(self, sec, msec):
print sec, msec, self.data
return 1
def play(self, mp3file):
self.data = ['test']
m = mpgedit.Play(mp3file)
m.status_callback(self.status)
while(m.play_frame()): pass
if __name__ == '__main__':
m = MyPlay()
m.play(sys.argv[1])
More information about the Pyrex
mailing list