[C++-sig] [Boost.Python v3] handle, object, and PyObject*

Jim Bosch talljimbo at gmail.com
Sat Nov 12 22:19:19 CET 2011

Boost.Python has two smart-pointer-like classes for holding PyObject*. 
"handle<>" is more or less a customized intrusive_ptr, with the ability 
to be templated on other PyObject "derived" types (like PyTypeObject). 
The "object" hierarchy provides a much higher-level API, and defaults to 
Python's None rather than a null pointer.

In terms of actual usage, I see:

  - "object" is widely used in the public Boost.Python API, and is 
extremely useful there.

  - "handle<>" is rarely used except as a bridge to create object from 
PyObject*.  The internal API tends to use raw PyObject* instead.

  - "handle<>" is almost never used with a non-default template parameter.

Is there any reason why the internal API uses raw PyObject* instead of 

If not, I'm inclined to start using handle<> there (or even object, for 
features that have become widely used like rvalue-converters).

And since handle<> is almost never used as a template, I'm inclined to 
make it a regular class - or even just a typedef of intrusive_ptr<PyObject>.

Any thoughts?


More information about the Cplusplus-sig mailing list