Skip to content
Closed
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
7 changes: 7 additions & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,11 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
sw_dict = PyType_stgdict(swapped);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PyType_stgdict() never returns NULL here since CreateSwappedType() just created a type with PyCStgDict.

if (sw_dict == NULL) {
Py_DECREF(result);
Py_DECREF(swapped);
return NULL;
}
#ifdef WORDS_BIGENDIAN
PyObject_SetAttrString((PyObject *)result, "__ctype_le__", swapped);
PyObject_SetAttrString((PyObject *)result, "__ctype_be__", (PyObject *)result);
Expand Down Expand Up @@ -4054,6 +4059,8 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
}

dict = PyType_stgdict((PyObject *)type);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PyType_stgdict() never returns NULL here since _init_pos_args() is called only for _ctypes.Structure and _ctypes.Union which creates types with PyCStgDict or recursively for their base classes after checking that PyType_stgdict() is not NULL.

if (dict == NULL)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We've started to put curly braces around one-liners: https://www.python.org/dev/peps/pep-0007/#code-lay-out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aaaaah, thanks for the confirmation @brettcannon ! I had a long discussion with @serhiy-storchaka about that ;-)

return -1;
fields = PyDict_GetItemString((PyObject *)dict, "_fields_");
if (fields == NULL)
return index;
Expand Down