wlav / CPyCppyy

Other
23 stars 20 forks source link

report type of passed argument when conversion fails #2

Open N-Coder opened 3 years ago

N-Coder commented 3 years ago

Could the PyErr_Clear in Utility::ClassName, which gets called when the passed object has no __cpp_name__, interfere with the following SetPyError_ and the PyErr_Fetch it calls?

std::string CPyCppyy::Utility::ClassName(PyObject* pyobj) {
    std::string clname = "<unknown>";
    PyObject* pyclass = (PyObject*)Py_TYPE(pyobj);
    PyObject* pyname = PyObject_GetAttr(pyclass, PyStrings::gCppName);
    if (!pyname) {
        PyErr_Clear();
        pyname = PyObject_GetAttr(pyclass, PyStrings::gName);
    }
N-Coder commented 3 years ago

I changed it to ClassName and removed the ref counting, but I'm still unsure what'll happen in case of an exception.

wlav commented 3 years ago

I'm thinking (not tested) that in case of an exception, PyErr_Clear would need to be called for ClassName() to succeed. I'm also thinking that if there is an exception, fetching it and using it as part of the message may be useful.