summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-19 21:48:41 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-19 21:48:41 (GMT)
commit21431e85d505b9698c085c25cbf1b2997a352b85 (patch)
treefc98ab07e6d8f8f6e41a2fdb9a24b54d9de330b8
parent630e46424a578bb619037dceed72a734d39ee237 (diff)
downloadcpython-21431e85d505b9698c085c25cbf1b2997a352b85.zip
cpython-21431e85d505b9698c085c25cbf1b2997a352b85.tar.gz
cpython-21431e85d505b9698c085c25cbf1b2997a352b85.tar.bz2
This is the uncontroversial half of patch 1263 by Thomas Lee:
changes to codecs.c and structmember.c to use PyUnicode instead of PyString.
-rw-r--r--Python/codecs.c20
-rw-r--r--Python/structmember.c10
2 files changed, 17 insertions, 13 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 464fffc..4b24676 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;
diff --git a/Python/structmember.c b/Python/structmember.c
index 3eb7218..c4b7d80 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -51,13 +51,13 @@ PyMember_GetOne(const char *addr, PyMemberDef *l)
v = Py_None;
}
else
- v = PyString_FromString(*(char**)addr);
+ v = PyUnicode_FromString(*(char**)addr);
break;
case T_STRING_INPLACE:
- v = PyString_FromString((char*)addr);
+ v = PyUnicode_FromString((char*)addr);
break;
case T_CHAR:
- v = PyString_FromStringAndSize((char*)addr, 1);
+ v = PyUnicode_FromStringAndSize((char*)addr, 1);
break;
case T_OBJECT:
v = *(PyObject **)addr;
@@ -225,8 +225,8 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
Py_XDECREF(oldv);
break;
case T_CHAR:
- if (PyString_Check(v) && PyString_Size(v) == 1) {
- *(char*)addr = PyString_AsString(v)[0];
+ if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) {
+ *(char*)addr = PyUnicode_AsString(v)[0];
}
else {
PyErr_BadArgument();