Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int CPyDict_Update(PyObject *dict, PyObject *stuff) {
int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) {
if (PyDict_CheckExact(dict)) {
// Argh this sucks
if (PyDict_Check(stuff) || _CPyObject_HasAttr(stuff, mypyc_interned_str.keys)) {
if (PyDict_Check(stuff)|| PyObject_HasAttrWithError(stuff, mypyc_interned_str.keys)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this return -1 on failure which would be bad and trigger the if? (when would that failure be...)

I'm not very familiar with C so maybe I'm wrong :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wouldn't this return -1 on failure

Yes, but that's already returned from _CPyObject_HasAttr on failure as well.
https://docs.python.org/3/c-api/object.html#c.PyObject_GetOptionalAttr

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess if you want minimal PRs this can be fixed in a followup then...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pushed a new commit to explicitly check for > 0. That should resolve that issue as well.

return PyDict_Update(dict, stuff);
} else {
return PyDict_MergeFromSeq2(dict, stuff, 1);
Expand All @@ -178,7 +178,7 @@ PyObject *CPyDict_FromAny(PyObject *obj) {
if (!dict) {
return NULL;
}
if (_CPyObject_HasAttr(obj, mypyc_interned_str.keys)) {
if (PyObject_HasAttrWithError(obj, mypyc_interned_str.keys)) {
res = PyDict_Update(dict, obj);
} else {
res = PyDict_MergeFromSeq2(dict, obj, 1);
Expand Down
10 changes: 0 additions & 10 deletions mypyc/lib-rt/pythonsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,6 @@ _CPyDictView_New(PyObject *dict, PyTypeObject *type)
}
#endif

static int
_CPyObject_HasAttr(PyObject *v, PyObject *name) {
PyObject *tmp = NULL;
int result = PyObject_GetOptionalAttr(v, name, &tmp);
if (tmp) {
Py_DECREF(tmp);
}
return result;
}

#if CPY_3_12_FEATURES

// These are copied from genobject.c in Python 3.12
Expand Down