-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-41842: Add a unregister function in _codecs module #22360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
fefda70
f7775c0
71b624e
d186726
f8e912b
40666fc
3257b6c
a493a35
e29ec44
db4631e
5efff22
f18cd4f
8f6dc4d
4308ea8
c9a0c99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :func:`codecs.unregister` and :c:func:`PyCodec_Unregister` to unregister | ||
a codec search function. | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,27 @@ int PyCodec_Register(PyObject *search_function) | |
return -1; | ||
} | ||
|
||
int | ||
PyCodec_Unregister(PyObject *search_function) | ||
{ | ||
PyInterpreterState *interp = PyInterpreterState_Get(); | ||
PyObject *codec_search_path = interp->codec_search_path; | ||
/* Do nothing if codec_search_path is not created yet or was cleared. */ | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (codec_search_path == NULL) { | ||
return 0; | ||
} | ||
|
||
Py_ssize_t n = PyList_Size(codec_search_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the macro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it's a list right now, its type can change tomorrow. @shihai1991: If you modify the code to use fast macros, please add the following assertion before using it:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vstinner Copy that, I have already updated it. |
||
for (Py_ssize_t i = 0; i < n; i++) { | ||
PyObject *item = PyList_GetItem(codec_search_path, i); | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (item == search_function) { | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyDict_Clear(interp->codec_search_cache); | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return PyList_SetSlice(codec_search_path, i, i+1, NULL); | ||
} | ||
} | ||
shihai1991 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} | ||
|
||
extern int _Py_normalize_encoding(const char *, char *, size_t); | ||
|
||
/* Convert a string to a normalized Python string(decoded from UTF-8): all characters are | ||
|
Uh oh!
There was an error while loading. Please reload this page.