CPyCppyy
CPyCppyy copied to clipboard
report type of passed argument when conversion fails
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);
}
I changed it to ClassName and removed the ref counting, but I'm still unsure what'll happen in case of an exception.
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.