diff options
author | Guido van Rossum <guido@python.org> | 2007-10-19 21:48:41 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-19 21:48:41 +0000 |
commit | d2f673acdad1d4d415b2ac07a2f78e03fca00ff1 (patch) | |
tree | a65e3fd718d8e15abad41fc057f5c4eafc903d7a /Python/codecs.c | |
parent | 325c6d4703412fa475d7a9ea4bed3474a0390add (diff) | |
download | cpython-d2f673acdad1d4d415b2ac07a2f78e03fca00ff1.tar.gz |
This is the uncontroversial half of patch 1263 by Thomas Lee:
changes to codecs.c and structmember.c to use PyUnicode instead of
PyString.
Diffstat (limited to 'Python/codecs.c')
-rw-r--r-- | Python/codecs.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Python/codecs.c b/Python/codecs.c index 464fffc150..4b2467634d 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -55,16 +55,15 @@ PyObject *normalizestring(const char *string) size_t len = strlen(string); char *p; PyObject *v; - + if (len > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "string is too large"); return NULL; } - - v = PyString_FromStringAndSize(NULL, len); - if (v == NULL) - return NULL; - p = PyString_AS_STRING(v); + + p = PyMem_Malloc(len + 1); + if (p == NULL) + return NULL; for (i = 0; i < len; i++) { register char ch = string[i]; if (ch == ' ') @@ -73,6 +72,11 @@ PyObject *normalizestring(const char *string) ch = tolower(Py_CHARMASK(ch)); p[i] = ch; } + p[i] = '\0'; + v = PyUnicode_FromString(p); + if (v == NULL) + return NULL; + PyMem_Free(p); return v; } @@ -112,7 +116,7 @@ PyObject *_PyCodec_Lookup(const char *encoding) v = normalizestring(encoding); if (v == NULL) goto onError; - PyString_InternInPlace(&v); + PyUnicode_InternInPlace(&v); /* First, try to lookup the name in the registry dictionary */ result = PyDict_GetItem(interp->codec_search_cache, v); @@ -193,7 +197,7 @@ PyObject *args_tuple(PyObject *object, if (errors) { PyObject *v; - v = PyString_FromString(errors); + v = PyUnicode_FromString(errors); if (v == NULL) { Py_DECREF(args); return NULL; |