[C++-sig] Py++ - problem with split_module and return_opaque_pointer-policy

Roman Yakovenko roman.yakovenko at gmail.com
Tue Sep 12 13:14:35 CEST 2006


On 9/12/06, Ganssauge, Gottfried <Gottfried.Ganssauge at haufe.de> wrote:
> The return_value_policy<return_opaque_pointer> requires
> an additional macro call (BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID)
> in the declaration section of a module.
> This can be added e.g. using module_builder_t.add_declaration_code(),
> and it works as long as you're generating the code using write_module().
>
> In the moment you're using "split_module" to split your output, this
> scheme breaks,
> because BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID is required in every
> translation
> unit using the opaque pointer type whose type_id is defined with that
> macro.
> Instead it is only generated into the main module.
>

Does "every translation unit" means "in every cpp file" ?
If not the quick work-around I can propose is to put this macro in
some header file
and to include it.

The solution to your problem requires small refactoring in Py++. I
will do that before next
release, but it will take some time.
The solution will be to add "add_declaration_code" to free function:

mb = module_builder.module_builder_t( ["test.hpp"] )

get_opaque = mb.free_function (name = "get_opaque")

get_opaque.add_declaration_code("BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)")
get_opaque.call_policies = return_value_policy (return_opaque_pointer)

What do you think?

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list