[C++-sig] Re: (no subject)
David Abrahams
dave at boost-consulting.com
Mon Sep 29 15:53:54 CEST 2003
Raoul Gough <RaoulGough at yahoo.co.uk> writes:
> Also, if you want to manage Python objects in C++, the Boost.Python
> library has some code to help with the reference count management,
> mostly in the "object" class. Maybe grepping for the (undocumented?)
> borrowed_reference or new_reference in the libs/python/src tree will
> provide suitable examples?
Uhm. Those are really not for user consumption, which is why they're
not in namespace boost::python::. I'm not sure it was the right
choice, but users are supposed to go through handle<> to acquire
references. Either:
handle<> x(whatever); // new reference
handle<> x(borrowed(whatever)); // borrowed reference
object(x); // now we have an object.
I've been thinking a bit about this interface recently. I think
something like the following might be better:
class reference
{
public:
PyObject* get() const;
...
protected:
reference(PyObject*);
reference();
private:
void operator delete(void*); // not defined
void operator delete(void*, size_t);
};
class borrowed_reference : reference
{
public:
borrowed_reference(PyObject*);
};
class new_reference : reference
{
public:
new_reference(PyObject*);
};
This allows python::references to be passed around, but not
constructed. You have to say borrowed_reference or new_reference
explicitly.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list