From: Marcelo M. <mm...@ac...> - 2005-11-22 16:49:33
|
Robert Jones wrote: > Hi All - can any of you generous souls give me a hint on this one? > > I am ultimately trying to call the windows function > > long WaitForMultipleObjects( > long nCount, > HANDLE *lpHandles, > int bWaitAll, > long dwMilliseconds > ); > > (Only the first two arguments matter for the moment). To provide > the HANDLEs I have a Python list. I know I have the list properly > populated because I have written this > > void writeHandle( HANDLE h ) { > printf( "HANDLE -> %0x\n", h ); > } > > which I have called with this Python code > > for obj in osWaitObjs: > writeHandle( obj ) > > and which prints out exactly the values I am expecting. > Now, to call the big function with my list I have written this > typemap > > %typemap ( in ) ( long nCount, HANDLE * lpHandles ) { > int i; > printf( "typemap (in)( long nCount, HANDLE * lpHandles )\n" ); > if ( ! PyList_Check( $input ) ) { > PyErr_SetString( PyExc_ValueError, "Expecting a list" ); > return NULL; > } > $1 = PyList_Size( $input ); > $2 = ( HANDLE * ) malloc( ( $1 + 1 ) * sizeof( HANDLE ) ); > printf( "List(" ); > for ( i = 0; i < $1; i ++ ) { > PyObject * obj = PyList_GetItem( $input, i ); > $2[ i ] = ( HANDLE ) PyInt_AsLong( obj ); > printf( "%0x, ", $2[ i ] ); > } > $2[ i ] = 0; > printf( ")\n" ); > } > > which includes lots of debugging printf's. Unfortunately the values > that result > from this conversion are not the values of the HANDLEs. HANDLE is > ultimately > defined as a void*. I'm pretty sure my typemap is not right, but I'm > not sure how. > > Cheers, Rob. If HANDLE is a void *, then you can't use PyInt_AsLong, you shoud try SWIG_ConvertPtr instead. See the void.swg file in Lib/typemaps (CVS version) for more details. Marcelo |