[C++-sig] Re: Defining Policies for unknown data handles
Nicodemus
nicodemus at globalite.com.br
Mon Apr 7 22:48:31 CEST 2003
Gottfried Ganßauge wrote:
>>I don't know, the generated code seems to be ok. Perhaps someone else
>>can help?
>>
>>
>There's something missing from the generated code: a call to the macro
>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
>This *must* be used to create a specialization for the type_id function.
>
>See the documentation for return_opaque_pointer.
>
>Here is an example:
>--- opaque.h ---------------><------------------------------------><---
>typedef struct opaque_ *opaque;
>
>extern opaque open_opaque();
>
>--- opaque.pyste -----------><------------------------------------><---
>f = Function('open_opaque', 'opaque.h')
>set_policy (f, return_value_policy (return_opaque_pointer))
>
>---- opaque.cpp-------------><------------------------------------><--
>// Includes
>====================================================================
>#include <boost/python.hpp>
>#include <opaque.h>
>
>// Using
>=======================================================================
>using namespace boost::python;
>
>/*****************************************************
> * THE FOLLOWING LINE SHOULD BE ADDED BY PYSTE
> */
>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
>
>// Module
>======================================================================
>BOOST_PYTHON_MODULE(opaque)
>{
> def("open_opaque", &open_opaque, return_value_policy<
>return_opaque_pointer >());
>}
>-----------------------------><------------------------------------><---
>
>Cheers,
>
>Gottfried
>
>
Yes, I forgot about the specialization, sorry 8/. Thanks Gottfried!
Here's the generated file:
// Includes
====================================================================
#include <boost/python.hpp>
#include <test.h>
// Using
=======================================================================
using namespace boost::python;
// Declarations
================================================================
namespace {
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
}// namespace
// Module
======================================================================
BOOST_PYTHON_MODULE(test)
{
def("open_opaque", &open_opaque, return_value_policy<
return_opaque_pointer >());
}
But this is producing compiler errors in my machine (Windows XP, Intel
6.0, STLport-4.5.3):
test.cpp
test.cpp(13): error: "type_info" is ambiguous
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
^
test.cpp(13): error: "type_id" is not a class or function template
name in the current scope
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
^
test.cpp(13): error: expected a ";"
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
... snip more 1452 lines of errors. 8P
I believe the code is correct, seems more like a problem with my setup.
Any ideas?
Regards,
Nicodemus.
More information about the Cplusplus-sig
mailing list