[C++-sig] test if object instance is instance of extension class in C++

Holger Joukl Holger.Joukl at LBBW.de
Fri Feb 24 15:33:49 CET 2012


Hi,

> On 02/24/2012 05:44 AM, Holger Joukl wrote:
> > Just for the record, this is what I do now:
> >
> > inline
> > bool isMyExtensionClass(PyObject* &pyobj) {
> >     bp::extract<MyExtensionClass&> extractor(pyobj);
> >     return extractor.check();
> > }
>
> I'm not sure why you use raw PyObject pointers in the first place. That
> should all be hidden behind bpl::object instances (which will then take
> care of the ref counting business for you).

We're porting a legacy boost.python v1-wrapped library to current
boost.python.
Some parts of its internal methods operate on raw PyObject pointers. While
we're probably going to change that for now I all I want is a running
version
and change as little as possible.

> > inline
> > bool isMyExtensionClass(bp::object &obj) {
> >     bp::extract<MyExtensionClass&> extractor(obj);
> >     return extractor.check();
> > }
>
> bp::object itself has reference (smart pointer) semantics, so there is
> no need to pass objects by reference.

I see. Just out of curiosity:
If I pass by reference I do save a copy constructor call, don't I?
But I circumvent the bp::object refcount safety, though(?).
But in a type check like above this shouldn't be dangerous - right?

Holger

Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart



More information about the Cplusplus-sig mailing list