diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-26 04:19:43 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-26 04:19:43 (GMT) |
commit | 6ea45d33412d4ecb2862645d57137b7ea1223281 (patch) | |
tree | 90a60a1298fff16a71f2501e87613385624a52d9 | |
parent | 5b0fdc9d0aef58fffe225bee493d62cd905d6b80 (diff) | |
download | cpython-6ea45d33412d4ecb2862645d57137b7ea1223281.zip cpython-6ea45d33412d4ecb2862645d57137b7ea1223281.tar.gz cpython-6ea45d33412d4ecb2862645d57137b7ea1223281.tar.bz2 |
Use unicode and remove support for some uses of str8.
-rw-r--r-- | Lib/binhex.py | 4 | ||||
-rw-r--r-- | Modules/cjkcodecs/cjkcodecs.h | 11 | ||||
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 26 | ||||
-rw-r--r-- | Objects/abstract.c | 7 | ||||
-rw-r--r-- | Objects/floatobject.c | 19 | ||||
-rw-r--r-- | Objects/object.c | 20 | ||||
-rw-r--r-- | Objects/typeobject.c | 44 | ||||
-rw-r--r-- | Python/bltinmodule.c | 28 |
8 files changed, 59 insertions, 100 deletions
diff --git a/Lib/binhex.py b/Lib/binhex.py index a8abf1b..8da8961 100644 --- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -420,8 +420,8 @@ class HexBin: self.FName = fname self.FInfo = FInfo() - self.FInfo.Creator = str8(creator) - self.FInfo.Type = str8(type) + self.FInfo.Creator = creator + self.FInfo.Type = type self.FInfo.Flags = flags self.state = _DID_HEADER diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h index c79b304..9449c1f 100644 --- a/Modules/cjkcodecs/cjkcodecs.h +++ b/Modules/cjkcodecs/cjkcodecs.h @@ -261,22 +261,19 @@ getcodec(PyObject *self, PyObject *encoding) const MultibyteCodec *codec; const char *enc; - if (PyUnicode_Check(encoding)) { - encoding = _PyUnicode_AsDefaultEncodedString(encoding, NULL); - if (encoding == NULL) - return NULL; - } - if (!PyString_Check(encoding)) { + if (!PyUnicode_Check(encoding)) { PyErr_SetString(PyExc_TypeError, "encoding name must be a string."); return NULL; } + enc = PyUnicode_AsString(encoding, NULL); + if (enc == NULL) + return NULL; cofunc = getmultibytecodec(); if (cofunc == NULL) return NULL; - enc = PyString_AS_STRING(encoding); for (codec = codec_list; codec->encoding[0]; codec++) if (strcmp(codec->encoding, enc) == 0) break; diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 7d14437..4778efb 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -85,16 +85,20 @@ internal_error_callback(const char *errors) else if (strcmp(errors, "replace") == 0) return ERROR_REPLACE; else - return PyString_FromString(errors); + return PyUnicode_FromString(errors); } static PyObject * call_error_callback(PyObject *errors, PyObject *exc) { PyObject *args, *cb, *r; + const char *str; - assert(PyString_Check(errors)); - cb = PyCodec_LookupError(PyString_AS_STRING(errors)); + assert(PyUnicode_Check(errors)); + str = PyUnicode_AsString(errors); + if (str == NULL) + return NULL; + cb = PyCodec_LookupError(str); if (cb == NULL) return NULL; @@ -129,7 +133,7 @@ codecctx_errors_get(MultibyteStatefulCodecContext *self) return self->errors; } - return PyString_FromString(errors); + return PyUnicode_FromString(errors); } static int @@ -137,18 +141,18 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value, void *closure) { PyObject *cb; + const char *str; - if (PyUnicode_Check(value)) { - value = _PyUnicode_AsDefaultEncodedString(value, NULL); - if (value == NULL) - return -1; - } - if (!PyString_Check(value)) { + if (!PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "errors must be a string"); return -1; } - cb = internal_error_callback(PyString_AS_STRING(value)); + str = PyUnicode_AsString(value); + if (str == NULL) + return -1; + + cb = internal_error_callback(str); if (cb == NULL) return -1; diff --git a/Objects/abstract.c b/Objects/abstract.c index 4e25061..e303caf 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1281,13 +1281,6 @@ PyNumber_Long(PyObject *o) } if (PyLong_Check(o)) /* A long subclass without nb_long */ return _PyLong_Copy((PyLongObject *)o); - if (PyString_Check(o)) - /* need to do extra error checking that PyLong_FromString() - * doesn't do. In particular long('9.5') must raise an - * exception, not truncate the float. - */ - return long_from_string(PyString_AS_STRING(o), - PyString_GET_SIZE(o)); if (PyUnicode_Check(o)) /* The above check is done in PyLong_FromUnicode(). */ return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o), diff --git a/Objects/floatobject.c b/Objects/floatobject.c index ca94750..f74b19d 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -74,11 +74,7 @@ PyFloat_FromString(PyObject *v) Py_ssize_t len; PyObject *result = NULL; - if (PyString_Check(v)) { - s = PyString_AS_STRING(v); - len = PyString_GET_SIZE(v); - } - else if (PyUnicode_Check(v)) { + if (PyUnicode_Check(v)) { s_buffer = (char *)PyMem_MALLOC(PyUnicode_GET_SIZE(v)+1); if (s_buffer == NULL) return PyErr_NoMemory(); @@ -843,7 +839,7 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return float_subtype_new(type, args, kwds); /* Wimp out */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) return NULL; - if (PyString_Check(x)) + if (PyUnicode_Check(x)) return PyFloat_FromString(x); return PyNumber_Float(x); } @@ -894,18 +890,15 @@ float_getformat(PyTypeObject *v, PyObject* arg) char* s; float_format_type r; - if (PyUnicode_Check(arg)) { - arg = _PyUnicode_AsDefaultEncodedString(arg, NULL); - if (arg == NULL) - return NULL; - } - if (!PyString_Check(arg)) { + if (!PyUnicode_Check(arg)) { PyErr_Format(PyExc_TypeError, "__getformat__() argument must be string, not %.500s", Py_Type(arg)->tp_name); return NULL; } - s = PyString_AS_STRING(arg); + s = PyUnicode_AsString(arg); + if (s == NULL) + return NULL; if (strcmp(s, "double") == 0) { r = double_format; } diff --git a/Objects/object.c b/Objects/object.c index 04d5f48..dd68ecd 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -357,7 +357,7 @@ _PyObject_Dump(PyObject* op) PyObject * PyObject_Repr(PyObject *v) { - PyObject *ress, *resu; + PyObject *res; if (PyErr_CheckSignals()) return NULL; #ifdef USE_STACKCHECK @@ -371,21 +371,15 @@ PyObject_Repr(PyObject *v) else if (Py_Type(v)->tp_repr == NULL) return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v); else { - ress = (*v->ob_type->tp_repr)(v); - if (!ress) - return NULL; - if (PyUnicode_Check(ress)) - return ress; - if (!PyString_Check(ress)) { + res = (*v->ob_type->tp_repr)(v); + if (res != NULL && !PyUnicode_Check(res)) { PyErr_Format(PyExc_TypeError, "__repr__ returned non-string (type %.200s)", - ress->ob_type->tp_name); - Py_DECREF(ress); + res->ob_type->tp_name); + Py_DECREF(res); return NULL; } - resu = PyUnicode_FromObject(ress); - Py_DECREF(ress); - return resu; + return res; } } @@ -413,7 +407,7 @@ _PyObject_Str(PyObject *v) { PyObject *res; if (v == NULL) - return PyString_FromString("<NULL>"); + return PyUnicode_FromString("<NULL>"); if (PyString_CheckExact(v)) { Py_INCREF(v); return v; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 6ea8e1d..bdcccf1 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -55,17 +55,15 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context) "can't delete %s.__name__", type->tp_name); return -1; } - if (PyUnicode_Check(value)) { - value = _PyUnicode_AsDefaultEncodedString(value, NULL); - if (value == NULL) - return -1; - } - if (!PyString_Check(value)) { + if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "can only assign string to %s.__name__, not '%s'", type->tp_name, Py_Type(value)->tp_name); return -1; } + value = _PyUnicode_AsDefaultEncodedString(value, NULL); + if (value == NULL) + return -1; if (strlen(PyString_AS_STRING(value)) != (size_t)PyString_GET_SIZE(value)) { PyErr_Format(PyExc_ValueError, @@ -1918,30 +1916,22 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) */ { PyObject *doc = PyDict_GetItemString(dict, "__doc__"); - if (doc != NULL) { - char *tp_doc; - const char *str = NULL; + if (doc != NULL && PyUnicode_Check(doc)) { size_t n; - if (PyString_Check(doc)) { - str = PyString_AS_STRING(doc); - n = (size_t)PyString_GET_SIZE(doc); - } else if (PyUnicode_Check(doc)) { - str = PyUnicode_AsString(doc); - if (str == NULL) { - Py_DECREF(type); - return NULL; - } - n = strlen(str); + char *tp_doc; + const char *str = PyUnicode_AsString(doc); + if (str == NULL) { + Py_DECREF(type); + return NULL; } - if (str != NULL) { - tp_doc = (char *)PyObject_MALLOC(n+1); - if (tp_doc == NULL) { - Py_DECREF(type); - return NULL; - } - memcpy(tp_doc, str, n+1); - type->tp_doc = tp_doc; + n = strlen(str); + tp_doc = (char *)PyObject_MALLOC(n+1); + if (tp_doc == NULL) { + Py_DECREF(type); + return NULL; } + memcpy(tp_doc, str, n+1); + type->tp_doc = tp_doc; } } diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 17f5b59..22a57ea 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -40,7 +40,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) } func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ name = PyTuple_GET_ITEM(args, 1); - if ((!PyString_Check(name) && !PyUnicode_Check(name))) { + if (!PyUnicode_Check(name)) { PyErr_SetString(PyExc_TypeError, "__build_class__: name is not a string"); return NULL; @@ -631,8 +631,7 @@ builtin_exec(PyObject *self, PyObject *args) } else if (locals == Py_None) locals = globals; - if (!PyString_Check(prog) && - !PyUnicode_Check(prog) && + if (!PyUnicode_Check(prog) && !PyCode_Check(prog)) { PyErr_Format(PyExc_TypeError, "exec() arg 1 must be a string, file, or code " @@ -695,23 +694,15 @@ globals and locals. If only globals is given, locals defaults to it."); static PyObject * builtin_getattr(PyObject *self, PyObject *args) { - PyObject *v, *result, *dflt = NULL, *release = NULL; + PyObject *v, *result, *dflt = NULL; PyObject *name; if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt)) return NULL; - if (PyString_Check(name)) { - release = PyString_AsDecodedObject(name, NULL, NULL); - if (!release) - return NULL; - name = release; - } - if (!PyUnicode_Check(name)) { PyErr_SetString(PyExc_TypeError, "getattr(): attribute name must be string"); - Py_XDECREF(release); return NULL; } result = PyObject_GetAttr(v, name); @@ -722,7 +713,6 @@ builtin_getattr(PyObject *self, PyObject *args) Py_INCREF(dflt); result = dflt; } - Py_XDECREF(release); return result; } @@ -1221,17 +1211,15 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds) if (file == NULL || file == Py_None) file = PySys_GetObject("stdout"); - if (sep && sep != Py_None && !PyString_Check(sep) && - !PyUnicode_Check(sep)) { + if (sep && sep != Py_None && !PyUnicode_Check(sep)) { PyErr_Format(PyExc_TypeError, - "sep must be None, str or unicode, not %.200s", + "sep must be None or a string, not %.200s", sep->ob_type->tp_name); return NULL; } - if (end && end != Py_None && !PyString_Check(end) && - !PyUnicode_Check(end)) { + if (end && end != Py_None && !PyUnicode_Check(end)) { PyErr_Format(PyExc_TypeError, - "end must be None, str or unicode, not %.200s", + "end must be None or a string, not %.200s", end->ob_type->tp_name); return NULL; } @@ -1383,7 +1371,7 @@ builtin_input(PyObject *self, PyObject *args) result = NULL; } else { - result = PyString_FromStringAndSize(s, len-1); + result = PyUnicode_FromStringAndSize(s, len-1); } } PyMem_FREE(s); |