Mercurial > cpython-lru_cache-weakref
diff Python/codecs.c @ 12025:7994d9db7f4d legacy-trunk
On 17-Mar-2000, Marc-Andre Lemburg said:
Attached you find an update of the Unicode implementation.
The patch is against the current CVS version. I would appreciate
if someone with CVS checkin permissions could check the changes
in.
The patch contains all bugs and patches sent this week and also
fixes a leak in the codecs code and a bug in the free list code
for Unicode objects (which only shows up when compiling Python
with Py_DEBUG; thanks to MarkH for spotting this one).
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Mon, 20 Mar 2000 16:36:48 +0000 |
| parents | d0e06efb3165 |
| children | f87b56eebacc |
line wrap: on
line diff
--- a/Python/codecs.c Mon Mar 20 16:09:09 2000 +0000 +++ b/Python/codecs.c Mon Mar 20 16:36:48 2000 +0000 @@ -93,9 +93,14 @@ PyObject *_PyCodec_Lookup(const char *encoding) { - PyObject *result, *args = NULL, *v; + PyObject *result, *args = NULL, *v = NULL; int i, len; + if (_PyCodec_SearchCache == NULL || _PyCodec_SearchPath == NULL) { + PyErr_SetString(PyExc_SystemError, + "codec module not properly initialized"); + goto onError; + } if (!import_encodings_called) import_encodings(); @@ -109,6 +114,7 @@ result = PyDict_GetItem(_PyCodec_SearchCache, v); if (result != NULL) { Py_INCREF(result); + Py_DECREF(v); return result; } @@ -121,6 +127,7 @@ if (args == NULL) goto onError; PyTuple_SET_ITEM(args,0,v); + v = NULL; for (i = 0; i < len; i++) { PyObject *func; @@ -146,7 +153,7 @@ if (i == len) { /* XXX Perhaps we should cache misses too ? */ PyErr_SetString(PyExc_LookupError, - "unkown encoding"); + "unknown encoding"); goto onError; } @@ -156,6 +163,7 @@ return result; onError: + Py_XDECREF(v); Py_XDECREF(args); return NULL; } @@ -378,5 +386,7 @@ void _PyCodecRegistry_Fini() { Py_XDECREF(_PyCodec_SearchPath); + _PyCodec_SearchPath = NULL; Py_XDECREF(_PyCodec_SearchCache); + _PyCodec_SearchCache = NULL; }
