[Python-3000-checkins] r58833 - python/branches/py3k-pep3137/Objects/unicodeobject.c
walter.doerwald
python-3000-checkins at python.org
Sat Nov 3 21:42:14 CET 2007
Author: walter.doerwald
Date: Sat Nov 3 21:42:13 2007
New Revision: 58833
Modified:
python/branches/py3k-pep3137/Objects/unicodeobject.c
Log:
Change PyUnicode_EncodeCharmap() back to return PyString
objects instead of PyBytes.
Modified: python/branches/py3k-pep3137/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/unicodeobject.c (original)
+++ python/branches/py3k-pep3137/Objects/unicodeobject.c Sat Nov 3 21:42:13 2007
@@ -4328,16 +4328,14 @@
}
static int
-charmapencode_resize(PyObject *outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize)
+charmapencode_resize(PyObject **outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize)
{
- Py_ssize_t outsize = PyBytes_GET_SIZE( outobj);
+ Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2*outsize)
requiredsize = 2*outsize;
- if (PyBytes_Resize(outobj, requiredsize)) {
- Py_DECREF(outobj);
+ if (_PyString_Resize(outobj, requiredsize))
return -1;
- }
return 0;
}
@@ -4352,21 +4350,21 @@
reallocation error occurred. The caller must decref the result */
static
charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
- PyObject *outobj, Py_ssize_t *outpos)
+ PyObject **outobj, Py_ssize_t *outpos)
{
PyObject *rep;
char *outstart;
- Py_ssize_t outsize = PyBytes_GET_SIZE(outobj);
+ Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
if (Py_Type(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(c, mapping);
Py_ssize_t requiredsize = *outpos+1;
if (res == -1)
return enc_FAILED;
- if (outsize<requiredsize)
+ if (outsize<requiredsize)
if (charmapencode_resize(outobj, outpos, requiredsize))
return enc_EXCEPTION;
- outstart = PyBytes_AS_STRING(outobj);
+ outstart = PyString_AS_STRING(*outobj);
outstart[(*outpos)++] = (char)res;
return enc_SUCCESS;
}
@@ -4385,7 +4383,7 @@
Py_DECREF(rep);
return enc_EXCEPTION;
}
- outstart = PyBytes_AS_STRING(outobj);
+ outstart = PyString_AS_STRING(*outobj);
outstart[(*outpos)++] = (char)PyInt_AS_LONG(rep);
}
else {
@@ -4397,7 +4395,7 @@
Py_DECREF(rep);
return enc_EXCEPTION;
}
- outstart = PyBytes_AS_STRING(outobj);
+ outstart = PyString_AS_STRING(*outobj);
memcpy(outstart + *outpos, repchars, repsize);
*outpos += repsize;
}
@@ -4413,7 +4411,7 @@
const Py_UNICODE *p, Py_ssize_t size, Py_ssize_t *inpos, PyObject *mapping,
PyObject **exceptionObject,
int *known_errorHandler, PyObject **errorHandler, const char *errors,
- PyObject *res, Py_ssize_t *respos)
+ PyObject **res, Py_ssize_t *respos)
{
PyObject *repunicode = NULL; /* initialize to prevent gcc warning */
Py_ssize_t repsize;
@@ -4548,7 +4546,7 @@
/* allocate enough for a simple encoding without
replacements, if we need more, we'll resize */
- res = PyBytes_FromStringAndSize(NULL, size);
+ res = PyString_FromStringAndSize(NULL, size);
if (res == NULL)
goto onError;
if (size == 0)
@@ -4556,14 +4554,14 @@
while (inpos<size) {
/* try to encode it */
- charmapencode_result x = charmapencode_output(p[inpos], mapping, res, &respos);
+ charmapencode_result x = charmapencode_output(p[inpos], mapping, &res, &respos);
if (x==enc_EXCEPTION) /* error */
goto onError;
if (x==enc_FAILED) { /* unencodable character */
if (charmap_encoding_error(p, size, &inpos, mapping,
&exc,
&known_errorHandler, &errorHandler, errors,
- res, &respos)) {
+ &res, &respos)) {
goto onError;
}
}
@@ -4573,10 +4571,9 @@
}
/* Resize if we allocated to much */
- if (respos<PyBytes_GET_SIZE(res)) {
- if (PyBytes_Resize(res, respos))
- goto onError;
- }
+ if (respos<PyString_GET_SIZE(res))
+ _PyString_Resize(&res, respos);
+
Py_XDECREF(exc);
Py_XDECREF(errorHandler);
return res;
More information about the Python-3000-checkins
mailing list