diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-05-18 17:15:44 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-05-18 17:15:44 (GMT) |
commit | 1ab833082738ced53318aca05901e596d5ede683 (patch) | |
tree | 0ff2b4c1fcbab3233e012f04bce801cadfd6d7f9 /Objects/longobject.c | |
parent | 14176a56d3fe36388115688d0b5acae0c759c044 (diff) | |
download | cpython-1ab833082738ced53318aca05901e596d5ede683.zip cpython-1ab833082738ced53318aca05901e596d5ede683.tar.gz cpython-1ab833082738ced53318aca05901e596d5ede683.tar.bz2 |
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
PyString_Concat() and PyString_ConcatAndDel() (the name PyUnicode_Concat()
was already taken).
Change PyObject_Repr() to always return a unicode object.
Update all repr implementations to return unicode objects.
Add a function PyObject_ReprStr8() that calls PyObject_Repr() and converts
the result to an 8bit string.
Use PyObject_ReprStr8() where using PyObject_Repr() can't be done
straightforward.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 61e5bed..d325b8e 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1430,10 +1430,10 @@ static PyObject * long_format(PyObject *aa, int base) { register PyLongObject *a = (PyLongObject *)aa; - PyStringObject *str; + PyObject *str; Py_ssize_t i, j, sz; Py_ssize_t size_a; - char *p; + Py_UNICODE *p; int bits; char sign = '\0'; @@ -1459,10 +1459,10 @@ long_format(PyObject *aa, int base) "int is too large to format"); return NULL; } - str = (PyStringObject *) PyString_FromStringAndSize((char *)0, sz); + str = PyUnicode_FromUnicode(NULL, sz); if (str == NULL) return NULL; - p = PyString_AS_STRING(str) + sz; + p = PyUnicode_AS_UNICODE(str) + sz; *p = '\0'; if (a->ob_size < 0) sign = '-'; @@ -1486,7 +1486,7 @@ long_format(PyObject *aa, int base) do { char cdigit = (char)(accum & (base - 1)); cdigit += (cdigit < 10) ? '0' : 'a'-10; - assert(p > PyString_AS_STRING(str)); + assert(p > PyUnicode_AS_UNICODE(str)); *--p = cdigit; accumbits -= basebits; accum >>= basebits; @@ -1538,7 +1538,7 @@ long_format(PyObject *aa, int base) do { digit nextrem = (digit)(rem / base); char c = (char)(rem - nextrem * base); - assert(p > PyString_AS_STRING(str)); + assert(p > PyUnicode_AS_UNICODE(str)); c += (c < 10) ? '0' : 'a'-10; *--p = c; rem = nextrem; @@ -1567,14 +1567,16 @@ long_format(PyObject *aa, int base) } if (sign) *--p = sign; - if (p != PyString_AS_STRING(str)) { - char *q = PyString_AS_STRING(str); + if (p != PyUnicode_AS_UNICODE(str)) { + Py_UNICODE *q = PyUnicode_AS_UNICODE(str); assert(p > q); do { } while ((*q++ = *p++) != '\0'); q--; - _PyString_Resize((PyObject **)&str, - (Py_ssize_t) (q - PyString_AS_STRING(str))); + if (PyUnicode_Resize(&str, (Py_ssize_t) (q - PyUnicode_AS_UNICODE(str)))) { + Py_DECREF(str); + return NULL; + } } return (PyObject *)str; } @@ -1928,7 +1930,7 @@ digit beyond the first. strobj = PyString_FromStringAndSize(orig_str, slen); if (strobj == NULL) return NULL; - strrepr = PyObject_Repr(strobj); + strrepr = PyObject_ReprStr8(strobj); Py_DECREF(strobj); if (strrepr == NULL) return NULL; @@ -3525,7 +3527,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) /* create a repr() of the input string, * just like PyLong_FromString does. */ PyObject *srepr; - srepr = PyObject_Repr(x); + srepr = PyObject_ReprStr8(x); if (srepr == NULL) return NULL; PyErr_Format(PyExc_ValueError, |