Menu

#40 Problems with check method when dealing with derived class

None
closed-fixed
nobody
None
5
2016-06-25
2016-06-22
Ben Webb
No

In the file ExtensionsType.hxx, the following code

static bool check( PyObject *p )
{
// is p like me?
return p->ob_type == type_object();
}

    needs to be changed to the following to handled derived classes

static bool check( PyObject p )
{
return PyObject_IsInstance(p,
(type())) ? true : false;
}

    This allows the following code to work when a class defined in a py file is derived from a c++ new style class

    Py::PythonClassObject<dlPyProgress> pyProgress(obj);
return &pyProgress.getCxxObject()->m_Progress;

Without the change the Py::PythonClassObject line throws an exception

Discussion

  • Barry Alan Scott

    Thanks for the report.
    Please see r340 that fixes this issue.
    You will see that I built on your solution and added test code.
    Note: PyObject_IsInstance can return 1, 0 or -1

     
  • Barry Alan Scott

    • status: open --> closed-fixed
    • Group: -->
     

Log in to post a comment.