RPython function callback from C

I have the PortAudio blocking API working, simple reading and writing to the sound card works. PortAudio also has an async API where samples are fed to a callback as they stream in. But i'm not sure how to define a RPython function that will be called as a callback from C, is this even possible? I see some references in the source of rffi that seems to suggest it is possible. Full source code is here http://pastebin.com/6YHbT7CU I'm passing the callback like this: def stream_callback( *args ): print 'stream callback' return 0 # 0=continue, 1=complete, 2=abort stream_callback_ptr = rffi.CCallback([], rffi.INT) OpenDefaultStream = rffi.llexternal( 'Pa_OpenDefaultStream', [ StreamRefPtr, # PaStream** rffi.INT, # numInputChannels rffi.INT, # numOutputChannels rffi.INT, # sampleFormat rffi.DOUBLE, # double sampleRate rffi.INT, # unsigned long framesPerBuffer #rffi.VOIDP, #PaStreamCallback *streamCallback stream_callback_ptr, rffi.VOIDP, #void *userData ], rffi.INT, # return compilation_info=eci, _callable=stream_callback ) entrypoint(): ... callback = lltype.nullptr( stream_callback_ptr.TO ) ok = OpenDefaultStream( streamptr, 2, 2, Int16, 22050.0, 512, callback, userdata )

Hi, Le 14 août 2010 03:51:00 UTC+2, Hart's Antler <bhartsho@yahoo.com> a écrit :
Yes this is possible. See an example in pypy/rpython/lltypesystem/test/test_ll2ctypes.py in the function test_qsort_callback(). Why are you passing _callable=stream_callback? It should be enough to pass stream_callback directly as a function argument. -- Amaury Forgeot d'Arc

Hi, Le 14 août 2010 03:51:00 UTC+2, Hart's Antler <bhartsho@yahoo.com> a écrit :
Yes this is possible. See an example in pypy/rpython/lltypesystem/test/test_ll2ctypes.py in the function test_qsort_callback(). Why are you passing _callable=stream_callback? It should be enough to pass stream_callback directly as a function argument. -- Amaury Forgeot d'Arc
participants (2)
-
Amaury Forgeot d'Arc
-
Hart's Antler