Consider this Python expression:

  x = a.b.c

If a and b are expressions, Python will destroy the objects after the value of 
c is obtained.  This is what kills me with Ledger, because the code looks like 
this:

  for post in ledger.Journal("sample.dat").collect("-M assets"):

But I need the journal to stay alive for "post" to be meaningful.  Well, it 
turns out that Boost.Python lets me force this to happen, which I wasn't doing 
previously:

    .def("collect", py_collect, with_custodian_and_ward_postcall<0, 1>())

This statement says that the return value of collect now holds a refcount for 
the object that created it, so that the journal stays alive until the 
collection is deleted.  With this change, the example works.

So, maybe the hope for Python isn't lost after all!

John

Reply via email to