> On Jul 11, 2026, at 12:45, [email protected] wrote: > > Is a finalizer wanted here at all, or is explicit lifetime management > (with / destroy) the intended contract for the Python bindings? And if > a finalizer is acceptable, do you prefer the Python-wrapper approach > or the SWIG thisown approach?
Well, explicit lifetime management is the contract on the C side. A complication in either of your proposals is that gnc_get_current_session isn’t necessarily borrowed: If there is no current session then it calls gnc_session_new(). Since it also creates a book for the session it’s really the preferred constructor, but unfortunately qof_session_new is used directly in a few places. The only really safe way to have shared ownership—a requirement for automatic destruction in a GC binding--is with properly-used shared pointers. GObject provides C shared pointers but they have to be manually reffed and unreffed and our current code either ignores that feature altogether or isn’t always consistent about it. C++ std::shared_ptrs are automatic but can’t be used directly from C. Regards, John Ralls
_______________________________________________ gnucash-devel mailing list [email protected] https://lists.gnucash.org/mailman/listinfo/gnucash-devel
