Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CPPScope.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ static PyObject* pt_new(PyTypeObject* subtype, PyObject* args, PyObject* kwds)
// so make it accessible (the __cpp_cross__ data member also signals that
// this is a cross-inheritance class)
PyObject* bname = CPyCppyy_PyText_FromString(Cppyy::GetBaseName(result->fCppType, 0).c_str());
PyErr_Clear();
if (PyObject_SetAttrString((PyObject*)result, "__cpp_cross__", bname) == -1)
PyErr_Clear();
Py_DECREF(bname);
Expand Down Expand Up @@ -542,6 +543,7 @@ static int meta_setattro(PyObject* pyclass, PyObject* pyname, PyObject* pyval)
}
}

PyErr_Clear(); // creation might have failed
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens when meta_getattro fails. In my investigation, it failed for some special methods. And if the user does something like:

In [3]: cppyy.cppdef("""
   ...: namespace ns {}
   ...: """)
Out[3]: True

In [4]: gbl.ns.something = 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, now that I think about this, in the above-mentioned cases, it should not be calling meta_getattro. I will need to cross-check this.

return PyType_Type.tp_setattro(pyclass, pyname, pyval);
}

Expand Down
1 change: 1 addition & 0 deletions src/Pythonize.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, const std::string& name)

// data with size
Utility::AddToClass(pyclass, "__real_data", "data");
PyErr_Clear(); // AddToClass might have failed for data
Comment on lines 1805 to +1806
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failure is at

PyObject* pyfunc = PyObject_GetAttrString(pyclass, const_cast<char*>(func));

With pyclass and "data" as arguments.
I guess this is one of the errors that we should not clear/ignore. I will look into it.

Utility::AddToClass(pyclass, "data", (PyCFunction)VectorData);

// numpy array conversion
Expand Down
7 changes: 4 additions & 3 deletions src/Utility.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ static bool AddTypeName(std::string& tmpl_name, PyObject* tn, PyObject* arg,
PyErr_Clear();

// ctypes function pointer
PyObject* argtypes = PyObject_GetAttrString(arg, "argtypes");
PyObject* ret = PyObject_GetAttrString(arg, "restype");
if (argtypes && ret) {
PyObject* argtypes = nullptr;
PyObject* ret = nullptr;
if ((argtypes = PyObject_GetAttrString(arg, "argtypes")) && (ret = PyObject_GetAttrString(arg, "restype"))) {
Comment on lines +555 to +557
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a safer rewrite for the PyErr_Clear in line 582 below.
The first GetAttr fails, then in the second, Python's assert(!PyErr_Occurred()) fails.

std::ostringstream tpn;
PyObject* pytc = PyObject_GetAttr(ret, PyStrings::gCTypesType);
tpn << CT2CppNameS(pytc, false)
Expand Down Expand Up @@ -895,6 +895,7 @@ Py_ssize_t CPyCppyy::Utility::GetBuffer(PyObject* pyobject, char tc, int size, v
if (PyObject_CheckBuffer(pyobject)) {
if (PySequence_Check(pyobject) && !PySequence_Size(pyobject))
return 0; // PyObject_GetBuffer() crashes on some platforms for some zero-sized seqeunces
PyErr_Clear();
Comment on lines 896 to +898
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens when PySequence_Size fails with an error something like "sequence does not have __len__", but PySequence_Check succeeds. (I will cross-check, once)


Py_buffer bufinfo;
memset(&bufinfo, 0, sizeof(Py_buffer));
Expand Down