[Pyrex] staticforward

Bryan Weingarten bryan.weingarten at pobox.com
Thu Aug 21 15:31:57 CEST 2003


please,

i really need help solving this.  please don't give up on me yet.   here's
is the complete code of what i have now that is relevant to this problem.
when the status method is like i have in the example, it the c-extension
crashes. but if i have it as a nested or global function (see the #
comments) it works correctly.

thank you,

bryan

----


#!/usr/bin/python
import sys
import mpgedit

class MyPlay:
    def status(self, sec, msec):  # never gets called
        print sec, msec, self.data
        return 1

    def play(self, mp3file):
        # def status(sec, msec):  # this works
        #       print sec, msec, self.data
        #       return 1

        self.data = ('test', 2.0, {1:'one'})
        m = mpgedit.Play(mp3file)
        m.status_callback(self.status) #crashes the c-extension
        # m.status_callback(status) # this works
        while(m.play_frame()): pass

if __name__ == '__main__':
    m = MyPlay()
    m.play(sys.argv[1])

--------

cdef extern from "Python.h":
    void Py_INCREF(object)

cdef extern from "playif.h":
    int  mpgedit_play_init(char *)
    int  mpgedit_play_frame(int)
    void mpgedit_play_close(int)
    ctypedef int (*status)(void *, long, long) except 0
    void mpgedit_play_set_status_callback(int, status, void*)

class Play:
    def __init__(self, mp3file):
        self.ctx = mpgedit_play_init(mp3file)

    def __del__(self):
        mpgedit_play_close(self.ctx)

    def play_frame(self):
        return mpgedit_play_frame(self.ctx)

    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)







More information about the Pyrex mailing list