diff options
Diffstat (limited to 'Objects')
-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 |
4 files changed, 30 insertions, 60 deletions
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; } } |