Skip to content
Merged
Prev Previous commit
Next Next commit
apply victor and Zackery's comment
  • Loading branch information
shihai1991 committed Sep 26, 2020
commit 8f6dc4d62b0f9c5b8750a2206179ef20a965e3fa
5 changes: 3 additions & 2 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Base32 Encoding with Extended Hex Alphabet.
codecs
------

Add a :func:`codecs.unregister` to unregister a codec search function.
Add a :func:`codecs.unregister` function to unregister a codec search function.
(Contributed by Hai Shi in :issue:`41842`.)

curses
Expand Down Expand Up @@ -243,7 +243,8 @@ New Features
:class:`datetime.time` objects.
(Contributed by Zackery Spytz in :issue:`30155`.)

* Add a :c:func:`PyCodec_Unregister` to unregister a codec search function.
* Add a :c:func:`PyCodec_Unregister` function to unregister a codec
search function.
(Contributed by Hai Shi in :issue:`41842`.)

Porting to Python 3.10
Expand Down
10 changes: 7 additions & 3 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ PyCodec_Unregister(PyObject *search_function)
return 0;
}

Py_ssize_t n = PyList_Size(codec_search_path);
assert(PyList_CheckExact(codec_search_path));
Py_ssize_t n = PyList_GET_SIZE(codec_search_path);
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *item = PyList_GetItem(codec_search_path, i);
PyObject *item = PyList_GET_ITEM(codec_search_path, i);
if (item == search_function) {
Comment thread
shihai1991 marked this conversation as resolved.
PyDict_Clear(interp->codec_search_cache);
if (interp->codec_search_cache != NULL) {
assert(PyDict_Check(interp->codec_search_cache));
PyDict_Clear(interp->codec_search_cache);
}
return PyList_SetSlice(codec_search_path, i, i+1, NULL);
}
}
Comment thread
shihai1991 marked this conversation as resolved.
Expand Down