CPyCppyy icon indicating copy to clipboard operation
CPyCppyy copied to clipboard

report type of passed argument when conversion fails

Open N-Coder opened this issue 4 years ago • 3 comments

N-Coder avatar Oct 24 '21 10:10 N-Coder

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 avatar Oct 25 '21 06:10 N-Coder

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

N-Coder avatar Nov 07 '21 11:11 N-Coder

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.

wlav avatar Nov 08 '21 17:11 wlav