[C++-sig] Defining Policies for unknown data handles

Nicodemus nicodemus at globalite.com.br
Sat Apr 5 20:22:21 CEST 2003


Lutz Paelike wrote:

> Hi all,


Hi Lutz,

> i'm starting with boost python and also tried the great pyste tool to
> make some python bindings.
>
> I have a question, which seems not too difficult for me, but i'm not
> sure which is the right way to go..
>
> I have a commercial application with an interface i like to use.
> There are a couple of structures and functions defined.
> Some of them use a pointer to a hidden structure returned by a
> initalizing function. I don't need to know anything about the struct ,
> i just pass it on to other functions to refer to the internal data.
>
> It's going like this:
>
> 1. Definition of  data handle:
>
> typedef struct _CapChannel *CapChannel;    /* Opaque pointer to a 
> channel*/
>
> 2. Get Handle
>
> CapChannel CapCreateChannel _PROTO((char *name, CapChannelUsage usage,
>                     int data_type));
> 3. Use Handle
>
> int    CapSetData _PROTO((CapChannel channel, void *data));
>
>
> You get the picture...
>
> So when i use pyste to generate the boost python interface code it gives
> a warning:
>
> ---> Error: CapCreateChannel returns a pointer or a reference, but no
> policy was specified.
>
> This makes perfect sense for me, as Pyste/Boost Python don't know how to
> deal with this reference.
> The question for me is now which is the right policy to use and how do
> i define this correctly?
> I don't need access to _CapChannel from Python. I just want to store the
> pointer. 


Just set the correct policy for CapCreateChannel:

f = Function('CapCreateChannel', ...)
set_policy(f, return_value_policy(return_opaque_pointer))

Note: pyste didn't support return_opaque_pointer until version 0.6.5, 
which I just commited to CVS.

Hope that helps,
Nicodemus.







More information about the Cplusplus-sig mailing list