[pypy-dev] Wrapping C, void pointer

Hart's Antler bhartsho at yahoo.com
Fri Aug 13 03:42:23 CEST 2010


I am wrapping PortAudio for RPython.  Following the source code in RSDL as a guide i can clearly see what to do with constants, structs, functions and so on.  So far so good until i reached something new in PortAudio i am not sure how to deal with, a void typedef and a void pointer.  In the RSDL example pointers were defined by Ptr = lltype.Ptr(lltype.ForwardReference()), then in the CConfig class the struct was defined and rffi_platform.configure parses, finally the Ptr is told TO become the type - given the output of platform.configure.  How do we deal with this situation from PortAudio?

# from portaudio.h
typedef void PaStream;
PaError Pa_OpenStream( PaStream** stream,
                       const PaStreamParameters *inputParameters,
                       const PaStreamParameters *outputParameters,
                       double sampleRate,
                       unsigned long framesPerBuffer,
                       PaStreamFlags streamFlags,
                       PaStreamCallback *streamCallback,
                       void *userData );

###############################
I have tried the following but it fails when i try to malloc the void pointer.

OpenDefaultStream = external(	'Pa_OpenDefaultStream', 
	[
		rffi.VOIDPP,	# PaStream** 
		rffi.INT, 		# numInputChannels
		rffi.INT, 		# numOutputChannels
		rffi.INT, 		# sampleFormat
		rffi.INT, 		# sampleRate
		rffi.INT, 		# framesPerBuffer
		rffi.INT,		#streamcallback
		rffi.VOIDP,		#userData
	],	
	rffi.INT
)
Stream = lltype.Void		#rffi.VOIDP
def test():
	print 'portaudio version %s' %GetVersion()
	assert Initialize() == 0		# paNoError = 0, error code is returned on init fail.

	stream = lltype.malloc(Stream, flavor='raw')
	try: ok = OpenDefaultStream( stream, 1, 1, Int16, 22050, FramesPerBufferUnspecified, 0 )
	finally: lltype.free(stream, flavor='raw')
	Terminate()


-brett






More information about the Pypy-dev mailing list