[C++-sig] Handle class and lifetime

Roman Yakovenko roman.yakovenko at gmail.com
Mon Jul 2 06:15:26 CEST 2007


On 6/30/07, Anders Wang Kristensen <awk at imm.dtu.dk> wrote:
> Hi,
>
> I'm a little confused by the call policies in boost python.
>
> I have something like the following situation:
>
> struct vertex
> {
>    graph* p;
>    int x;
> };
>
> struct graph
> {
>    vertex get_vertex(int i);
> };
>
> and in my python module:
>
> class_<graph> pyg("graph")
> pyg.def("get_vertex", &graph::get_vertex,
>    with_custodian_and_ward_postcall<0,1>());
>
> Is this the right way to make sure that graphs wont be destroyed while
> there are still vertices around which reference these graphs?

I think that you are right. You always can check yourself be testing
reference count sys.getrefcount

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



More information about the Cplusplus-sig mailing list