[C++-sig] How to use BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID ?

Niall Douglas s_sourceforge at nedprod.com
Thu Sep 18 21:24:59 CEST 2008


On 18 Sep 2008 at 5:21, William Marié wrote:

> I would need to create an opaque boost python type, i had a look on the
> internet, here is what i found for instance to declare a void* opaque type :
> 
> struct void_ {};
> BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);

No, that's trickery from before my 2005 patch implementing native 
void * support.

> This works well if you have to call C++ function from Python but how do i do
> if i want to call a python function from C++ with a void* parameter :
> 
> ex :
> void* pFoo = 0x78985465;
> object callable = ....;
> callable( (void_*)pFoo );
> 
> I can't find out how to make this work properly i always have a runtime
> error :
> TypeError: No to_python (by-value) converter found for C++ type: struct
> void_ *

It just automatically works as an opaque pointer. Python cannot 
access the value, but can pass it into functions.

There should be an example in the regression suite.

Cheers,
Niall






More information about the Cplusplus-sig mailing list