Renamed PyString to PyBytes
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 445d56a..1401188 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1100,9 +1100,9 @@
}
/* Coerce object */
- if (PyString_Check(obj)) {
- s = PyString_AS_STRING(obj);
- len = PyString_GET_SIZE(obj);
+ if (PyBytes_Check(obj)) {
+ s = PyBytes_AS_STRING(obj);
+ len = PyBytes_GET_SIZE(obj);
}
else if (PyObject_AsCharBuffer(obj, &s, &len)) {
/* Overwrite the error message with something more useful in
@@ -1298,7 +1298,7 @@
v = PyCodec_Encode(unicode, encoding, errors);
if (v == NULL)
goto onError;
- assert(PyString_Check(v));
+ assert(PyBytes_Check(v));
return v;
onError:
@@ -1367,8 +1367,8 @@
if (bytes == NULL)
return NULL;
if (psize != NULL)
- *psize = PyString_GET_SIZE(bytes);
- return PyString_AS_STRING(bytes);
+ *psize = PyBytes_GET_SIZE(bytes);
+ return PyBytes_AS_STRING(bytes);
}
char*
@@ -1480,11 +1480,11 @@
inputobj = PyUnicodeDecodeError_GetObject(*exceptionObject);
if (!inputobj)
goto onError;
- if (!PyString_Check(inputobj)) {
+ if (!PyBytes_Check(inputobj)) {
PyErr_Format(PyExc_TypeError, "exception attribute object must be bytes");
}
- *input = PyString_AS_STRING(inputobj);
- insize = PyString_GET_SIZE(inputobj);
+ *input = PyBytes_AS_STRING(inputobj);
+ insize = PyBytes_GET_SIZE(inputobj);
*inend = *input + insize;
/* we can DECREF safely, as the exception has another reference,
so the object won't go away. */
@@ -1762,7 +1762,7 @@
char * start;
if (size == 0)
- return PyString_FromStringAndSize(NULL, 0);
+ return PyBytes_FromStringAndSize(NULL, 0);
v = PyByteArray_FromStringAndSize(NULL, cbAllocated);
if (v == NULL)
@@ -1834,7 +1834,7 @@
*out++ = '-';
}
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), out - start);
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), out - start);
Py_DECREF(v);
return result;
}
@@ -2100,10 +2100,10 @@
nallocated = size * 4;
if (nallocated / 4 != size) /* overflow! */
return PyErr_NoMemory();
- result = PyString_FromStringAndSize(NULL, nallocated);
+ result = PyBytes_FromStringAndSize(NULL, nallocated);
if (result == NULL)
return NULL;
- p = PyString_AS_STRING(result);
+ p = PyBytes_AS_STRING(result);
}
for (i = 0; i < size;) {
@@ -2151,13 +2151,13 @@
/* This was stack allocated. */
nneeded = p - stackbuf;
assert(nneeded <= nallocated);
- result = PyString_FromStringAndSize(stackbuf, nneeded);
+ result = PyBytes_FromStringAndSize(stackbuf, nneeded);
}
else {
/* Cut back to size actually needed. */
- nneeded = p - PyString_AS_STRING(result);
+ nneeded = p - PyBytes_AS_STRING(result);
assert(nneeded <= nallocated);
- _PyString_Resize(&result, nneeded);
+ _PyBytes_Resize(&result, nneeded);
}
return result;
@@ -2427,7 +2427,7 @@
}
done:
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v);
return result;
#undef STORECHAR
@@ -2691,7 +2691,7 @@
}
done:
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v);
return result;
#undef STORECHAR
@@ -3106,7 +3106,7 @@
*p++ = (char) ch;
}
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr),
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr),
p - PyByteArray_AS_STRING(repr));
Py_DECREF(repr);
return result;
@@ -3124,7 +3124,7 @@
if (!s)
return NULL;
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s),
PyByteArray_GET_SIZE(s));
Py_DECREF(s);
return result;
@@ -3327,7 +3327,7 @@
size = p - q;
done:
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr), size);
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr), size);
Py_DECREF(repr);
return result;
}
@@ -3344,7 +3344,7 @@
if (!s)
return NULL;
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s),
PyByteArray_GET_SIZE(s));
Py_DECREF(s);
return result;
@@ -3577,7 +3577,7 @@
/* allocate enough for a simple encoding without
replacements, if we need more, we'll resize */
if (size == 0)
- return PyString_FromStringAndSize(NULL, 0);
+ return PyBytes_FromStringAndSize(NULL, 0);
res = PyByteArray_FromStringAndSize(NULL, size);
if (res == NULL)
return NULL;
@@ -3708,7 +3708,7 @@
}
}
}
- result = PyString_FromStringAndSize(PyByteArray_AS_STRING(res),
+ result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(res),
str - PyByteArray_AS_STRING(res));
onError:
Py_DECREF(res);
@@ -3960,20 +3960,20 @@
if (*repr == NULL) {
/* Create string object */
- *repr = PyString_FromStringAndSize(NULL, mbcssize);
+ *repr = PyBytes_FromStringAndSize(NULL, mbcssize);
if (*repr == NULL)
return -1;
}
else {
/* Extend string object */
- n = PyString_Size(*repr);
- if (_PyString_Resize(repr, n + mbcssize) < 0)
+ n = PyBytes_Size(*repr);
+ if (_PyBytes_Resize(repr, n + mbcssize) < 0)
return -1;
}
/* Do the conversion */
if (size > 0) {
- char *s = PyString_AS_STRING(*repr) + n;
+ char *s = PyBytes_AS_STRING(*repr) + n;
if (0 == WideCharToMultiByte(CP_ACP, 0, p, size, s, mbcssize, NULL, NULL)) {
PyErr_SetFromWindowsErrWithFilename(0, NULL);
return -1;
@@ -4440,7 +4440,7 @@
}
return x;
}
- else if (PyString_Check(x))
+ else if (PyBytes_Check(x))
return x;
else {
/* wrong return value */
@@ -4455,11 +4455,11 @@
static int
charmapencode_resize(PyObject **outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize)
{
- Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
+ Py_ssize_t outsize = PyBytes_GET_SIZE(*outobj);
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2*outsize)
requiredsize = 2*outsize;
- if (_PyString_Resize(outobj, requiredsize))
+ if (_PyBytes_Resize(outobj, requiredsize))
return -1;
return 0;
}
@@ -4479,7 +4479,7 @@
{
PyObject *rep;
char *outstart;
- Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
+ Py_ssize_t outsize = PyBytes_GET_SIZE(*outobj);
if (Py_TYPE(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(c, mapping);
@@ -4489,7 +4489,7 @@
if (outsize<requiredsize)
if (charmapencode_resize(outobj, outpos, requiredsize))
return enc_EXCEPTION;
- outstart = PyString_AS_STRING(*outobj);
+ outstart = PyBytes_AS_STRING(*outobj);
outstart[(*outpos)++] = (char)res;
return enc_SUCCESS;
}
@@ -4508,19 +4508,19 @@
Py_DECREF(rep);
return enc_EXCEPTION;
}
- outstart = PyString_AS_STRING(*outobj);
+ outstart = PyBytes_AS_STRING(*outobj);
outstart[(*outpos)++] = (char)PyLong_AS_LONG(rep);
}
else {
- const char *repchars = PyString_AS_STRING(rep);
- Py_ssize_t repsize = PyString_GET_SIZE(rep);
+ const char *repchars = PyBytes_AS_STRING(rep);
+ Py_ssize_t repsize = PyBytes_GET_SIZE(rep);
Py_ssize_t requiredsize = *outpos+repsize;
if (outsize<requiredsize)
if (charmapencode_resize(outobj, outpos, requiredsize)) {
Py_DECREF(rep);
return enc_EXCEPTION;
}
- outstart = PyString_AS_STRING(*outobj);
+ outstart = PyBytes_AS_STRING(*outobj);
memcpy(outstart + *outpos, repchars, repsize);
*outpos += repsize;
}
@@ -4671,7 +4671,7 @@
/* allocate enough for a simple encoding without
replacements, if we need more, we'll resize */
- res = PyString_FromStringAndSize(NULL, size);
+ res = PyBytes_FromStringAndSize(NULL, size);
if (res == NULL)
goto onError;
if (size == 0)
@@ -4696,8 +4696,8 @@
}
/* Resize if we allocated to much */
- if (respos<PyString_GET_SIZE(res))
- _PyString_Resize(&res, respos);
+ if (respos<PyBytes_GET_SIZE(res))
+ _PyBytes_Resize(&res, respos);
Py_XDECREF(exc);
Py_XDECREF(errorHandler);
@@ -6622,7 +6622,7 @@
v = PyUnicode_AsEncodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a bytes object "
"(type=%.400s)",
@@ -8475,7 +8475,7 @@
PyObject *str; /* temporary string object. */
PyObject *result;
- str = _PyString_FormatLong(val, flags, prec, type, &buf, &len);
+ str = _PyBytes_FormatLong(val, flags, prec, type, &buf, &len);
if (!str)
return NULL;
result = PyUnicode_FromStringAndSize(buf, len);