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

Stefan Seefeld stefan at seefeld.name
Fri Feb 24 14:36:27 CET 2012

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).

> 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.



      ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list