Skip to content
Prev Previous commit
Next Next commit
Add more comments.
  • Loading branch information
serhiy-storchaka committed Nov 7, 2023
commit 2d132e6fae6a31993359aec74dd4d8ce28e94144
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4872,7 +4872,7 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
Py_DECREF(key);
return result;
}

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.

Please add // not found after to be extra explicit, since this code pattern is not common.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added here and in other places.


// not found
if (!PyType_Check(itemtype)) {
PyErr_SetString(PyExc_TypeError,
"Expected a type object");
Expand Down
2 changes: 2 additions & 0 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,8 +1922,10 @@ create_pointer_type(PyObject *module, PyObject *cls)
PyObject *key;

if (PyDict_GetItemRef(_ctypes_ptrtype_cache, cls, &result) != 0) {
// error or found
return result;
}
// not found
if (PyUnicode_CheckExact(cls)) {
PyObject *name = PyUnicode_FromFormat("LP_%U", cls);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
Expand Down
2 changes: 2 additions & 0 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,11 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
PyObject *attrib = Py_NewRef(self->extra->attrib);
PyObject *value;
if (PyDict_GetItemRef(attrib, key, &value) != 0) {
// error or found
Py_DECREF(attrib);
return value;
}
// not found
Py_DECREF(attrib);
}

Expand Down
1 change: 1 addition & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ local_getattro(localobject *self, PyObject *name)
/* Optimization: just look in dict ourselves */
PyObject *value;
if (PyDict_GetItemRef(ldict, name, &value) != 0) {
// error or found
return value;
}

Expand Down
2 changes: 2 additions & 0 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ PyModule_GetNameObject(PyObject *mod)
}
PyObject *name;
if (PyDict_GetItemRef(dict, &_Py_ID(__name__), &name) <= 0) {
// error or not found
goto error;
}
if (!PyUnicode_Check(name)) {
Expand Down Expand Up @@ -562,6 +563,7 @@ PyModule_GetFilenameObject(PyObject *mod)
}
PyObject *fileobj;
if (PyDict_GetItemRef(dict, &_Py_ID(__file__), &fileobj) <= 0) {
// error or not found
goto error;
}
if (!PyUnicode_Check(fileobj)) {
Expand Down
2 changes: 2 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,10 +1489,12 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
if (dict != NULL) {
Py_INCREF(dict);
if (PyDict_GetItemRef(dict, name, method) != 0) {
// error or found
Py_DECREF(dict);
Py_XDECREF(descr);
return 0;
}
// not found
Py_DECREF(dict);
}

Expand Down
1 change: 1 addition & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10247,6 +10247,7 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
assert(dict != NULL && PyDict_Check(dict));

if (PyDict_GetItemRef(dict, name, &res) != 0) {
// error or found
Py_DECREF(mro);
return res;
}
Expand Down
3 changes: 2 additions & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,9 +2373,10 @@ get_path_importer(PyThreadState *tstate, PyObject *path_importer_cache,
return NULL; /* Shouldn't happen */

if (PyDict_GetItemRef(path_importer_cache, p, &importer) != 0) {
// error or found
return importer;
}

// not found
/* set path_importer_cache[p] to None to avoid recursion */
if (PyDict_SetItem(path_importer_cache, p, Py_None) != 0)
return NULL;
Expand Down