diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2014-09-15 23:50:44 +1200 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2014-09-15 23:50:44 +1200 |
commit | 5e16d8ca5aa2a75af135013975cea98b38a5b17b (patch) | |
tree | ca52a08b87adc739e72c4e1c3643dd10351f9e1b /Python/codecs.c | |
parent | e55ee080c93df539f7beebfc5344648d6bbb0755 (diff) | |
download | cpython-5e16d8ca5aa2a75af135013975cea98b38a5b17b.tar.gz |
Issue #22166: clear codec caches in test_codecs
Diffstat (limited to 'Python/codecs.c')
-rw-r--r-- | Python/codecs.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Python/codecs.c b/Python/codecs.c index e06d6e0922..6b8033ecf8 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -185,6 +185,32 @@ PyObject *_PyCodec_Lookup(const char *encoding) return NULL; } +int _PyCodec_Forget(const char *encoding) +{ + PyInterpreterState *interp; + PyObject *v; + int result; + + interp = PyThreadState_GET()->interp; + if (interp->codec_search_path == NULL) { + return -1; + } + + /* Convert the encoding to a normalized Python string: all + characters are converted to lower case, spaces and hyphens are + replaced with underscores. */ + v = normalizestring(encoding); + if (v == NULL) { + return -1; + } + + /* Drop the named codec from the internal cache */ + result = PyDict_DelItem(interp->codec_search_cache, v); + Py_DECREF(v); + + return result; +} + /* Codec registry encoding check API. */ int PyCodec_KnownEncoding(const char *encoding) |