[PyKDE] How to pass structure as a parameter to function

Phil Thompson phil at riverbankcomputing.co.uk
Fri May 27 22:06:56 BST 2005


On Wednesday 25 May 2005 11:09 am, jim j wrote:
> hi,
>        i'm encountering a problem while passing a
> structure variable as a function parameter from
> python. We have already generated the corresponding
> wrapper code using SIP for my C library. In this
> function one of the parameter is a structure pointer.
> So python application has to pass a structure variable
> to the function wrapper. My funtion is this:
>
>        ///////////////////
> mymodule.h///////////////////////////////
>
> typedef struct _drvObject
> {
>     unsigned long   drvHandle;
>     TCHAR           msgQName[20];
>     unsigned long   msgQId;
>     unsigned long   protMsgQId;
>     unsigned long   respMsgQId;
> }DRVOBJECT, *P_DRVOBJECT;
>
>
>
>                     OpenDriver(P_DRVOBJECT pDrvObject,
> BOOL bSubscribeToDrvMsgs);
>
>
>
> My wrapper code looks like this:
>
>
> ///////////////////////////////////sipmymodulemodule.c/////////////////////
>///////////////////////////// `        static PyObject
> *func_OpenDriver(PyObject *,PyObject *sipArgs)
> {
>  int sipArgsParsed = 0;
>
>  {
>   struct _drvObject * a0;
>   int a1;
>
>   if
> (sipParseArgs(&sipArgsParsed,sipArgs,"vi",&a0,&a1))
>   {
>    APPDRV_STATUS sipRes;
>
>    sipRes = OpenDriver(a0,a1);
>
>    return
> sipConvertFromNamedEnum(sipRes,sipEnum_APP_STATUS);
>   }
>  }
>
>  /* Raise an exception if the arguments couldn't be
> parsed. */
>
> sipNoFunction(sipArgsParsed,sipNm_AppToDrvInterface_OpenDriver);
>
>  return NULL;
> }
>
>
> i'm importing my module in python and calling this
>
> function like below:
> >>>import Mymodule
> >>>Mymodule.OpenDriver(DRVOBJECT ,1)   /// Here i am
>
> facing problem, i don't know how to pass the address
> of structure variable to that library generated by sip
> tool
>
>
>
>
>
>                       hope somebody can help me in
> solving this problem

As you are not wrapping the DRVOBJECT structure, how are you creating the data 
structure?

sip.voidptr was originally intended as a way of passing void* between SIP 
generated modules. However, it should also be able to be used to get 
"external" void* into SIP generated modules.

In tonight's SIP snapshot I've tried to make sip.voidptr more usable. You can 
now create instances from Python. It takes a single parameter from which the 
value of the pointer is derived - it must be either None, an integer, a 
Python CObject, or another sip.voidptr instance. I've also added the 
ascobject() method which returns a Python CObject that wraps the pointer.

Phil




More information about the PyQt mailing list