summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c44
-rw-r--r--Objects/boolobject.c4
-rw-r--r--Objects/bufferobject.c26
-rw-r--r--Objects/bytes_methods.c20
-rw-r--r--Objects/bytesobject.c16
-rw-r--r--Objects/cellobject.c4
-rw-r--r--Objects/classobject.c174
-rw-r--r--Objects/codeobject.c44
-rw-r--r--Objects/complexobject.c18
-rw-r--r--Objects/descrobject.c22
-rw-r--r--Objects/dictobject.c78
-rw-r--r--Objects/exceptions.c96
-rw-r--r--Objects/fileobject.c112
-rw-r--r--Objects/floatobject.c24
-rw-r--r--Objects/frameobject.c10
-rw-r--r--Objects/funcobject.c16
-rw-r--r--Objects/genobject.c4
-rw-r--r--Objects/intobject.c16
-rw-r--r--Objects/listobject.c20
-rw-r--r--Objects/longobject.c34
-rw-r--r--Objects/methodobject.c12
-rw-r--r--Objects/moduleobject.c22
-rw-r--r--Objects/object.c58
-rw-r--r--Objects/rangeobject.c6
-rw-r--r--Objects/setobject.c30
-rw-r--r--Objects/sliceobject.c18
-rw-r--r--Objects/stringlib/formatter.h2
-rw-r--r--Objects/stringlib/string_format.h2
-rw-r--r--Objects/stringlib/stringdefs.h14
-rw-r--r--Objects/stringobject.c962
-rw-r--r--Objects/structseq.c4
-rw-r--r--Objects/tupleobject.c16
-rw-r--r--Objects/typeobject.c120
-rw-r--r--Objects/unicodeobject.c132
-rw-r--r--Objects/weakrefobject.c8
35 files changed, 1094 insertions, 1094 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 83de88f..3e6feb5 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -105,7 +105,7 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
/* cache a hashed version of the attribute string */
if (hintstrobj == NULL) {
- hintstrobj = PyString_InternFromString("__length_hint__");
+ hintstrobj = PyBytes_InternFromString("__length_hint__");
if (hintstrobj == NULL)
goto defaultcase;
}
@@ -227,7 +227,7 @@ PyObject_DelItemString(PyObject *o, char *key)
null_error();
return -1;
}
- okey = PyString_FromString(key);
+ okey = PyBytes_FromString(key);
if (okey == NULL)
return -1;
ret = PyObject_DelItem(o, okey);
@@ -729,21 +729,21 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
/* Initialize cached value */
if (str__format__ == NULL) {
/* Initialize static variable needed by _PyType_Lookup */
- str__format__ = PyString_InternFromString("__format__");
+ str__format__ = PyBytes_InternFromString("__format__");
if (str__format__ == NULL)
goto done;
}
/* If no format_spec is provided, use an empty string */
if (format_spec == NULL) {
- empty = PyString_FromStringAndSize(NULL, 0);
+ empty = PyBytes_FromStringAndSize(NULL, 0);
format_spec = empty;
}
/* Check the format_spec type, and make sure it's str or unicode */
if (PyUnicode_Check(format_spec))
spec_is_unicode = 1;
- else if (PyString_Check(format_spec))
+ else if (PyBytes_Check(format_spec))
spec_is_unicode = 0;
else {
PyErr_Format(PyExc_TypeError,
@@ -823,7 +823,7 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
/* Check the result type, and make sure it's str or unicode */
if (PyUnicode_Check(result))
result_is_unicode = 1;
- else if (PyString_Check(result))
+ else if (PyBytes_Check(result))
result_is_unicode = 0;
else {
PyErr_Format(PyExc_TypeError,
@@ -1541,7 +1541,7 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
const char *type_name;
static PyObject *int_name = NULL;
if (int_name == NULL) {
- int_name = PyString_InternFromString("__int__");
+ int_name = PyBytes_InternFromString("__int__");
if (int_name == NULL)
return NULL;
}
@@ -1567,7 +1567,7 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
non_integral_error:
if (PyInstance_Check(integral)) {
- type_name = PyString_AS_STRING(((PyInstanceObject *)integral)
+ type_name = PyBytes_AS_STRING(((PyInstanceObject *)integral)
->in_class->cl_name);
}
else {
@@ -1589,7 +1589,7 @@ PyNumber_Int(PyObject *o)
Py_ssize_t buffer_len;
if (trunc_name == NULL) {
- trunc_name = PyString_InternFromString("__trunc__");
+ trunc_name = PyBytes_InternFromString("__trunc__");
if (trunc_name == NULL)
return NULL;
}
@@ -1629,9 +1629,9 @@ PyNumber_Int(PyObject *o)
}
PyErr_Clear(); /* It's not an error if o.__trunc__ doesn't exist. */
- if (PyString_Check(o))
- return int_from_string(PyString_AS_STRING(o),
- PyString_GET_SIZE(o));
+ if (PyBytes_Check(o))
+ return int_from_string(PyBytes_AS_STRING(o),
+ PyBytes_GET_SIZE(o));
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(o))
return PyInt_FromUnicode(PyUnicode_AS_UNICODE(o),
@@ -1674,7 +1674,7 @@ PyNumber_Long(PyObject *o)
Py_ssize_t buffer_len;
if (trunc_name == NULL) {
- trunc_name = PyString_InternFromString("__trunc__");
+ trunc_name = PyBytes_InternFromString("__trunc__");
if (trunc_name == NULL)
return NULL;
}
@@ -1716,13 +1716,13 @@ PyNumber_Long(PyObject *o)
}
PyErr_Clear(); /* It's not an error if o.__trunc__ doesn't exist. */
- if (PyString_Check(o))
+ if (PyBytes_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));
+ return long_from_string(PyBytes_AS_STRING(o),
+ PyBytes_GET_SIZE(o));
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(o))
/* The above check is done in PyLong_FromUnicode(). */
@@ -2413,7 +2413,7 @@ PyMapping_GetItemString(PyObject *o, char *key)
if (key == NULL)
return null_error();
- okey = PyString_FromString(key);
+ okey = PyBytes_FromString(key);
if (okey == NULL)
return NULL;
r = PyObject_GetItem(o, okey);
@@ -2432,7 +2432,7 @@ PyMapping_SetItemString(PyObject *o, char *key, PyObject *value)
return -1;
}
- okey = PyString_FromString(key);
+ okey = PyBytes_FromString(key);
if (okey == NULL)
return -1;
r = PyObject_SetItem(o, okey, value);
@@ -2760,7 +2760,7 @@ abstract_get_bases(PyObject *cls)
PyObject *bases;
if (__bases__ == NULL) {
- __bases__ = PyString_InternFromString("__bases__");
+ __bases__ = PyBytes_InternFromString("__bases__");
if (__bases__ == NULL)
return NULL;
}
@@ -2838,7 +2838,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
int retval = 0;
if (__class__ == NULL) {
- __class__ = PyString_InternFromString("__class__");
+ __class__ = PyBytes_InternFromString("__class__");
if (__class__ == NULL)
return -1;
}
@@ -2914,7 +2914,7 @@ PyObject_IsInstance(PyObject *inst, PyObject *cls)
return 1;
if (name == NULL) {
- name = PyString_InternFromString("__instancecheck__");
+ name = PyBytes_InternFromString("__instancecheck__");
if (name == NULL)
return -1;
}
@@ -2998,7 +2998,7 @@ PyObject_IsSubclass(PyObject *derived, PyObject *cls)
PyErr_Fetch(&t, &v, &tb);
if (name == NULL) {
- name = PyString_InternFromString("__subclasscheck__");
+ name = PyBytes_InternFromString("__subclasscheck__");
if (name == NULL)
return -1;
}
diff --git a/Objects/boolobject.c b/Objects/boolobject.c
index fd73d28..93affd1 100644
--- a/Objects/boolobject.c
+++ b/Objects/boolobject.c
@@ -25,10 +25,10 @@ bool_repr(PyBoolObject *self)
if (self->ob_ival)
s = true_str ? true_str :
- (true_str = PyString_InternFromString("True"));
+ (true_str = PyBytes_InternFromString("True"));
else
s = false_str ? false_str :
- (false_str = PyString_InternFromString("False"));
+ (false_str = PyBytes_InternFromString("False"));
Py_XINCREF(s);
return s;
}
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
index 37d9bcb..ee8dd3d 100644
--- a/Objects/bufferobject.c
+++ b/Objects/bufferobject.c
@@ -287,13 +287,13 @@ buffer_repr(PyBufferObject *self)
const char *status = self->b_readonly ? "read-only" : "read-write";
if ( self->b_base == NULL )
- return PyString_FromFormat("<%s buffer ptr %p, size %zd at %p>",
+ return PyBytes_FromFormat("<%s buffer ptr %p, size %zd at %p>",
status,
self->b_ptr,
self->b_size,
self);
else
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"<%s buffer for %p, size %zd, offset %zd at %p>",
status,
self->b_base,
@@ -318,7 +318,7 @@ buffer_hash(PyBufferObject *self)
* underlying memory is immutable. b_readonly is a necessary but not
* sufficient condition for a buffer to be hashable. Perhaps it would
* be better to only allow hashing if the underlying object is known to
- * be immutable (e.g. PyString_Check() is true). Another idea would
+ * be immutable (e.g. PyBytes_Check() is true). Another idea would
* be to call tp_hash on the underlying object and see if it raises
* an error. */
if ( !self->b_readonly )
@@ -349,7 +349,7 @@ buffer_str(PyBufferObject *self)
Py_ssize_t size;
if (!get_buf(self, &ptr, &size, ANY_BUFFER))
return NULL;
- return PyString_FromStringAndSize((const char *)ptr, size);
+ return PyBytes_FromStringAndSize((const char *)ptr, size);
}
/* Sequence methods */
@@ -401,10 +401,10 @@ buffer_concat(PyBufferObject *self, PyObject *other)
if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
return NULL;
- ob = PyString_FromStringAndSize(NULL, size + count);
+ ob = PyBytes_FromStringAndSize(NULL, size + count);
if ( ob == NULL )
return NULL;
- p = PyString_AS_STRING(ob);
+ p = PyBytes_AS_STRING(ob);
memcpy(p, ptr1, size);
memcpy(p + size, ptr2, count);
@@ -426,11 +426,11 @@ buffer_repeat(PyBufferObject *self, Py_ssize_t count)
count = 0;
if (!get_buf(self, &ptr, &size, ANY_BUFFER))
return NULL;
- ob = PyString_FromStringAndSize(NULL, size * count);
+ ob = PyBytes_FromStringAndSize(NULL, size * count);
if ( ob == NULL )
return NULL;
- p = PyString_AS_STRING(ob);
+ p = PyBytes_AS_STRING(ob);
while ( count-- )
{
memcpy(p, ptr, size);
@@ -454,7 +454,7 @@ buffer_item(PyBufferObject *self, Py_ssize_t idx)
PyErr_SetString(PyExc_IndexError, "buffer index out of range");
return NULL;
}
- return PyString_FromStringAndSize((char *)ptr + idx, 1);
+ return PyBytes_FromStringAndSize((char *)ptr + idx, 1);
}
static PyObject *
@@ -472,7 +472,7 @@ buffer_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right)
right = size;
if ( right < left )
right = left;
- return PyString_FromStringAndSize((char *)ptr + left,
+ return PyBytes_FromStringAndSize((char *)ptr + left,
right - left);
}
@@ -501,9 +501,9 @@ buffer_subscript(PyBufferObject *self, PyObject *item)
}
if (slicelength <= 0)
- return PyString_FromStringAndSize("", 0);
+ return PyBytes_FromStringAndSize("", 0);
else if (step == 1)
- return PyString_FromStringAndSize((char *)p + start,
+ return PyBytes_FromStringAndSize((char *)p + start,
stop - start);
else {
PyObject *result;
@@ -518,7 +518,7 @@ buffer_subscript(PyBufferObject *self, PyObject *item)
result_buf[i] = source_buf[cur];
}
- result = PyString_FromStringAndSize(result_buf,
+ result = PyBytes_FromStringAndSize(result_buf,
slicelength);
PyMem_Free(result_buf);
return result;
diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c
index de87905..2d55601 100644
--- a/Objects/bytes_methods.c
+++ b/Objects/bytes_methods.c
@@ -462,11 +462,11 @@ _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len)
Py_ssize_t i;
/*
- newobj = PyString_FromStringAndSize(NULL, len);
+ newobj = PyBytes_FromStringAndSize(NULL, len);
if (!newobj)
return NULL;
- s = PyString_AS_STRING(newobj);
+ s = PyBytes_AS_STRING(newobj);
*/
Py_MEMCPY(result, cptr, len);
@@ -490,11 +490,11 @@ _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len)
Py_ssize_t i;
/*
- newobj = PyString_FromStringAndSize(NULL, len);
+ newobj = PyBytes_FromStringAndSize(NULL, len);
if (!newobj)
return NULL;
- s = PyString_AS_STRING(newobj);
+ s = PyBytes_AS_STRING(newobj);
*/
Py_MEMCPY(result, cptr, len);
@@ -520,10 +520,10 @@ _Py_bytes_title(char *result, char *s, Py_ssize_t len)
int previous_is_cased = 0;
/*
- newobj = PyString_FromStringAndSize(NULL, len);
+ newobj = PyBytes_FromStringAndSize(NULL, len);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
*/
for (i = 0; i < len; i++) {
int c = Py_CHARMASK(*s++);
@@ -553,10 +553,10 @@ _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len)
Py_ssize_t i;
/*
- newobj = PyString_FromStringAndSize(NULL, len);
+ newobj = PyBytes_FromStringAndSize(NULL, len);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
*/
if (0 < len) {
int c = Py_CHARMASK(*s++);
@@ -589,10 +589,10 @@ _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len)
Py_ssize_t i;
/*
- newobj = PyString_FromStringAndSize(NULL, len);
+ newobj = PyBytes_FromStringAndSize(NULL, len);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
*/
for (i = 0; i < len; i++) {
int c = Py_CHARMASK(*s++);
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 25fec6d..6e5df19 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -41,12 +41,12 @@ _getbytevalue(PyObject* arg, int *value)
return 0;
}
}
- else if (PyString_CheckExact(arg)) {
+ else if (PyBytes_CheckExact(arg)) {
if (Py_SIZE(arg) != 1) {
PyErr_SetString(PyExc_ValueError, "string must be of size 1");
return 0;
}
- face_value = Py_CHARMASK(((PyStringObject*)arg)->ob_sval[0]);
+ face_value = Py_CHARMASK(((PyBytesObject*)arg)->ob_sval[0]);
}
else {
PyErr_Format(PyExc_TypeError, "an integer or string of size 1 is required");
@@ -768,13 +768,13 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
return 0;
}
- if (PyString_Check(arg)) {
+ if (PyBytes_Check(arg)) {
PyObject *new, *encoded;
if (encoding != NULL) {
encoded = PyCodec_Encode(arg, encoding, errors);
if (encoded == NULL)
return -1;
- assert(PyString_Check(encoded));
+ assert(PyBytes_Check(encoded));
}
else {
encoded = arg;
@@ -799,7 +799,7 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
encoded = PyCodec_Encode(arg, encoding, errors);
if (encoded == NULL)
return -1;
- assert(PyString_Check(encoded));
+ assert(PyBytes_Check(encoded));
new = bytes_iconcat(self, encoded);
Py_DECREF(encoded);
if (new == NULL)
@@ -1002,7 +1002,7 @@ bytes_str(PyObject *op)
}
return bytes_repr((PyByteArrayObject*)op);
#endif
- return PyString_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
+ return PyBytes_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
}
static PyObject *
@@ -2969,7 +2969,7 @@ bytes_join(PyByteArrayObject *self, PyObject *it)
/* XXX Shouldn't we use _getbuffer() on these items instead? */
for (i = 0; i < n; i++) {
PyObject *obj = items[i];
- if (!PyByteArray_Check(obj) && !PyString_Check(obj)) {
+ if (!PyByteArray_Check(obj) && !PyBytes_Check(obj)) {
PyErr_Format(PyExc_TypeError,
"can only join an iterable of bytes "
"(item %ld has type '%.100s')",
@@ -2998,7 +2998,7 @@ bytes_join(PyByteArrayObject *self, PyObject *it)
if (PyByteArray_Check(obj))
buf = PyByteArray_AS_STRING(obj);
else
- buf = PyString_AS_STRING(obj);
+ buf = PyBytes_AS_STRING(obj);
if (i) {
memcpy(dest, self->ob_bytes, mysize);
dest += mysize;
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index 4e0bcf8..16bb150 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -73,9 +73,9 @@ static PyObject *
cell_repr(PyCellObject *op)
{
if (op->ob_ref == NULL)
- return PyString_FromFormat("<cell at %p: empty>", op);
+ return PyBytes_FromFormat("<cell at %p: empty>", op);
- return PyString_FromFormat("<cell at %p: %.80s object at %p>",
+ return PyBytes_FromFormat("<cell at %p: %.80s object at %p>",
op, op->ob_ref->ob_type->tp_name,
op->ob_ref);
}
diff --git a/Objects/classobject.c b/Objects/classobject.c
index caf6b3e..372a40e 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -32,21 +32,21 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
PyClassObject *op, *dummy;
static PyObject *docstr, *modstr, *namestr;
if (docstr == NULL) {
- docstr= PyString_InternFromString("__doc__");
+ docstr= PyBytes_InternFromString("__doc__");
if (docstr == NULL)
return NULL;
}
if (modstr == NULL) {
- modstr= PyString_InternFromString("__module__");
+ modstr= PyBytes_InternFromString("__module__");
if (modstr == NULL)
return NULL;
}
if (namestr == NULL) {
- namestr= PyString_InternFromString("__name__");
+ namestr= PyBytes_InternFromString("__name__");
if (namestr == NULL)
return NULL;
}
- if (name == NULL || !PyString_Check(name)) {
+ if (name == NULL || !PyBytes_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"PyClass_New: name must be a string");
return NULL;
@@ -101,13 +101,13 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
}
if (getattrstr == NULL) {
- getattrstr = PyString_InternFromString("__getattr__");
+ getattrstr = PyBytes_InternFromString("__getattr__");
if (getattrstr == NULL)
goto alloc_error;
- setattrstr = PyString_InternFromString("__setattr__");
+ setattrstr = PyBytes_InternFromString("__setattr__");
if (setattrstr == NULL)
goto alloc_error;
- delattrstr = PyString_InternFromString("__delattr__");
+ delattrstr = PyBytes_InternFromString("__delattr__");
if (delattrstr == NULL)
goto alloc_error;
}
@@ -222,7 +222,7 @@ static PyObject *
class_getattr(register PyClassObject *op, PyObject *name)
{
register PyObject *v;
- register char *sname = PyString_AsString(name);
+ register char *sname = PyBytes_AsString(name);
PyClassObject *klass;
descrgetfunc f;
@@ -253,7 +253,7 @@ class_getattr(register PyClassObject *op, PyObject *name)
if (v == NULL) {
PyErr_Format(PyExc_AttributeError,
"class %.50s has no attribute '%.400s'",
- PyString_AS_STRING(op->cl_name), sname);
+ PyBytes_AS_STRING(op->cl_name), sname);
return NULL;
}
f = TP_DESCR_GET(v->ob_type);
@@ -316,9 +316,9 @@ set_bases(PyClassObject *c, PyObject *v)
static char *
set_name(PyClassObject *c, PyObject *v)
{
- if (v == NULL || !PyString_Check(v))
+ if (v == NULL || !PyBytes_Check(v))
return "__name__ must be a string object";
- if (strlen(PyString_AS_STRING(v)) != (size_t)PyString_GET_SIZE(v))
+ if (strlen(PyBytes_AS_STRING(v)) != (size_t)PyBytes_GET_SIZE(v))
return "__name__ must not contain null bytes";
set_slot(&c->cl_name, v);
return "";
@@ -333,9 +333,9 @@ class_setattr(PyClassObject *op, PyObject *name, PyObject *v)
"classes are read-only in restricted mode");
return -1;
}
- sname = PyString_AsString(name);
+ sname = PyBytes_AsString(name);
if (sname[0] == '_' && sname[1] == '_') {
- Py_ssize_t n = PyString_Size(name);
+ Py_ssize_t n = PyBytes_Size(name);
if (sname[n-1] == '_' && sname[n-2] == '_') {
char *err = NULL;
if (strcmp(sname, "__dict__") == 0)
@@ -365,7 +365,7 @@ class_setattr(PyClassObject *op, PyObject *name, PyObject *v)
if (rv < 0)
PyErr_Format(PyExc_AttributeError,
"class %.50s has no attribute '%.400s'",
- PyString_AS_STRING(op->cl_name), sname);
+ PyBytes_AS_STRING(op->cl_name), sname);
return rv;
}
else
@@ -377,15 +377,15 @@ class_repr(PyClassObject *op)
{
PyObject *mod = PyDict_GetItemString(op->cl_dict, "__module__");
char *name;
- if (op->cl_name == NULL || !PyString_Check(op->cl_name))
+ if (op->cl_name == NULL || !PyBytes_Check(op->cl_name))
name = "?";
else
- name = PyString_AsString(op->cl_name);
- if (mod == NULL || !PyString_Check(mod))
- return PyString_FromFormat("<class ?.%s at %p>", name, op);
+ name = PyBytes_AsString(op->cl_name);
+ if (mod == NULL || !PyBytes_Check(mod))
+ return PyBytes_FromFormat("<class ?.%s at %p>", name, op);
else
- return PyString_FromFormat("<class %s.%s at %p>",
- PyString_AsString(mod),
+ return PyBytes_FromFormat("<class %s.%s at %p>",
+ PyBytes_AsString(mod),
name, op);
}
@@ -397,21 +397,21 @@ class_str(PyClassObject *op)
PyObject *res;
Py_ssize_t m, n;
- if (name == NULL || !PyString_Check(name))
+ if (name == NULL || !PyBytes_Check(name))
return class_repr(op);
- if (mod == NULL || !PyString_Check(mod)) {
+ if (mod == NULL || !PyBytes_Check(mod)) {
Py_INCREF(name);
return name;
}
- m = PyString_GET_SIZE(mod);
- n = PyString_GET_SIZE(name);
- res = PyString_FromStringAndSize((char *)NULL, m+1+n);
+ m = PyBytes_GET_SIZE(mod);
+ n = PyBytes_GET_SIZE(name);
+ res = PyBytes_FromStringAndSize((char *)NULL, m+1+n);
if (res != NULL) {
- char *s = PyString_AS_STRING(res);
- memcpy(s, PyString_AS_STRING(mod), m);
+ char *s = PyBytes_AS_STRING(res);
+ memcpy(s, PyBytes_AS_STRING(mod), m);
s += m;
*s++ = '.';
- memcpy(s, PyString_AS_STRING(name), n);
+ memcpy(s, PyBytes_AS_STRING(name), n);
}
return res;
}
@@ -541,7 +541,7 @@ PyInstance_New(PyObject *klass, PyObject *arg, PyObject *kw)
static PyObject *initstr;
if (initstr == NULL) {
- initstr = PyString_InternFromString("__init__");
+ initstr = PyBytes_InternFromString("__init__");
if (initstr == NULL)
return NULL;
}
@@ -634,7 +634,7 @@ instance_dealloc(register PyInstanceObject *inst)
PyErr_Fetch(&error_type, &error_value, &error_traceback);
/* Execute __del__ method, if any. */
if (delstr == NULL) {
- delstr = PyString_InternFromString("__del__");
+ delstr = PyBytes_InternFromString("__del__");
if (delstr == NULL)
PyErr_WriteUnraisable((PyObject*)inst);
}
@@ -696,7 +696,7 @@ static PyObject *
instance_getattr1(register PyInstanceObject *inst, PyObject *name)
{
register PyObject *v;
- register char *sname = PyString_AsString(name);
+ register char *sname = PyBytes_AsString(name);
if (sname[0] == '_' && sname[1] == '_') {
if (strcmp(sname, "__dict__") == 0) {
if (PyEval_GetRestricted()) {
@@ -716,7 +716,7 @@ instance_getattr1(register PyInstanceObject *inst, PyObject *name)
if (v == NULL && !PyErr_Occurred()) {
PyErr_Format(PyExc_AttributeError,
"%.50s instance has no attribute '%.400s'",
- PyString_AS_STRING(inst->in_class->cl_name), sname);
+ PyBytes_AS_STRING(inst->in_class->cl_name), sname);
}
return v;
}
@@ -779,7 +779,7 @@ _PyInstance_Lookup(PyObject *pinst, PyObject *name)
assert(PyInstance_Check(pinst));
inst = (PyInstanceObject *)pinst;
- assert(PyString_Check(name));
+ assert(PyBytes_Check(name));
v = PyDict_GetItem(inst->in_dict, name);
if (v == NULL)
@@ -795,8 +795,8 @@ instance_setattr1(PyInstanceObject *inst, PyObject *name, PyObject *v)
if (rv < 0)
PyErr_Format(PyExc_AttributeError,
"%.50s instance has no attribute '%.400s'",
- PyString_AS_STRING(inst->in_class->cl_name),
- PyString_AS_STRING(name));
+ PyBytes_AS_STRING(inst->in_class->cl_name),
+ PyBytes_AS_STRING(name));
return rv;
}
else
@@ -807,9 +807,9 @@ static int
instance_setattr(PyInstanceObject *inst, PyObject *name, PyObject *v)
{
PyObject *func, *args, *res, *tmp;
- char *sname = PyString_AsString(name);
+ char *sname = PyBytes_AsString(name);
if (sname[0] == '_' && sname[1] == '_') {
- Py_ssize_t n = PyString_Size(name);
+ Py_ssize_t n = PyBytes_Size(name);
if (sname[n-1] == '_' && sname[n-2] == '_') {
if (strcmp(sname, "__dict__") == 0) {
if (PyEval_GetRestricted()) {
@@ -875,7 +875,7 @@ instance_repr(PyInstanceObject *inst)
static PyObject *reprstr;
if (reprstr == NULL) {
- reprstr = PyString_InternFromString("__repr__");
+ reprstr = PyBytes_InternFromString("__repr__");
if (reprstr == NULL)
return NULL;
}
@@ -889,16 +889,16 @@ instance_repr(PyInstanceObject *inst)
classname = inst->in_class->cl_name;
mod = PyDict_GetItemString(inst->in_class->cl_dict,
"__module__");
- if (classname != NULL && PyString_Check(classname))
- cname = PyString_AsString(classname);
+ if (classname != NULL && PyBytes_Check(classname))
+ cname = PyBytes_AsString(classname);
else
cname = "?";
- if (mod == NULL || !PyString_Check(mod))
- return PyString_FromFormat("<?.%s instance at %p>",
+ if (mod == NULL || !PyBytes_Check(mod))
+ return PyBytes_FromFormat("<?.%s instance at %p>",
cname, inst);
else
- return PyString_FromFormat("<%s.%s instance at %p>",
- PyString_AsString(mod),
+ return PyBytes_FromFormat("<%s.%s instance at %p>",
+ PyBytes_AsString(mod),
cname, inst);
}
res = PyEval_CallObject(func, (PyObject *)NULL);
@@ -914,7 +914,7 @@ instance_str(PyInstanceObject *inst)
static PyObject *strstr;
if (strstr == NULL) {
- strstr = PyString_InternFromString("__str__");
+ strstr = PyBytes_InternFromString("__str__");
if (strstr == NULL)
return NULL;
}
@@ -939,7 +939,7 @@ instance_hash(PyInstanceObject *inst)
static PyObject *hashstr, *eqstr, *cmpstr;
if (hashstr == NULL) {
- hashstr = PyString_InternFromString("__hash__");
+ hashstr = PyBytes_InternFromString("__hash__");
if (hashstr == NULL)
return -1;
}
@@ -952,7 +952,7 @@ instance_hash(PyInstanceObject *inst)
address. If an __eq__ or __cmp__ method exists, there must
be a __hash__. */
if (eqstr == NULL) {
- eqstr = PyString_InternFromString("__eq__");
+ eqstr = PyBytes_InternFromString("__eq__");
if (eqstr == NULL)
return -1;
}
@@ -962,7 +962,7 @@ instance_hash(PyInstanceObject *inst)
return -1;
PyErr_Clear();
if (cmpstr == NULL) {
- cmpstr = PyString_InternFromString("__cmp__");
+ cmpstr = PyBytes_InternFromString("__cmp__");
if (cmpstr == NULL)
return -1;
}
@@ -1014,7 +1014,7 @@ instance_length(PyInstanceObject *inst)
Py_ssize_t outcome;
if (lenstr == NULL) {
- lenstr = PyString_InternFromString("__len__");
+ lenstr = PyBytes_InternFromString("__len__");
if (lenstr == NULL)
return -1;
}
@@ -1063,7 +1063,7 @@ instance_subscript(PyInstanceObject *inst, PyObject *key)
PyObject *res;
if (getitemstr == NULL) {
- getitemstr = PyString_InternFromString("__getitem__");
+ getitemstr = PyBytes_InternFromString("__getitem__");
if (getitemstr == NULL)
return NULL;
}
@@ -1090,7 +1090,7 @@ instance_ass_subscript(PyInstanceObject *inst, PyObject *key, PyObject *value)
if (value == NULL) {
if (delitemstr == NULL) {
- delitemstr = PyString_InternFromString("__delitem__");
+ delitemstr = PyBytes_InternFromString("__delitem__");
if (delitemstr == NULL)
return -1;
}
@@ -1098,7 +1098,7 @@ instance_ass_subscript(PyInstanceObject *inst, PyObject *key, PyObject *value)
}
else {
if (setitemstr == NULL) {
- setitemstr = PyString_InternFromString("__setitem__");
+ setitemstr = PyBytes_InternFromString("__setitem__");
if (setitemstr == NULL)
return -1;
}
@@ -1135,7 +1135,7 @@ instance_item(PyInstanceObject *inst, Py_ssize_t i)
PyObject *func, *res;
if (getitemstr == NULL) {
- getitemstr = PyString_InternFromString("__getitem__");
+ getitemstr = PyBytes_InternFromString("__getitem__");
if (getitemstr == NULL)
return NULL;
}
@@ -1154,7 +1154,7 @@ instance_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j)
static PyObject *getslicestr;
if (getslicestr == NULL) {
- getslicestr = PyString_InternFromString("__getslice__");
+ getslicestr = PyBytes_InternFromString("__getslice__");
if (getslicestr == NULL)
return NULL;
}
@@ -1166,7 +1166,7 @@ instance_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j)
PyErr_Clear();
if (getitemstr == NULL) {
- getitemstr = PyString_InternFromString("__getitem__");
+ getitemstr = PyBytes_InternFromString("__getitem__");
if (getitemstr == NULL)
return NULL;
}
@@ -1194,7 +1194,7 @@ instance_ass_item(PyInstanceObject *inst, Py_ssize_t i, PyObject *item)
if (item == NULL) {
if (delitemstr == NULL) {
- delitemstr = PyString_InternFromString("__delitem__");
+ delitemstr = PyBytes_InternFromString("__delitem__");
if (delitemstr == NULL)
return -1;
}
@@ -1202,7 +1202,7 @@ instance_ass_item(PyInstanceObject *inst, Py_ssize_t i, PyObject *item)
}
else {
if (setitemstr == NULL) {
- setitemstr = PyString_InternFromString("__setitem__");
+ setitemstr = PyBytes_InternFromString("__setitem__");
if (setitemstr == NULL)
return -1;
}
@@ -1236,7 +1236,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
if (value == NULL) {
if (delslicestr == NULL) {
delslicestr =
- PyString_InternFromString("__delslice__");
+ PyBytes_InternFromString("__delslice__");
if (delslicestr == NULL)
return -1;
}
@@ -1247,7 +1247,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
PyErr_Clear();
if (delitemstr == NULL) {
delitemstr =
- PyString_InternFromString("__delitem__");
+ PyBytes_InternFromString("__delitem__");
if (delitemstr == NULL)
return -1;
}
@@ -1263,7 +1263,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
else {
if (setslicestr == NULL) {
setslicestr =
- PyString_InternFromString("__setslice__");
+ PyBytes_InternFromString("__setslice__");
if (setslicestr == NULL)
return -1;
}
@@ -1274,7 +1274,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
PyErr_Clear();
if (setitemstr == NULL) {
setitemstr =
- PyString_InternFromString("__setitem__");
+ PyBytes_InternFromString("__setitem__");
if (setitemstr == NULL)
return -1;
}
@@ -1311,7 +1311,7 @@ instance_contains(PyInstanceObject *inst, PyObject *member)
*/
if(__contains__ == NULL) {
- __contains__ = PyString_InternFromString("__contains__");
+ __contains__ = PyBytes_InternFromString("__contains__");
if(__contains__ == NULL)
return -1;
}
@@ -1417,7 +1417,7 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc,
}
if (coerce_obj == NULL) {
- coerce_obj = PyString_InternFromString("__coerce__");
+ coerce_obj = PyBytes_InternFromString("__coerce__");
if (coerce_obj == NULL)
return NULL;
}
@@ -1504,7 +1504,7 @@ instance_coerce(PyObject **pv, PyObject **pw)
PyObject *coerced;
if (coerce_obj == NULL) {
- coerce_obj = PyString_InternFromString("__coerce__");
+ coerce_obj = PyBytes_InternFromString("__coerce__");
if (coerce_obj == NULL)
return -1;
}
@@ -1552,7 +1552,7 @@ instance_coerce(PyObject **pv, PyObject **pw)
#define UNARY(funcname, methodname) \
static PyObject *funcname(PyInstanceObject *self) { \
static PyObject *o; \
- if (o == NULL) { o = PyString_InternFromString(methodname); \
+ if (o == NULL) { o = PyBytes_InternFromString(methodname); \
if (o == NULL) return NULL; } \
return generic_unary_op(self, o); \
}
@@ -1561,7 +1561,7 @@ static PyObject *funcname(PyInstanceObject *self) { \
#define UNARY_FB(funcname, methodname, funcname_fb) \
static PyObject *funcname(PyInstanceObject *self) { \
static PyObject *o; \
- if (o == NULL) { o = PyString_InternFromString(methodname); \
+ if (o == NULL) { o = PyBytes_InternFromString(methodname); \
if (o == NULL) return NULL; } \
if (PyObject_HasAttr((PyObject*)self, o)) \
return generic_unary_op(self, o); \
@@ -1630,7 +1630,7 @@ half_cmp(PyObject *v, PyObject *w)
assert(PyInstance_Check(v));
if (cmp_obj == NULL) {
- cmp_obj = PyString_InternFromString("__cmp__");
+ cmp_obj = PyBytes_InternFromString("__cmp__");
if (cmp_obj == NULL)
return -2;
}
@@ -1738,7 +1738,7 @@ instance_nonzero(PyInstanceObject *self)
static PyObject *nonzerostr;
if (nonzerostr == NULL) {
- nonzerostr = PyString_InternFromString("__nonzero__");
+ nonzerostr = PyBytes_InternFromString("__nonzero__");
if (nonzerostr == NULL)
return -1;
}
@@ -1747,7 +1747,7 @@ instance_nonzero(PyInstanceObject *self)
return -1;
PyErr_Clear();
if (lenstr == NULL) {
- lenstr = PyString_InternFromString("__len__");
+ lenstr = PyBytes_InternFromString("__len__");
if (lenstr == NULL)
return -1;
}
@@ -1787,7 +1787,7 @@ instance_index(PyInstanceObject *self)
static PyObject *indexstr = NULL;
if (indexstr == NULL) {
- indexstr = PyString_InternFromString("__index__");
+ indexstr = PyBytes_InternFromString("__index__");
if (indexstr == NULL)
return NULL;
}
@@ -1814,7 +1814,7 @@ instance_int(PyInstanceObject *self)
PyObject *truncated;
static PyObject *int_name;
if (int_name == NULL) {
- int_name = PyString_InternFromString("__int__");
+ int_name = PyBytes_InternFromString("__int__");
if (int_name == NULL)
return NULL;
}
@@ -1929,7 +1929,7 @@ init_name_op(void)
if (name_op == NULL)
return -1;
for (i = 0; i < NAME_OPS; ++i) {
- name_op[i] = PyString_InternFromString(_name_op[i]);
+ name_op[i] = PyBytes_InternFromString(_name_op[i]);
if (name_op[i] == NULL)
return -1;
}
@@ -2012,12 +2012,12 @@ instance_getiter(PyInstanceObject *self)
PyObject *func;
if (iterstr == NULL) {
- iterstr = PyString_InternFromString("__iter__");
+ iterstr = PyBytes_InternFromString("__iter__");
if (iterstr == NULL)
return NULL;
}
if (getitemstr == NULL) {
- getitemstr = PyString_InternFromString("__getitem__");
+ getitemstr = PyBytes_InternFromString("__getitem__");
if (getitemstr == NULL)
return NULL;
}
@@ -2055,7 +2055,7 @@ instance_iternext(PyInstanceObject *self)
PyObject *func;
if (nextstr == NULL) {
- nextstr = PyString_InternFromString("next");
+ nextstr = PyBytes_InternFromString("next");
if (nextstr == NULL)
return NULL;
}
@@ -2087,7 +2087,7 @@ instance_call(PyObject *func, PyObject *arg, PyObject *kw)
PyErr_Clear();
PyErr_Format(PyExc_AttributeError,
"%.200s instance has no __call__ method",
- PyString_AsString(inst->in_class->cl_name));
+ PyBytes_AsString(inst->in_class->cl_name));
return NULL;
}
/* We must check and increment the recursion depth here. Scenario:
@@ -2261,7 +2261,7 @@ instancemethod_get_doc(PyMethodObject *im, void *context)
{
static PyObject *docstr;
if (docstr == NULL) {
- docstr= PyString_InternFromString("__doc__");
+ docstr= PyBytes_InternFromString("__doc__");
if (docstr == NULL)
return NULL;
}
@@ -2384,12 +2384,12 @@ instancemethod_repr(PyMethodObject *a)
return NULL;
PyErr_Clear();
}
- else if (!PyString_Check(funcname)) {
+ else if (!PyBytes_Check(funcname)) {
Py_DECREF(funcname);
funcname = NULL;
}
else
- sfuncname = PyString_AS_STRING(funcname);
+ sfuncname = PyBytes_AS_STRING(funcname);
if (klass == NULL)
klassname = NULL;
else {
@@ -2399,28 +2399,28 @@ instancemethod_repr(PyMethodObject *a)
return NULL;
PyErr_Clear();
}
- else if (!PyString_Check(klassname)) {
+ else if (!PyBytes_Check(klassname)) {
Py_DECREF(klassname);
klassname = NULL;
}
else
- sklassname = PyString_AS_STRING(klassname);
+ sklassname = PyBytes_AS_STRING(klassname);
}
if (self == NULL)
- result = PyString_FromFormat("<unbound method %s.%s>",
+ result = PyBytes_FromFormat("<unbound method %s.%s>",
sklassname, sfuncname);
else {
/* XXX Shouldn't use repr() here! */
PyObject *selfrepr = PyObject_Repr(self);
if (selfrepr == NULL)
goto fail;
- if (!PyString_Check(selfrepr)) {
+ if (!PyBytes_Check(selfrepr)) {
Py_DECREF(selfrepr);
goto fail;
}
- result = PyString_FromFormat("<bound method %s.%s of %s>",
+ result = PyBytes_FromFormat("<bound method %s.%s of %s>",
sklassname, sfuncname,
- PyString_AS_STRING(selfrepr));
+ PyBytes_AS_STRING(selfrepr));
Py_DECREF(selfrepr);
}
fail:
@@ -2472,8 +2472,8 @@ getclassname(PyObject *klass, char *buf, int bufsize)
PyErr_Clear();
return;
}
- if (PyString_Check(name)) {
- strncpy(buf, PyString_AS_STRING(name), bufsize);
+ if (PyBytes_Check(name)) {
+ strncpy(buf, PyBytes_AS_STRING(name), bufsize);
buf[bufsize-1] = '\0';
}
Py_DECREF(name);
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index e94b4cc..9892d9c 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -32,10 +32,10 @@ intern_strings(PyObject *tuple)
for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i);
- if (v == NULL || !PyString_CheckExact(v)) {
+ if (v == NULL || !PyBytes_CheckExact(v)) {
Py_FatalError("non-string found in code slot");
}
- PyString_InternInPlace(&PyTuple_GET_ITEM(tuple, i));
+ PyBytes_InternInPlace(&PyTuple_GET_ITEM(tuple, i));
}
}
@@ -57,9 +57,9 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
varnames == NULL || !PyTuple_Check(varnames) ||
freevars == NULL || !PyTuple_Check(freevars) ||
cellvars == NULL || !PyTuple_Check(cellvars) ||
- name == NULL || !PyString_Check(name) ||
- filename == NULL || !PyString_Check(filename) ||
- lnotab == NULL || !PyString_Check(lnotab) ||
+ name == NULL || !PyBytes_Check(name) ||
+ filename == NULL || !PyBytes_Check(filename) ||
+ lnotab == NULL || !PyBytes_Check(lnotab) ||
!PyObject_CheckReadBuffer(code)) {
PyErr_BadInternalCall();
return NULL;
@@ -71,11 +71,11 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
/* Intern selected string constants */
for (i = PyTuple_Size(consts); --i >= 0; ) {
PyObject *v = PyTuple_GetItem(consts, i);
- if (!PyString_Check(v))
+ if (!PyBytes_Check(v))
continue;
- if (!all_name_chars((unsigned char *)PyString_AS_STRING(v)))
+ if (!all_name_chars((unsigned char *)PyBytes_AS_STRING(v)))
continue;
- PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
+ PyBytes_InternInPlace(&PyTuple_GET_ITEM(consts, i));
}
co = PyObject_NEW(PyCodeObject, &PyCode_Type);
if (co != NULL) {
@@ -145,10 +145,10 @@ validate_and_copy_tuple(PyObject *tup)
for (i = 0; i < len; i++) {
item = PyTuple_GET_ITEM(tup, i);
- if (PyString_CheckExact(item)) {
+ if (PyBytes_CheckExact(item)) {
Py_INCREF(item);
}
- else if (!PyString_Check(item)) {
+ else if (!PyBytes_Check(item)) {
PyErr_Format(
PyExc_TypeError,
"name tuples must contain only "
@@ -158,9 +158,9 @@ validate_and_copy_tuple(PyObject *tup)
return NULL;
}
else {
- item = PyString_FromStringAndSize(
- PyString_AS_STRING(item),
- PyString_GET_SIZE(item));
+ item = PyBytes_FromStringAndSize(
+ PyBytes_AS_STRING(item),
+ PyBytes_GET_SIZE(item));
if (item == NULL) {
Py_DECREF(newtuple);
return NULL;
@@ -281,14 +281,14 @@ code_repr(PyCodeObject *co)
if (co->co_firstlineno != 0)
lineno = co->co_firstlineno;
- if (co->co_filename && PyString_Check(co->co_filename))
- filename = PyString_AS_STRING(co->co_filename);
- if (co->co_name && PyString_Check(co->co_name))
- name = PyString_AS_STRING(co->co_name);
+ if (co->co_filename && PyBytes_Check(co->co_filename))
+ filename = PyBytes_AS_STRING(co->co_filename);
+ if (co->co_name && PyBytes_Check(co->co_name))
+ name = PyBytes_AS_STRING(co->co_name);
PyOS_snprintf(buf, sizeof(buf),
"<code object %.100s at %p, file \"%.300s\", line %d>",
name, co, filename, lineno);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static int
@@ -508,8 +508,8 @@ was actually done until 2.2) expand 300, 300 to 255, 255, 45, 45, but to
int
PyCode_Addr2Line(PyCodeObject *co, int addrq)
{
- int size = PyString_Size(co->co_lnotab) / 2;
- unsigned char *p = (unsigned char*)PyString_AsString(co->co_lnotab);
+ int size = PyBytes_Size(co->co_lnotab) / 2;
+ unsigned char *p = (unsigned char*)PyBytes_AsString(co->co_lnotab);
int line = co->co_firstlineno;
int addr = 0;
while (--size >= 0) {
@@ -604,8 +604,8 @@ PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds)
int size, addr, line;
unsigned char* p;
- p = (unsigned char*)PyString_AS_STRING(co->co_lnotab);
- size = PyString_GET_SIZE(co->co_lnotab) / 2;
+ p = (unsigned char*)PyBytes_AS_STRING(co->co_lnotab);
+ size = PyBytes_GET_SIZE(co->co_lnotab) / 2;
addr = 0;
line = co->co_firstlineno;
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 6e0fbb2..e22c200 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -303,7 +303,7 @@ PyComplex_AsCComplex(PyObject *op)
cv.imag = 0.;
if (complex_str == NULL) {
- if (!(complex_str = PyString_InternFromString("__complex__")))
+ if (!(complex_str = PyBytes_InternFromString("__complex__")))
return cv;
}
@@ -421,7 +421,7 @@ complex_repr(PyComplexObject *v)
{
char buf[100];
complex_to_buf(buf, sizeof(buf), v, PREC_REPR);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyObject *
@@ -429,7 +429,7 @@ complex_str(PyComplexObject *v)
{
char buf[100];
complex_to_buf(buf, sizeof(buf), v, PREC_STR);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static long
@@ -876,9 +876,9 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
#endif
Py_ssize_t len;
- if (PyString_Check(v)) {
- s = PyString_AS_STRING(v);
- len = PyString_GET_SIZE(v);
+ if (PyBytes_Check(v)) {
+ s = PyBytes_AS_STRING(v);
+ len = PyBytes_GET_SIZE(v);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
@@ -1064,7 +1064,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_INCREF(r);
return r;
}
- if (PyString_Check(r) || PyUnicode_Check(r)) {
+ if (PyBytes_Check(r) || PyUnicode_Check(r)) {
if (i != NULL) {
PyErr_SetString(PyExc_TypeError,
"complex() can't take second arg"
@@ -1073,7 +1073,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
return complex_subtype_from_string(type, r);
}
- if (i != NULL && (PyString_Check(i) || PyUnicode_Check(i))) {
+ if (i != NULL && (PyBytes_Check(i) || PyUnicode_Check(i))) {
PyErr_SetString(PyExc_TypeError,
"complex() second arg can't be a string");
return NULL;
@@ -1081,7 +1081,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* XXX Hack to support classes with __complex__ method */
if (complexstr == NULL) {
- complexstr = PyString_InternFromString("__complex__");
+ complexstr = PyBytes_InternFromString("__complex__");
if (complexstr == NULL)
return NULL;
}
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index fcc174e..7cf5e62 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -15,8 +15,8 @@ descr_dealloc(PyDescrObject *descr)
static char *
descr_name(PyDescrObject *descr)
{
- if (descr->d_name != NULL && PyString_Check(descr->d_name))
- return PyString_AS_STRING(descr->d_name);
+ if (descr->d_name != NULL && PyBytes_Check(descr->d_name))
+ return PyBytes_AS_STRING(descr->d_name);
else
return "?";
}
@@ -24,7 +24,7 @@ descr_name(PyDescrObject *descr)
static PyObject *
descr_repr(PyDescrObject *descr, char *format)
{
- return PyString_FromFormat(format, descr_name(descr),
+ return PyBytes_FromFormat(format, descr_name(descr),
descr->d_type->tp_name);
}
@@ -314,7 +314,7 @@ method_get_doc(PyMethodDescrObject *descr, void *closure)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(descr->d_method->ml_doc);
+ return PyBytes_FromString(descr->d_method->ml_doc);
}
static PyMemberDef descr_members[] = {
@@ -335,7 +335,7 @@ member_get_doc(PyMemberDescrObject *descr, void *closure)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(descr->d_member->doc);
+ return PyBytes_FromString(descr->d_member->doc);
}
static PyGetSetDef member_getset[] = {
@@ -350,7 +350,7 @@ getset_get_doc(PyGetSetDescrObject *descr, void *closure)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(descr->d_getset->doc);
+ return PyBytes_FromString(descr->d_getset->doc);
}
static PyGetSetDef getset_getset[] = {
@@ -365,7 +365,7 @@ wrapperdescr_get_doc(PyWrapperDescrObject *descr, void *closure)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(descr->d_base->doc);
+ return PyBytes_FromString(descr->d_base->doc);
}
static PyGetSetDef wrapperdescr_getset[] = {
@@ -576,7 +576,7 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name)
if (descr != NULL) {
Py_XINCREF(type);
descr->d_type = type;
- descr->d_name = PyString_InternFromString(name);
+ descr->d_name = PyBytes_InternFromString(name);
if (descr->d_name == NULL) {
Py_DECREF(descr);
descr = NULL;
@@ -922,7 +922,7 @@ wrapper_hash(wrapperobject *wp)
static PyObject *
wrapper_repr(wrapperobject *wp)
{
- return PyString_FromFormat("<method-wrapper '%s' of %s object at %p>",
+ return PyBytes_FromFormat("<method-wrapper '%s' of %s object at %p>",
wp->descr->d_base->name,
wp->self->ob_type->tp_name,
wp->self);
@@ -947,7 +947,7 @@ wrapper_name(wrapperobject *wp)
{
char *s = wp->descr->d_base->name;
- return PyString_FromString(s);
+ return PyBytes_FromString(s);
}
static PyObject *
@@ -960,7 +960,7 @@ wrapper_doc(wrapperobject *wp)
return Py_None;
}
else {
- return PyString_FromString(s);
+ return PyBytes_FromString(s);
}
}
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 102ea98..cdf0dfa 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -224,7 +224,7 @@ PyDict_New(void)
{
register PyDictObject *mp;
if (dummy == NULL) { /* Auto-initialize dummy */
- dummy = PyString_FromString("<dummy key>");
+ dummy = PyBytes_FromString("<dummy key>");
if (dummy == NULL)
return NULL;
#ifdef SHOW_CONVERSION_COUNTS
@@ -373,7 +373,7 @@ lookdict(PyDictObject *mp, PyObject *key, register long hash)
* this assumption allows testing for errors during PyObject_RichCompareBool()
* to be dropped; string-string comparisons never raise exceptions. This also
* means we don't need to go through PyObject_RichCompareBool(); we can always
- * use _PyString_Eq() directly.
+ * use _PyBytes_Eq() directly.
*
* This is valuable because dicts with only string keys are very common.
*/
@@ -391,7 +391,7 @@ lookdict_string(PyDictObject *mp, PyObject *key, register long hash)
including subclasses of str; e.g., one reason to subclass
strings is to override __eq__, and for speed we don't cater to
that here. */
- if (!PyString_CheckExact(key)) {
+ if (!PyBytes_CheckExact(key)) {
#ifdef SHOW_CONVERSION_COUNTS
++converted;
#endif
@@ -405,7 +405,7 @@ lookdict_string(PyDictObject *mp, PyObject *key, register long hash)
if (ep->me_key == dummy)
freeslot = ep;
else {
- if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key))
+ if (ep->me_hash == hash && _PyBytes_Eq(ep->me_key, key))
return ep;
freeslot = NULL;
}
@@ -420,7 +420,7 @@ lookdict_string(PyDictObject *mp, PyObject *key, register long hash)
if (ep->me_key == key
|| (ep->me_hash == hash
&& ep->me_key != dummy
- && _PyString_Eq(ep->me_key, key)))
+ && _PyBytes_Eq(ep->me_key, key)))
return ep;
if (ep->me_key == dummy && freeslot == NULL)
freeslot = ep;
@@ -626,8 +626,8 @@ PyDict_GetItem(PyObject *op, PyObject *key)
PyThreadState *tstate;
if (!PyDict_Check(op))
return NULL;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1)
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1)
{
hash = PyObject_Hash(key);
if (hash == -1) {
@@ -680,8 +680,8 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
assert(key);
assert(value);
mp = (PyDictObject *)op;
- if (PyString_CheckExact(key)) {
- hash = ((PyStringObject *)key)->ob_shash;
+ if (PyBytes_CheckExact(key)) {
+ hash = ((PyBytesObject *)key)->ob_shash;
if (hash == -1)
hash = PyObject_Hash(key);
}
@@ -728,8 +728,8 @@ PyDict_DelItem(PyObject *op, PyObject *key)
return -1;
}
assert(key);
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -982,11 +982,11 @@ dict_repr(PyDictObject *mp)
i = Py_ReprEnter((PyObject *)mp);
if (i != 0) {
- return i > 0 ? PyString_FromString("{...}") : NULL;
+ return i > 0 ? PyBytes_FromString("{...}") : NULL;
}
if (mp->ma_used == 0) {
- result = PyString_FromString("{}");
+ result = PyBytes_FromString("{}");
goto Done;
}
@@ -994,7 +994,7 @@ dict_repr(PyDictObject *mp)
if (pieces == NULL)
goto Done;
- colon = PyString_FromString(": ");
+ colon = PyBytes_FromString(": ");
if (colon == NULL)
goto Done;
@@ -1006,8 +1006,8 @@ dict_repr(PyDictObject *mp)
/* Prevent repr from deleting value during key format. */
Py_INCREF(value);
s = PyObject_Repr(key);
- PyString_Concat(&s, colon);
- PyString_ConcatAndDel(&s, PyObject_Repr(value));
+ PyBytes_Concat(&s, colon);
+ PyBytes_ConcatAndDel(&s, PyObject_Repr(value));
Py_DECREF(value);
if (s == NULL)
goto Done;
@@ -1019,29 +1019,29 @@ dict_repr(PyDictObject *mp)
/* Add "{}" decorations to the first and last items. */
assert(PyList_GET_SIZE(pieces) > 0);
- s = PyString_FromString("{");
+ s = PyBytes_FromString("{");
if (s == NULL)
goto Done;
temp = PyList_GET_ITEM(pieces, 0);
- PyString_ConcatAndDel(&s, temp);
+ PyBytes_ConcatAndDel(&s, temp);
PyList_SET_ITEM(pieces, 0, s);
if (s == NULL)
goto Done;
- s = PyString_FromString("}");
+ s = PyBytes_FromString("}");
if (s == NULL)
goto Done;
temp = PyList_GET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1);
- PyString_ConcatAndDel(&temp, s);
+ PyBytes_ConcatAndDel(&temp, s);
PyList_SET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1, temp);
if (temp == NULL)
goto Done;
/* Paste them all together with ", " between. */
- s = PyString_FromString(", ");
+ s = PyBytes_FromString(", ");
if (s == NULL)
goto Done;
- result = _PyString_Join(s, pieces);
+ result = _PyBytes_Join(s, pieces);
Py_DECREF(s);
Done:
@@ -1064,8 +1064,8 @@ dict_subscript(PyDictObject *mp, register PyObject *key)
long hash;
PyDictEntry *ep;
assert(mp->ma_table != NULL);
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1081,7 +1081,7 @@ dict_subscript(PyDictObject *mp, register PyObject *key)
static PyObject *missing_str = NULL;
if (missing_str == NULL)
missing_str =
- PyString_InternFromString("__missing__");
+ PyBytes_InternFromString("__missing__");
missing = _PyType_Lookup(Py_TYPE(mp), missing_str);
if (missing != NULL)
return PyObject_CallFunctionObjArgs(missing,
@@ -1794,8 +1794,8 @@ dict_contains(register PyDictObject *mp, PyObject *key)
long hash;
PyDictEntry *ep;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1827,8 +1827,8 @@ dict_get(register PyDictObject *mp, PyObject *args)
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
return NULL;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1856,8 +1856,8 @@ dict_setdefault(register PyDictObject *mp, PyObject *args)
if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
return NULL;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1902,8 +1902,8 @@ dict_pop(PyDictObject *mp, PyObject *args)
"pop(): dictionary is empty");
return NULL;
}
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -2133,8 +2133,8 @@ PyDict_Contains(PyObject *op, PyObject *key)
PyDictObject *mp = (PyDictObject *)op;
PyDictEntry *ep;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -2260,7 +2260,7 @@ PyObject *
PyDict_GetItemString(PyObject *v, const char *key)
{
PyObject *kv, *rv;
- kv = PyString_FromString(key);
+ kv = PyBytes_FromString(key);
if (kv == NULL)
return NULL;
rv = PyDict_GetItem(v, kv);
@@ -2273,10 +2273,10 @@ PyDict_SetItemString(PyObject *v, const char *key, PyObject *item)
{
PyObject *kv;
int err;
- kv = PyString_FromString(key);
+ kv = PyBytes_FromString(key);
if (kv == NULL)
return -1;
- PyString_InternInPlace(&kv); /* XXX Should we really? */
+ PyBytes_InternInPlace(&kv); /* XXX Should we really? */
err = PyDict_SetItem(v, kv, item);
Py_DECREF(kv);
return err;
@@ -2287,7 +2287,7 @@ PyDict_DelItemString(PyObject *v, const char *key)
{
PyObject *kv;
int err;
- kv = PyString_FromString(key);
+ kv = PyBytes_FromString(key);
if (kv == NULL)
return -1;
err = PyDict_DelItem(v, kv);
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 48b47b0..085ef36 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -44,7 +44,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
- self->message = PyString_FromString("");
+ self->message = PyBytes_FromString("");
if (!self->message) {
Py_DECREF(self);
return NULL;
@@ -104,7 +104,7 @@ BaseException_str(PyBaseExceptionObject *self)
switch (PyTuple_GET_SIZE(self->args)) {
case 0:
- out = PyString_FromString("");
+ out = PyBytes_FromString("");
break;
case 1:
out = PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
@@ -133,13 +133,13 @@ BaseException_repr(PyBaseExceptionObject *self)
dot = strrchr(name, '.');
if (dot != NULL) name = dot+1;
- repr = PyString_FromString(name);
+ repr = PyBytes_FromString(name);
if (!repr) {
Py_DECREF(repr_suffix);
return NULL;
}
- PyString_ConcatAndDel(&repr, repr_suffix);
+ PyBytes_ConcatAndDel(&repr, repr_suffix);
return repr;
}
@@ -610,7 +610,7 @@ EnvironmentError_str(PyEnvironmentErrorObject *self)
PyObject *repr;
PyObject *tuple;
- fmt = PyString_FromString("[Errno %s] %s: %s");
+ fmt = PyBytes_FromString("[Errno %s] %s: %s");
if (!fmt)
return NULL;
@@ -645,7 +645,7 @@ EnvironmentError_str(PyEnvironmentErrorObject *self)
PyTuple_SET_ITEM(tuple, 2, repr);
- rtnval = PyString_Format(fmt, tuple);
+ rtnval = PyBytes_Format(fmt, tuple);
Py_DECREF(fmt);
Py_DECREF(tuple);
@@ -654,7 +654,7 @@ EnvironmentError_str(PyEnvironmentErrorObject *self)
PyObject *fmt;
PyObject *tuple;
- fmt = PyString_FromString("[Errno %s] %s");
+ fmt = PyBytes_FromString("[Errno %s] %s");
if (!fmt)
return NULL;
@@ -681,7 +681,7 @@ EnvironmentError_str(PyEnvironmentErrorObject *self)
PyTuple_SET_ITEM(tuple, 1, Py_None);
}
- rtnval = PyString_Format(fmt, tuple);
+ rtnval = PyBytes_Format(fmt, tuple);
Py_DECREF(fmt);
Py_DECREF(tuple);
@@ -841,7 +841,7 @@ WindowsError_str(PyWindowsErrorObject *self)
PyObject *repr;
PyObject *tuple;
- fmt = PyString_FromString("[Error %s] %s: %s");
+ fmt = PyBytes_FromString("[Error %s] %s: %s");
if (!fmt)
return NULL;
@@ -876,7 +876,7 @@ WindowsError_str(PyWindowsErrorObject *self)
PyTuple_SET_ITEM(tuple, 2, repr);
- rtnval = PyString_Format(fmt, tuple);
+ rtnval = PyBytes_Format(fmt, tuple);
Py_DECREF(fmt);
Py_DECREF(tuple);
@@ -885,7 +885,7 @@ WindowsError_str(PyWindowsErrorObject *self)
PyObject *fmt;
PyObject *tuple;
- fmt = PyString_FromString("[Error %s] %s");
+ fmt = PyBytes_FromString("[Error %s] %s");
if (!fmt)
return NULL;
@@ -912,7 +912,7 @@ WindowsError_str(PyWindowsErrorObject *self)
PyTuple_SET_ITEM(tuple, 1, Py_None);
}
- rtnval = PyString_Format(fmt, tuple);
+ rtnval = PyBytes_Format(fmt, tuple);
Py_DECREF(fmt);
Py_DECREF(tuple);
@@ -1109,21 +1109,21 @@ SyntaxError_str(PySyntaxErrorObject *self)
str = PyObject_Str(Py_None);
if (!str) return NULL;
/* Don't fiddle with non-string return (shouldn't happen anyway) */
- if (!PyString_Check(str)) return str;
+ if (!PyBytes_Check(str)) return str;
/* XXX -- do all the additional formatting with filename and
lineno here */
have_filename = (self->filename != NULL) &&
- PyString_Check(self->filename);
+ PyBytes_Check(self->filename);
have_lineno = (self->lineno != NULL) && PyInt_Check(self->lineno);
if (!have_filename && !have_lineno)
return str;
- bufsize = PyString_GET_SIZE(str) + 64;
+ bufsize = PyBytes_GET_SIZE(str) + 64;
if (have_filename)
- bufsize += PyString_GET_SIZE(self->filename);
+ bufsize += PyBytes_GET_SIZE(self->filename);
buffer = PyMem_MALLOC(bufsize);
if (buffer == NULL)
@@ -1131,19 +1131,19 @@ SyntaxError_str(PySyntaxErrorObject *self)
if (have_filename && have_lineno)
PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)",
- PyString_AS_STRING(str),
- my_basename(PyString_AS_STRING(self->filename)),
+ PyBytes_AS_STRING(str),
+ my_basename(PyBytes_AS_STRING(self->filename)),
PyInt_AsLong(self->lineno));
else if (have_filename)
PyOS_snprintf(buffer, bufsize, "%s (%s)",
- PyString_AS_STRING(str),
- my_basename(PyString_AS_STRING(self->filename)));
+ PyBytes_AS_STRING(str),
+ my_basename(PyBytes_AS_STRING(self->filename)));
else /* only have_lineno */
PyOS_snprintf(buffer, bufsize, "%s (line %ld)",
- PyString_AS_STRING(str),
+ PyBytes_AS_STRING(str),
PyInt_AsLong(self->lineno));
- result = PyString_FromString(buffer);
+ result = PyBytes_FromString(buffer);
PyMem_FREE(buffer);
if (result == NULL)
@@ -1250,7 +1250,7 @@ get_string(PyObject *attr, const char *name)
return NULL;
}
- if (!PyString_Check(attr)) {
+ if (!PyBytes_Check(attr)) {
PyErr_Format(PyExc_TypeError, "%.200s attribute must be str", name);
return NULL;
}
@@ -1262,7 +1262,7 @@ get_string(PyObject *attr, const char *name)
static int
set_string(PyObject **attr, const char *value)
{
- PyObject *obj = PyString_FromString(value);
+ PyObject *obj = PyBytes_FromString(value);
if (!obj)
return -1;
Py_CLEAR(*attr);
@@ -1345,7 +1345,7 @@ PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
"object");
if (!obj)
return -1;
- size = PyString_GET_SIZE(obj);
+ size = PyBytes_GET_SIZE(obj);
*start = ((PyUnicodeErrorObject *)exc)->start;
if (*start<0)
*start = 0;
@@ -1415,7 +1415,7 @@ PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
if (!obj)
return -1;
*end = ((PyUnicodeErrorObject *)exc)->end;
- size = PyString_GET_SIZE(obj);
+ size = PyBytes_GET_SIZE(obj);
if (*end<1)
*end = 1;
if (*end>size)
@@ -1506,11 +1506,11 @@ UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds,
Py_CLEAR(self->reason);
if (!PyArg_ParseTuple(args, "O!O!nnO!",
- &PyString_Type, &self->encoding,
+ &PyBytes_Type, &self->encoding,
objecttype, &self->object,
&self->start,
&self->end,
- &PyString_Type, &self->reason)) {
+ &PyBytes_Type, &self->reason)) {
self->encoding = self->object = self->reason = NULL;
return -1;
}
@@ -1590,20 +1590,20 @@ UnicodeEncodeError_str(PyObject *self)
PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar);
else
PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar);
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s",
- PyString_AS_STRING(uself->encoding),
+ PyBytes_AS_STRING(uself->encoding),
badchar_str,
uself->start,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"'%.400s' codec can't encode characters in position %zd-%zd: %.400s",
- PyString_AS_STRING(uself->encoding),
+ PyBytes_AS_STRING(uself->encoding),
uself->start,
uself->end-1,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
@@ -1642,7 +1642,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
return -1;
return UnicodeError_init((PyUnicodeErrorObject *)self, args,
- kwds, &PyString_Type);
+ kwds, &PyBytes_Type);
}
static PyObject *
@@ -1654,21 +1654,21 @@ UnicodeDecodeError_str(PyObject *self)
/* FromFormat does not support %02x, so format that separately */
char byte[4];
PyOS_snprintf(byte, sizeof(byte), "%02x",
- ((int)PyString_AS_STRING(uself->object)[uself->start])&0xff);
- return PyString_FromFormat(
+ ((int)PyBytes_AS_STRING(uself->object)[uself->start])&0xff);
+ return PyBytes_FromFormat(
"'%.400s' codec can't decode byte 0x%s in position %zd: %.400s",
- PyString_AS_STRING(uself->encoding),
+ PyBytes_AS_STRING(uself->encoding),
byte,
uself->start,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"'%.400s' codec can't decode bytes in position %zd-%zd: %.400s",
- PyString_AS_STRING(uself->encoding),
+ PyBytes_AS_STRING(uself->encoding),
uself->start,
uself->end-1,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
@@ -1718,7 +1718,7 @@ UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args,
&PyUnicode_Type, &self->object,
&self->start,
&self->end,
- &PyString_Type, &self->reason)) {
+ &PyBytes_Type, &self->reason)) {
self->object = self->reason = NULL;
return -1;
}
@@ -1744,18 +1744,18 @@ UnicodeTranslateError_str(PyObject *self)
PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar);
else
PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar);
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"can't translate character u'\\%s' in position %zd: %.400s",
badchar_str,
uself->start,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"can't translate characters in position %zd-%zd: %.400s",
uself->start,
uself->end-1,
- PyString_AS_STRING(uself->reason)
+ PyBytes_AS_STRING(uself->reason)
);
}
@@ -2111,7 +2111,7 @@ _PyExc_Init(void)
(PyBaseExceptionObject *)PyExc_RecursionErrorInst;
PyObject *args_tuple;
PyObject *exc_message;
- exc_message = PyString_FromString("maximum recursion depth exceeded");
+ exc_message = PyBytes_FromString("maximum recursion depth exceeded");
if (!exc_message)
Py_FatalError("cannot allocate argument for RuntimeError "
"pre-allocation");
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 4f8c46b..86f3a14 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -26,7 +26,7 @@
#include <io.h>
#endif
-#define BUF(v) PyString_AS_STRING((PyStringObject *)v)
+#define BUF(v) PyBytes_AS_STRING((PyBytesObject *)v)
#ifndef DONT_HAVE_ERRNO_H
#include <errno.h>
@@ -159,7 +159,7 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
Py_INCREF(name);
f->f_name = name;
- f->f_mode = PyString_FromString(mode);
+ f->f_mode = PyBytes_FromString(mode);
f->f_close = close;
f->f_softspace = 0;
@@ -367,7 +367,7 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type,
NULL, NULL);
if (f != NULL) {
- PyObject *o_name = PyString_FromString(name);
+ PyObject *o_name = PyBytes_FromString(name);
if (o_name == NULL)
return NULL;
if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
@@ -441,7 +441,7 @@ int
PyFile_SetEncoding(PyObject *f, const char *enc)
{
PyFileObject *file = (PyFileObject*)f;
- PyObject *str = PyString_FromString(enc);
+ PyObject *str = PyBytes_FromString(enc);
assert(PyFile_Check(f));
if (!str)
@@ -502,20 +502,20 @@ file_repr(PyFileObject *f)
#ifdef Py_USING_UNICODE
PyObject *ret = NULL;
PyObject *name = PyUnicode_AsUnicodeEscapeString(f->f_name);
- const char *name_str = name ? PyString_AsString(name) : "?";
- ret = PyString_FromFormat("<%s file u'%s', mode '%s' at %p>",
+ const char *name_str = name ? PyBytes_AsString(name) : "?";
+ ret = PyBytes_FromFormat("<%s file u'%s', mode '%s' at %p>",
f->f_fp == NULL ? "closed" : "open",
name_str,
- PyString_AsString(f->f_mode),
+ PyBytes_AsString(f->f_mode),
f);
Py_XDECREF(name);
return ret;
#endif
} else {
- return PyString_FromFormat("<%s file '%s', mode '%s' at %p>",
+ return PyBytes_FromFormat("<%s file '%s', mode '%s' at %p>",
f->f_fp == NULL ? "closed" : "open",
- PyString_AsString(f->f_name),
- PyString_AsString(f->f_mode),
+ PyBytes_AsString(f->f_name),
+ PyBytes_AsString(f->f_mode),
f);
}
}
@@ -935,7 +935,7 @@ file_read(PyFileObject *f, PyObject *args)
"requested number of bytes is more than a Python string can hold");
return NULL;
}
- v = PyString_FromStringAndSize((char *)NULL, buffersize);
+ v = PyBytes_FromStringAndSize((char *)NULL, buffersize);
if (v == NULL)
return NULL;
bytesread = 0;
@@ -966,7 +966,7 @@ file_read(PyFileObject *f, PyObject *args)
}
if (bytesrequested < 0) {
buffersize = new_buffersize(f, buffersize);
- if (_PyString_Resize(&v, buffersize) < 0)
+ if (_PyBytes_Resize(&v, buffersize) < 0)
return NULL;
} else {
/* Got what was requested. */
@@ -974,7 +974,7 @@ file_read(PyFileObject *f, PyObject *args)
}
}
if (bytesread != buffersize)
- _PyString_Resize(&v, bytesread);
+ _PyBytes_Resize(&v, bytesread);
return v;
}
@@ -1092,7 +1092,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
size_t increment; /* amount to increment the buffer */
size_t prev_v_size;
- /* Optimize for normal case: avoid _PyString_Resize if at all
+ /* Optimize for normal case: avoid _PyBytes_Resize if at all
* possible via first reading into stack buffer "buf".
*/
total_v_size = INITBUFSIZE; /* start small and pray */
@@ -1110,7 +1110,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
clearerr(fp);
if (PyErr_CheckSignals())
return NULL;
- v = PyString_FromStringAndSize(buf, pvfree - buf);
+ v = PyBytes_FromStringAndSize(buf, pvfree - buf);
return v;
}
/* fgets read *something* */
@@ -1139,7 +1139,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
assert(p > pvfree && *(p-1) == '\0');
--p; /* don't include \0 from fgets */
}
- v = PyString_FromStringAndSize(buf, p - buf);
+ v = PyBytes_FromStringAndSize(buf, p - buf);
return v;
}
/* yuck: fgets overwrote all the newlines, i.e. the entire
@@ -1160,7 +1160,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
* into its buffer.
*/
total_v_size = MAXBUFSIZE << 1;
- v = PyString_FromStringAndSize((char*)NULL, (int)total_v_size);
+ v = PyBytes_FromStringAndSize((char*)NULL, (int)total_v_size);
if (v == NULL)
return v;
/* copy over everything except the last null byte */
@@ -1215,13 +1215,13 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
Py_DECREF(v);
return NULL;
}
- if (_PyString_Resize(&v, (int)total_v_size) < 0)
+ if (_PyBytes_Resize(&v, (int)total_v_size) < 0)
return NULL;
/* overwrite the trailing null byte */
pvfree = BUF(v) + (prev_v_size - 1);
}
if (BUF(v) + total_v_size != p)
- _PyString_Resize(&v, p - BUF(v));
+ _PyBytes_Resize(&v, p - BUF(v));
return v;
#undef INITBUFSIZE
#undef MAXBUFSIZE
@@ -1253,7 +1253,7 @@ get_line(PyFileObject *f, int n)
return getline_via_fgets(f, fp);
#endif
total_v_size = n > 0 ? n : 100;
- v = PyString_FromStringAndSize((char *)NULL, total_v_size);
+ v = PyBytes_FromStringAndSize((char *)NULL, total_v_size);
if (v == NULL)
return NULL;
buf = BUF(v);
@@ -1326,7 +1326,7 @@ get_line(PyFileObject *f, int n)
Py_DECREF(v);
return NULL;
}
- if (_PyString_Resize(&v, total_v_size) < 0)
+ if (_PyBytes_Resize(&v, total_v_size) < 0)
return NULL;
buf = BUF(v) + used_v_size;
end = BUF(v) + total_v_size;
@@ -1334,7 +1334,7 @@ get_line(PyFileObject *f, int n)
used_v_size = buf - BUF(v);
if (used_v_size != total_v_size)
- _PyString_Resize(&v, used_v_size);
+ _PyBytes_Resize(&v, used_v_size);
return v;
}
@@ -1379,7 +1379,7 @@ PyFile_GetLine(PyObject *f, int n)
result = PyEval_CallObject(reader, args);
Py_DECREF(reader);
Py_DECREF(args);
- if (result != NULL && !PyString_Check(result) &&
+ if (result != NULL && !PyBytes_Check(result) &&
!PyUnicode_Check(result)) {
Py_DECREF(result);
result = NULL;
@@ -1388,9 +1388,9 @@ PyFile_GetLine(PyObject *f, int n)
}
}
- if (n < 0 && result != NULL && PyString_Check(result)) {
- char *s = PyString_AS_STRING(result);
- Py_ssize_t len = PyString_GET_SIZE(result);
+ if (n < 0 && result != NULL && PyBytes_Check(result)) {
+ char *s = PyBytes_AS_STRING(result);
+ Py_ssize_t len = PyBytes_GET_SIZE(result);
if (len == 0) {
Py_DECREF(result);
result = NULL;
@@ -1399,10 +1399,10 @@ PyFile_GetLine(PyObject *f, int n)
}
else if (s[len-1] == '\n') {
if (result->ob_refcnt == 1)
- _PyString_Resize(&result, len-1);
+ _PyBytes_Resize(&result, len-1);
else {
PyObject *v;
- v = PyString_FromStringAndSize(s, len-1);
+ v = PyBytes_FromStringAndSize(s, len-1);
Py_DECREF(result);
result = v;
}
@@ -1450,7 +1450,7 @@ file_readline(PyFileObject *f, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:readline", &n))
return NULL;
if (n == 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
if (n < 0)
n = 0;
return get_line(f, n);
@@ -1516,18 +1516,18 @@ file_readlines(PyFileObject *f, PyObject *args)
}
if (big_buffer == NULL) {
/* Create the big buffer */
- big_buffer = PyString_FromStringAndSize(
+ big_buffer = PyBytes_FromStringAndSize(
NULL, buffersize);
if (big_buffer == NULL)
goto error;
- buffer = PyString_AS_STRING(big_buffer);
+ buffer = PyBytes_AS_STRING(big_buffer);
memcpy(buffer, small_buffer, nfilled);
}
else {
/* Grow the big buffer */
- if ( _PyString_Resize(&big_buffer, buffersize) < 0 )
+ if ( _PyBytes_Resize(&big_buffer, buffersize) < 0 )
goto error;
- buffer = PyString_AS_STRING(big_buffer);
+ buffer = PyBytes_AS_STRING(big_buffer);
}
continue;
}
@@ -1536,7 +1536,7 @@ file_readlines(PyFileObject *f, PyObject *args)
do {
/* Process complete lines */
p++;
- line = PyString_FromStringAndSize(q, p-q);
+ line = PyBytes_FromStringAndSize(q, p-q);
if (line == NULL)
goto error;
err = PyList_Append(list, line);
@@ -1555,7 +1555,7 @@ file_readlines(PyFileObject *f, PyObject *args)
}
if (nfilled != 0) {
/* Partial last line */
- line = PyString_FromStringAndSize(buffer, nfilled);
+ line = PyBytes_FromStringAndSize(buffer, nfilled);
if (line == NULL)
goto error;
if (sizehint > 0) {
@@ -1565,7 +1565,7 @@ file_readlines(PyFileObject *f, PyObject *args)
Py_DECREF(line);
goto error;
}
- PyString_Concat(&line, rest);
+ PyBytes_Concat(&line, rest);
Py_DECREF(rest);
if (line == NULL)
goto error;
@@ -1672,7 +1672,7 @@ file_writelines(PyFileObject *f, PyObject *seq)
could potentially execute Python code. */
for (i = 0; i < j; i++) {
PyObject *v = PyList_GET_ITEM(list, i);
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
const char *buffer;
if (((f->f_binary &&
PyObject_AsReadBuffer(v,
@@ -1685,7 +1685,7 @@ file_writelines(PyFileObject *f, PyObject *seq)
"writelines() argument must be a sequence of strings");
goto error;
}
- line = PyString_FromStringAndSize(buffer,
+ line = PyBytes_FromStringAndSize(buffer,
len);
if (line == NULL)
goto error;
@@ -1701,8 +1701,8 @@ file_writelines(PyFileObject *f, PyObject *seq)
errno = 0;
for (i = 0; i < j; i++) {
line = PyList_GET_ITEM(list, i);
- len = PyString_GET_SIZE(line);
- nwritten = fwrite(PyString_AS_STRING(line),
+ len = PyBytes_GET_SIZE(line);
+ nwritten = fwrite(PyBytes_AS_STRING(line),
1, len, f->f_fp);
if (nwritten != len) {
FILE_ABORT_ALLOW_THREADS(f)
@@ -1896,13 +1896,13 @@ get_newlines(PyFileObject *f, void *closure)
Py_INCREF(Py_None);
return Py_None;
case NEWLINE_CR:
- return PyString_FromString("\r");
+ return PyBytes_FromString("\r");
case NEWLINE_LF:
- return PyString_FromString("\n");
+ return PyBytes_FromString("\n");
case NEWLINE_CR|NEWLINE_LF:
return Py_BuildValue("(ss)", "\r", "\n");
case NEWLINE_CRLF:
- return PyString_FromString("\r\n");
+ return PyBytes_FromString("\r\n");
case NEWLINE_CR|NEWLINE_CRLF:
return Py_BuildValue("(ss)", "\r", "\r\n");
case NEWLINE_LF|NEWLINE_CRLF:
@@ -2004,10 +2004,10 @@ readahead(PyFileObject *f, int bufsize)
horrified by the recursive call: maximum recursion depth is limited by
logarithmic buffer growth to about 50 even when reading a 1gb line. */
-static PyStringObject *
+static PyBytesObject *
readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
{
- PyStringObject* s;
+ PyBytesObject* s;
char *bufptr;
char *buf;
Py_ssize_t len;
@@ -2018,17 +2018,17 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
len = f->f_bufend - f->f_bufptr;
if (len == 0)
- return (PyStringObject *)
- PyString_FromStringAndSize(NULL, skip);
+ return (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, skip);
bufptr = (char *)memchr(f->f_bufptr, '\n', len);
if (bufptr != NULL) {
bufptr++; /* Count the '\n' */
len = bufptr - f->f_bufptr;
- s = (PyStringObject *)
- PyString_FromStringAndSize(NULL, skip+len);
+ s = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, skip+len);
if (s == NULL)
return NULL;
- memcpy(PyString_AS_STRING(s)+skip, f->f_bufptr, len);
+ memcpy(PyBytes_AS_STRING(s)+skip, f->f_bufptr, len);
f->f_bufptr = bufptr;
if (bufptr == f->f_bufend)
drop_readahead(f);
@@ -2043,7 +2043,7 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
PyMem_Free(buf);
return NULL;
}
- memcpy(PyString_AS_STRING(s)+skip, bufptr, len);
+ memcpy(PyBytes_AS_STRING(s)+skip, bufptr, len);
PyMem_Free(buf);
}
return s;
@@ -2055,13 +2055,13 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
static PyObject *
file_iternext(PyFileObject *f)
{
- PyStringObject* l;
+ PyBytesObject* l;
if (f->f_fp == NULL)
return err_closed();
l = readahead_get_line_skip(f, 0, READAHEAD_BUFSIZE);
- if (l == NULL || PyString_GET_SIZE(l) == 0) {
+ if (l == NULL || PyBytes_GET_SIZE(l) == 0) {
Py_XDECREF(l);
return NULL;
}
@@ -2078,7 +2078,7 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
assert(type != NULL && type->tp_alloc != NULL);
if (not_yet_string == NULL) {
- not_yet_string = PyString_InternFromString("<uninitialized file>");
+ not_yet_string = PyBytes_InternFromString("<uninitialized file>");
if (not_yet_string == NULL)
return NULL;
}
@@ -2294,7 +2294,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
#ifdef Py_USING_UNICODE
if ((flags & Py_PRINT_RAW) &&
PyUnicode_Check(v) && enc != Py_None) {
- char *cenc = PyString_AS_STRING(enc);
+ char *cenc = PyBytes_AS_STRING(enc);
value = PyUnicode_AsEncodedString(v, cenc, "strict");
if (value == NULL)
return -1;
@@ -2365,7 +2365,7 @@ PyFile_WriteString(const char *s, PyObject *f)
return 0;
}
else if (!PyErr_Occurred()) {
- PyObject *v = PyString_FromString(s);
+ PyObject *v = PyBytes_FromString(s);
int err;
if (v == NULL)
return -1;
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index ceb0b6d..3b49341 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -185,9 +185,9 @@ PyFloat_FromString(PyObject *v, char **pend)
if (pend)
*pend = NULL;
- if (PyString_Check(v)) {
- s = PyString_AS_STRING(v);
- len = PyString_GET_SIZE(v);
+ if (PyBytes_Check(v)) {
+ s = PyBytes_AS_STRING(v);
+ len = PyBytes_GET_SIZE(v);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
@@ -488,7 +488,7 @@ float_repr(PyFloatObject *v)
char buf[100];
format_float(buf, sizeof(buf), v, PREC_REPR);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyObject *
@@ -496,7 +496,7 @@ float_str(PyFloatObject *v)
{
char buf[100];
format_float(buf, sizeof(buf), v, PREC_STR);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
/* Comparison is pretty much a nightmare. When comparing float to float,
@@ -1221,7 +1221,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 (PyBytes_Check(x))
return PyFloat_FromString(x, NULL);
return PyNumber_Float(x);
}
@@ -1272,13 +1272,13 @@ float_getformat(PyTypeObject *v, PyObject* arg)
char* s;
float_format_type r;
- if (!PyString_Check(arg)) {
+ if (!PyBytes_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 = PyBytes_AS_STRING(arg);
if (strcmp(s, "double") == 0) {
r = double_format;
}
@@ -1294,11 +1294,11 @@ float_getformat(PyTypeObject *v, PyObject* arg)
switch (r) {
case unknown_format:
- return PyString_FromString("unknown");
+ return PyBytes_FromString("unknown");
case ieee_little_endian_format:
- return PyString_FromString("IEEE, little-endian");
+ return PyBytes_FromString("IEEE, little-endian");
case ieee_big_endian_format:
- return PyString_FromString("IEEE, big-endian");
+ return PyBytes_FromString("IEEE, big-endian");
default:
Py_FatalError("insane float_format or double_format");
return NULL;
@@ -1397,7 +1397,7 @@ float__format__(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
return NULL;
- if (PyString_Check(format_spec))
+ if (PyBytes_Check(format_spec))
return string_float__format__(self, args);
if (PyUnicode_Check(format_spec)) {
/* Convert format_spec to a str */
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 025431e..36c1fc2 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -114,7 +114,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
/* Find the bytecode offset for the start of the given line, or the
* first code-owning line after it. */
- PyString_AsStringAndSize(f->f_code->co_lnotab, &lnotab, &lnotab_len);
+ PyBytes_AsStringAndSize(f->f_code->co_lnotab, &lnotab, &lnotab_len);
addr = 0;
line = f->f_code->co_firstlineno;
new_lasti = -1;
@@ -137,7 +137,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
}
/* We're now ready to look at the bytecode. */
- PyString_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len);
+ PyBytes_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len);
min_addr = MIN(new_lasti, f->f_lasti);
max_addr = MAX(new_lasti, f->f_lasti);
@@ -548,7 +548,7 @@ static PyObject *builtin_object;
int _PyFrame_Init()
{
- builtin_object = PyString_InternFromString("__builtins__");
+ builtin_object = PyBytes_InternFromString("__builtins__");
return (builtin_object != NULL);
}
@@ -728,7 +728,7 @@ map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = values[j];
- assert(PyString_Check(key));
+ assert(PyBytes_Check(key));
if (deref) {
assert(PyCell_Check(value));
value = PyCell_GET(value);
@@ -776,7 +776,7 @@ dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = PyObject_GetItem(dict, key);
- assert(PyString_Check(key));
+ assert(PyBytes_Check(key));
/* We only care about NULLs if clear is true. */
if (value == NULL) {
PyErr_Clear();
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index a2e87b7..216b6da 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -28,7 +28,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
consts = ((PyCodeObject *)code)->co_consts;
if (PyTuple_Size(consts) >= 1) {
doc = PyTuple_GetItem(consts, 0);
- if (!PyString_Check(doc) && !PyUnicode_Check(doc))
+ if (!PyBytes_Check(doc) && !PyUnicode_Check(doc))
doc = Py_None;
}
else
@@ -42,7 +42,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
Otherwise, use None.
*/
if (!__name__) {
- __name__ = PyString_InternFromString("__name__");
+ __name__ = PyBytes_InternFromString("__name__");
if (!__name__) {
Py_DECREF(op);
return NULL;
@@ -254,7 +254,7 @@ func_set_code(PyFunctionObject *op, PyObject *value)
PyErr_Format(PyExc_ValueError,
"%s() requires a code object with %zd free vars,"
" not %zd",
- PyString_AsString(op->func_name),
+ PyBytes_AsString(op->func_name),
nclosure, nfree);
return -1;
}
@@ -281,7 +281,7 @@ func_set_name(PyFunctionObject *op, PyObject *value)
return -1;
/* Not legal to del f.func_name or to set it to anything
* other than a string object. */
- if (value == NULL || !PyString_Check(value)) {
+ if (value == NULL || !PyBytes_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"__name__ must be set to a string object");
return -1;
@@ -380,7 +380,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
&PyDict_Type, &globals,
&name, &defaults, &closure))
return NULL;
- if (name != Py_None && !PyString_Check(name)) {
+ if (name != Py_None && !PyBytes_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"arg 3 (name) must be None or string");
return NULL;
@@ -409,7 +409,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
if (nfree != nclosure)
return PyErr_Format(PyExc_ValueError,
"%s requires closure of length %zd, not %zd",
- PyString_AS_STRING(code->co_name),
+ PyBytes_AS_STRING(code->co_name),
nfree, nclosure);
if (nclosure) {
Py_ssize_t i;
@@ -465,8 +465,8 @@ func_dealloc(PyFunctionObject *op)
static PyObject*
func_repr(PyFunctionObject *op)
{
- return PyString_FromFormat("<function %s at %p>",
- PyString_AsString(op->func_name),
+ return PyBytes_FromFormat("<function %s at %p>",
+ PyBytes_AsString(op->func_name),
op);
}
diff --git a/Objects/genobject.c b/Objects/genobject.c
index d2ef508..b1c51a8 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -285,10 +285,10 @@ static PyObject *
gen_repr(PyGenObject *gen)
{
char *code_name;
- code_name = PyString_AsString(((PyCodeObject *)gen->gi_code)->co_name);
+ code_name = PyBytes_AsString(((PyCodeObject *)gen->gi_code)->co_name);
if (code_name == NULL)
return NULL;
- return PyString_FromFormat("<generator object %.200s at %p>",
+ return PyBytes_FromFormat("<generator object %.200s at %p>",
code_name, gen);
}
diff --git a/Objects/intobject.c b/Objects/intobject.c
index eacad9d..2af9451 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -368,7 +368,7 @@ PyInt_FromString(char *s, char **pend, int base)
if (*end != '\0') {
bad:
slen = strlen(s) < 200 ? strlen(s) : 200;
- sobj = PyString_FromStringAndSize(s, slen);
+ sobj = PyBytes_FromStringAndSize(s, slen);
if (sobj == NULL)
return NULL;
srepr = PyObject_Repr(sobj);
@@ -377,7 +377,7 @@ PyInt_FromString(char *s, char **pend, int base)
return NULL;
PyErr_Format(PyExc_ValueError,
"invalid literal for int() with base %d: %s",
- base, PyString_AS_STRING(srepr));
+ base, PyBytes_AS_STRING(srepr));
Py_DECREF(srepr);
return NULL;
}
@@ -965,11 +965,11 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return PyInt_FromLong(0L);
if (base == -909)
return PyNumber_Int(x);
- if (PyString_Check(x)) {
+ if (PyBytes_Check(x)) {
/* Since PyInt_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */
- char *string = PyString_AS_STRING(x);
- if (strlen(string) != PyString_Size(x)) {
+ char *string = PyBytes_AS_STRING(x);
+ if (strlen(string) != PyBytes_Size(x)) {
/* create a repr() of the input string,
* just like PyInt_FromString does */
PyObject *srepr;
@@ -978,7 +978,7 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
PyErr_Format(PyExc_ValueError,
"invalid literal for int() with base %d: %s",
- base, PyString_AS_STRING(srepr));
+ base, PyBytes_AS_STRING(srepr));
Py_DECREF(srepr);
return NULL;
}
@@ -1106,7 +1106,7 @@ _PyInt_Format(PyIntObject *v, int base, int newstyle)
if (negative)
*--p = '-';
- return PyString_FromStringAndSize(p, &buf[sizeof(buf)] - p);
+ return PyBytes_FromStringAndSize(p, &buf[sizeof(buf)] - p);
}
static PyObject *
@@ -1116,7 +1116,7 @@ int__format__(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
return NULL;
- if (PyString_Check(format_spec))
+ if (PyBytes_Check(format_spec))
return string_int__format__(self, args);
if (PyUnicode_Check(format_spec)) {
/* Convert format_spec to a str */
diff --git a/Objects/listobject.c b/Objects/listobject.c
index ee2fda1..9d742d8 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -174,7 +174,7 @@ PyList_GetItem(PyObject *op, Py_ssize_t i)
}
if (i < 0 || i >= Py_SIZE(op)) {
if (indexerr == NULL)
- indexerr = PyString_FromString(
+ indexerr = PyBytes_FromString(
"list index out of range");
PyErr_SetObject(PyExc_IndexError, indexerr);
return NULL;
@@ -349,11 +349,11 @@ list_repr(PyListObject *v)
i = Py_ReprEnter((PyObject*)v);
if (i != 0) {
- return i > 0 ? PyString_FromString("[...]") : NULL;
+ return i > 0 ? PyBytes_FromString("[...]") : NULL;
}
if (Py_SIZE(v) == 0) {
- result = PyString_FromString("[]");
+ result = PyBytes_FromString("[]");
goto Done;
}
@@ -379,29 +379,29 @@ list_repr(PyListObject *v)
/* Add "[]" decorations to the first and last items. */
assert(PyList_GET_SIZE(pieces) > 0);
- s = PyString_FromString("[");
+ s = PyBytes_FromString("[");
if (s == NULL)
goto Done;
temp = PyList_GET_ITEM(pieces, 0);
- PyString_ConcatAndDel(&s, temp);
+ PyBytes_ConcatAndDel(&s, temp);
PyList_SET_ITEM(pieces, 0, s);
if (s == NULL)
goto Done;
- s = PyString_FromString("]");
+ s = PyBytes_FromString("]");
if (s == NULL)
goto Done;
temp = PyList_GET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1);
- PyString_ConcatAndDel(&temp, s);
+ PyBytes_ConcatAndDel(&temp, s);
PyList_SET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1, temp);
if (temp == NULL)
goto Done;
/* Paste them all together with ", " between. */
- s = PyString_FromString(", ");
+ s = PyBytes_FromString(", ");
if (s == NULL)
goto Done;
- result = _PyString_Join(s, pieces);
+ result = _PyBytes_Join(s, pieces);
Py_DECREF(s);
Done:
@@ -433,7 +433,7 @@ list_item(PyListObject *a, Py_ssize_t i)
{
if (i < 0 || i >= Py_SIZE(a)) {
if (indexerr == NULL)
- indexerr = PyString_FromString(
+ indexerr = PyBytes_FromString(
"list index out of range");
PyErr_SetObject(PyExc_IndexError, indexerr);
return NULL;
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 7fc4576..5922aa5 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1200,7 +1200,7 @@ PyAPI_FUNC(PyObject *)
_PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
{
register PyLongObject *a = (PyLongObject *)aa;
- PyStringObject *str;
+ PyBytesObject *str;
Py_ssize_t i, j, sz;
Py_ssize_t size_a;
char *p;
@@ -1229,10 +1229,10 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
"long is too large to format");
return NULL;
}
- str = (PyStringObject *) PyString_FromStringAndSize((char *)0, sz);
+ str = (PyBytesObject *) PyBytes_FromStringAndSize((char *)0, sz);
if (str == NULL)
return NULL;
- p = PyString_AS_STRING(str) + sz;
+ p = PyBytes_AS_STRING(str) + sz;
*p = '\0';
if (addL)
*--p = 'L';
@@ -1258,7 +1258,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
do {
char cdigit = (char)(accum & (base - 1));
cdigit += (cdigit < 10) ? '0' : 'a'-10;
- assert(p > PyString_AS_STRING(str));
+ assert(p > PyBytes_AS_STRING(str));
*--p = cdigit;
accumbits -= basebits;
accum >>= basebits;
@@ -1310,7 +1310,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
do {
digit nextrem = (digit)(rem / base);
char c = (char)(rem - nextrem * base);
- assert(p > PyString_AS_STRING(str));
+ assert(p > PyBytes_AS_STRING(str));
c += (c < 10) ? '0' : 'a'-10;
*--p = c;
rem = nextrem;
@@ -1348,14 +1348,14 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
}
if (sign)
*--p = sign;
- if (p != PyString_AS_STRING(str)) {
- char *q = PyString_AS_STRING(str);
+ if (p != PyBytes_AS_STRING(str)) {
+ char *q = PyBytes_AS_STRING(str);
assert(p > q);
do {
} while ((*q++ = *p++) != '\0');
q--;
- _PyString_Resize((PyObject **)&str,
- (Py_ssize_t) (q - PyString_AS_STRING(str)));
+ _PyBytes_Resize((PyObject **)&str,
+ (Py_ssize_t) (q - PyBytes_AS_STRING(str)));
}
return (PyObject *)str;
}
@@ -1719,7 +1719,7 @@ digit beyond the first.
onError:
Py_XDECREF(z);
slen = strlen(orig_str) < 200 ? strlen(orig_str) : 200;
- strobj = PyString_FromStringAndSize(orig_str, slen);
+ strobj = PyBytes_FromStringAndSize(orig_str, slen);
if (strobj == NULL)
return NULL;
strrepr = PyObject_Repr(strobj);
@@ -1728,7 +1728,7 @@ digit beyond the first.
return NULL;
PyErr_Format(PyExc_ValueError,
"invalid literal for long() with base %d: %s",
- base, PyString_AS_STRING(strrepr));
+ base, PyBytes_AS_STRING(strrepr));
Py_DECREF(strrepr);
return NULL;
}
@@ -3332,11 +3332,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return PyLong_FromLong(0L);
if (base == -909)
return PyNumber_Long(x);
- else if (PyString_Check(x)) {
+ else if (PyBytes_Check(x)) {
/* Since PyLong_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */
- char *string = PyString_AS_STRING(x);
- if (strlen(string) != PyString_Size(x)) {
+ char *string = PyBytes_AS_STRING(x);
+ if (strlen(string) != PyBytes_Size(x)) {
/* create a repr() of the input string,
* just like PyLong_FromString does. */
PyObject *srepr;
@@ -3345,11 +3345,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
PyErr_Format(PyExc_ValueError,
"invalid literal for long() with base %d: %s",
- base, PyString_AS_STRING(srepr));
+ base, PyBytes_AS_STRING(srepr));
Py_DECREF(srepr);
return NULL;
}
- return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
+ return PyLong_FromString(PyBytes_AS_STRING(x), NULL, base);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(x))
@@ -3414,7 +3414,7 @@ long__format__(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
return NULL;
- if (PyString_Check(format_spec))
+ if (PyBytes_Check(format_spec))
return string_long__format__(self, args);
if (PyUnicode_Check(format_spec)) {
/* Convert format_spec to a str */
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 737a3f7..57ab5c5 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -149,7 +149,7 @@ meth_get__doc__(PyCFunctionObject *m, void *closure)
const char *doc = m->m_ml->ml_doc;
if (doc != NULL)
- return PyString_FromString(doc);
+ return PyBytes_FromString(doc);
Py_INCREF(Py_None);
return Py_None;
}
@@ -157,7 +157,7 @@ meth_get__doc__(PyCFunctionObject *m, void *closure)
static PyObject *
meth_get__name__(PyCFunctionObject *m, void *closure)
{
- return PyString_FromString(m->m_ml->ml_name);
+ return PyBytes_FromString(m->m_ml->ml_name);
}
static int
@@ -202,9 +202,9 @@ static PyObject *
meth_repr(PyCFunctionObject *m)
{
if (m->m_self == NULL)
- return PyString_FromFormat("<built-in function %s>",
+ return PyBytes_FromFormat("<built-in function %s>",
m->m_ml->ml_name);
- return PyString_FromFormat("<built-in method %s of %s object at %p>",
+ return PyBytes_FromFormat("<built-in method %s of %s object at %p>",
m->m_ml->ml_name,
m->m_self->ob_type->tp_name,
m->m_self);
@@ -333,7 +333,7 @@ listmethodchain(PyMethodChain *chain)
i = 0;
for (c = chain; c != NULL; c = c->link) {
for (ml = c->methods; ml->ml_name != NULL; ml++) {
- PyList_SetItem(v, i, PyString_FromString(ml->ml_name));
+ PyList_SetItem(v, i, PyBytes_FromString(ml->ml_name));
i++;
}
}
@@ -360,7 +360,7 @@ Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
if (strcmp(name, "__doc__") == 0) {
const char *doc = self->ob_type->tp_doc;
if (doc != NULL)
- return PyString_FromString(doc);
+ return PyBytes_FromString(doc);
}
}
while (chain != NULL) {
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index d1aa771..fa3daa9 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -22,7 +22,7 @@ PyModule_New(const char *name)
m = PyObject_GC_New(PyModuleObject, &PyModule_Type);
if (m == NULL)
return NULL;
- nameobj = PyString_FromString(name);
+ nameobj = PyBytes_FromString(name);
m->md_dict = PyDict_New();
if (m->md_dict == NULL || nameobj == NULL)
goto fail;
@@ -68,12 +68,12 @@ PyModule_GetName(PyObject *m)
d = ((PyModuleObject *)m)->md_dict;
if (d == NULL ||
(nameobj = PyDict_GetItemString(d, "__name__")) == NULL ||
- !PyString_Check(nameobj))
+ !PyBytes_Check(nameobj))
{
PyErr_SetString(PyExc_SystemError, "nameless module");
return NULL;
}
- return PyString_AsString(nameobj);
+ return PyBytes_AsString(nameobj);
}
char *
@@ -88,12 +88,12 @@ PyModule_GetFilename(PyObject *m)
d = ((PyModuleObject *)m)->md_dict;
if (d == NULL ||
(fileobj = PyDict_GetItemString(d, "__file__")) == NULL ||
- !PyString_Check(fileobj))
+ !PyBytes_Check(fileobj))
{
PyErr_SetString(PyExc_SystemError, "module filename missing");
return NULL;
}
- return PyString_AsString(fileobj);
+ return PyBytes_AsString(fileobj);
}
void
@@ -117,8 +117,8 @@ _PyModule_Clear(PyObject *m)
/* First, clear only names starting with a single underscore */
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
- if (value != Py_None && PyString_Check(key)) {
- char *s = PyString_AsString(key);
+ if (value != Py_None && PyBytes_Check(key)) {
+ char *s = PyBytes_AsString(key);
if (s[0] == '_' && s[1] != '_') {
if (Py_VerboseFlag > 1)
PySys_WriteStderr("# clear[1] %s\n", s);
@@ -130,8 +130,8 @@ _PyModule_Clear(PyObject *m)
/* Next, clear all names except for __builtins__ */
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
- if (value != Py_None && PyString_Check(key)) {
- char *s = PyString_AsString(key);
+ if (value != Py_None && PyBytes_Check(key)) {
+ char *s = PyBytes_AsString(key);
if (s[0] != '_' || strcmp(s, "__builtins__") != 0) {
if (Py_VerboseFlag > 1)
PySys_WriteStderr("# clear[2] %s\n", s);
@@ -195,9 +195,9 @@ module_repr(PyModuleObject *m)
filename = PyModule_GetFilename((PyObject *)m);
if (filename == NULL) {
PyErr_Clear();
- return PyString_FromFormat("<module '%s' (built-in)>", name);
+ return PyBytes_FromFormat("<module '%s' (built-in)>", name);
}
- return PyString_FromFormat("<module '%s' from '%s'>", name, filename);
+ return PyBytes_FromFormat("<module '%s' from '%s'>", name, filename);
}
/* We only need a traverse function, no clear function: If the module
diff --git a/Objects/object.c b/Objects/object.c
index ccb5ab7..8f9d731 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -357,9 +357,9 @@ PyObject_Repr(PyObject *v)
}
#endif
if (v == NULL)
- return PyString_FromString("<NULL>");
+ return PyBytes_FromString("<NULL>");
else if (Py_TYPE(v)->tp_repr == NULL)
- return PyString_FromFormat("<%s object at %p>",
+ return PyBytes_FromFormat("<%s object at %p>",
Py_TYPE(v)->tp_name, v);
else {
PyObject *res;
@@ -377,7 +377,7 @@ PyObject_Repr(PyObject *v)
return NULL;
}
#endif
- if (!PyString_Check(res)) {
+ if (!PyBytes_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__repr__ returned non-string (type %.200s)",
Py_TYPE(res)->tp_name);
@@ -394,8 +394,8 @@ _PyObject_Str(PyObject *v)
PyObject *res;
int type_ok;
if (v == NULL)
- return PyString_FromString("<NULL>");
- if (PyString_CheckExact(v)) {
+ return PyBytes_FromString("<NULL>");
+ if (PyBytes_CheckExact(v)) {
Py_INCREF(v);
return v;
}
@@ -416,7 +416,7 @@ _PyObject_Str(PyObject *v)
Py_LeaveRecursiveCall();
if (res == NULL)
return NULL;
- type_ok = PyString_Check(res);
+ type_ok = PyBytes_Check(res);
#ifdef Py_USING_UNICODE
type_ok = type_ok || PyUnicode_Check(res);
#endif
@@ -447,7 +447,7 @@ PyObject_Str(PyObject *v)
return NULL;
}
#endif
- assert(PyString_Check(res));
+ assert(PyBytes_Check(res));
return res;
}
@@ -461,7 +461,7 @@ PyObject_Unicode(PyObject *v)
static PyObject *unicodestr;
if (v == NULL) {
- res = PyString_FromString("<NULL>");
+ res = PyBytes_FromString("<NULL>");
if (res == NULL)
return NULL;
str = PyUnicode_FromEncodedObject(res, NULL, "strict");
@@ -475,7 +475,7 @@ PyObject_Unicode(PyObject *v)
check this before trying the __unicode__
method. */
if (unicodestr == NULL) {
- unicodestr= PyString_InternFromString("__unicode__");
+ unicodestr= PyBytes_InternFromString("__unicode__");
if (unicodestr == NULL)
return NULL;
}
@@ -492,7 +492,7 @@ PyObject_Unicode(PyObject *v)
return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
PyUnicode_GET_SIZE(v));
}
- if (PyString_CheckExact(v)) {
+ if (PyBytes_CheckExact(v)) {
Py_INCREF(v);
res = v;
}
@@ -1084,7 +1084,7 @@ PyObject_GetAttrString(PyObject *v, const char *name)
if (Py_TYPE(v)->tp_getattr != NULL)
return (*Py_TYPE(v)->tp_getattr)(v, (char*)name);
- w = PyString_InternFromString(name);
+ w = PyBytes_InternFromString(name);
if (w == NULL)
return NULL;
res = PyObject_GetAttr(v, w);
@@ -1112,7 +1112,7 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
if (Py_TYPE(v)->tp_setattr != NULL)
return (*Py_TYPE(v)->tp_setattr)(v, (char*)name, w);
- s = PyString_InternFromString(name);
+ s = PyBytes_InternFromString(name);
if (s == NULL)
return -1;
res = PyObject_SetAttr(v, s, w);
@@ -1125,7 +1125,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
{
PyTypeObject *tp = Py_TYPE(v);
- if (!PyString_Check(name)) {
+ if (!PyBytes_Check(name)) {
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_getattro slots expect a string object as name
@@ -1147,10 +1147,10 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL)
- return (*tp->tp_getattr)(v, PyString_AS_STRING(name));
+ return (*tp->tp_getattr)(v, PyBytes_AS_STRING(name));
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'",
- tp->tp_name, PyString_AS_STRING(name));
+ tp->tp_name, PyBytes_AS_STRING(name));
return NULL;
}
@@ -1172,7 +1172,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyTypeObject *tp = Py_TYPE(v);
int err;
- if (!PyString_Check(name)){
+ if (!PyBytes_Check(name)){
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
@@ -1194,14 +1194,14 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
else
Py_INCREF(name);
- PyString_InternInPlace(&name);
+ PyBytes_InternInPlace(&name);
if (tp->tp_setattro != NULL) {
err = (*tp->tp_setattro)(v, name, value);
Py_DECREF(name);
return err;
}
if (tp->tp_setattr != NULL) {
- err = (*tp->tp_setattr)(v, PyString_AS_STRING(name), value);
+ err = (*tp->tp_setattr)(v, PyBytes_AS_STRING(name), value);
Py_DECREF(name);
return err;
}
@@ -1212,14 +1212,14 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
"(%s .%.100s)",
tp->tp_name,
value==NULL ? "del" : "assign to",
- PyString_AS_STRING(name));
+ PyBytes_AS_STRING(name));
else
PyErr_Format(PyExc_TypeError,
"'%.100s' object has only read-only attributes "
"(%s .%.100s)",
tp->tp_name,
value==NULL ? "del" : "assign to",
- PyString_AS_STRING(name));
+ PyBytes_AS_STRING(name));
return -1;
}
@@ -1271,7 +1271,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
Py_ssize_t dictoffset;
PyObject **dictptr;
- if (!PyString_Check(name)){
+ if (!PyBytes_Check(name)){
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
@@ -1386,7 +1386,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'",
- tp->tp_name, PyString_AS_STRING(name));
+ tp->tp_name, PyBytes_AS_STRING(name));
done:
Py_DECREF(name);
return res;
@@ -1401,7 +1401,7 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
PyObject **dictptr;
int res = -1;
- if (!PyString_Check(name)){
+ if (!PyBytes_Check(name)){
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
@@ -1469,13 +1469,13 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
if (descr == NULL) {
PyErr_Format(PyExc_AttributeError,
"'%.100s' object has no attribute '%.200s'",
- tp->tp_name, PyString_AS_STRING(name));
+ tp->tp_name, PyBytes_AS_STRING(name));
goto done;
}
PyErr_Format(PyExc_AttributeError,
"'%.50s' object attribute '%.400s' is read-only",
- tp->tp_name, PyString_AS_STRING(name));
+ tp->tp_name, PyBytes_AS_STRING(name));
done:
Py_DECREF(name);
return res;
@@ -1682,7 +1682,7 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
int i;
for (i = 0; i < PyList_GET_SIZE(list); ++i) {
PyObject *item = PyList_GET_ITEM(list, i);
- if (PyString_Check(item)) {
+ if (PyBytes_Check(item)) {
result = PyDict_SetItem(dict, item, Py_None);
if (result < 0)
break;
@@ -1904,7 +1904,7 @@ so there is exactly one (which is indestructible, by the way).
static PyObject *
none_repr(PyObject *op)
{
- return PyString_FromString("None");
+ return PyBytes_FromString("None");
}
/* ARGUSED */
@@ -1946,7 +1946,7 @@ PyObject _Py_NoneStruct = {
static PyObject *
NotImplemented_repr(PyObject *op)
{
- return PyString_FromString("NotImplemented");
+ return PyBytes_FromString("NotImplemented");
}
static PyTypeObject PyNotImplemented_Type = {
@@ -1983,7 +1983,7 @@ _Py_ReadyTypes(void)
if (PyType_Ready(&PyBool_Type) < 0)
Py_FatalError("Can't initialize 'bool'");
- if (PyType_Ready(&PyString_Type) < 0)
+ if (PyType_Ready(&PyBytes_Type) < 0)
Py_FatalError("Can't initialize 'str'");
if (PyType_Ready(&PyByteArray_Type) < 0)
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index da4356b..b3ed673 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -113,16 +113,16 @@ range_repr(rangeobject *r)
PyObject *rtn;
if (r->start == 0 && r->step == 1)
- rtn = PyString_FromFormat("xrange(%ld)",
+ rtn = PyBytes_FromFormat("xrange(%ld)",
r->start + r->len * r->step);
else if (r->step == 1)
- rtn = PyString_FromFormat("xrange(%ld, %ld)",
+ rtn = PyBytes_FromFormat("xrange(%ld, %ld)",
r->start,
r->start + r->len * r->step);
else
- rtn = PyString_FromFormat("xrange(%ld, %ld, %ld)",
+ rtn = PyBytes_FromFormat("xrange(%ld, %ld, %ld)",
r->start,
r->start + r->len * r->step,
r->step);
diff --git a/Objects/setobject.c b/Objects/setobject.c
index b379845..f63aa75 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -147,7 +147,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
/*
* Hacked up version of set_lookkey which can assume keys are always strings;
- * This means we can always use _PyString_Eq directly and not have to check to
+ * This means we can always use _PyBytes_Eq directly and not have to check to
* see if the comparison altered the table.
*/
static setentry *
@@ -164,7 +164,7 @@ set_lookkey_string(PySetObject *so, PyObject *key, register long hash)
including subclasses of str; e.g., one reason to subclass
strings is to override __eq__, and for speed we don't cater to
that here. */
- if (!PyString_CheckExact(key)) {
+ if (!PyBytes_CheckExact(key)) {
so->lookup = set_lookkey;
return set_lookkey(so, key, hash);
}
@@ -175,7 +175,7 @@ set_lookkey_string(PySetObject *so, PyObject *key, register long hash)
if (entry->key == dummy)
freeslot = entry;
else {
- if (entry->hash == hash && _PyString_Eq(entry->key, key))
+ if (entry->hash == hash && _PyBytes_Eq(entry->key, key))
return entry;
freeslot = NULL;
}
@@ -190,7 +190,7 @@ set_lookkey_string(PySetObject *so, PyObject *key, register long hash)
if (entry->key == key
|| (entry->hash == hash
&& entry->key != dummy
- && _PyString_Eq(entry->key, key)))
+ && _PyBytes_Eq(entry->key, key)))
return entry;
if (entry->key == dummy && freeslot == NULL)
freeslot = entry;
@@ -377,8 +377,8 @@ set_add_key(register PySetObject *so, PyObject *key)
register long hash;
register Py_ssize_t n_used;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -424,8 +424,8 @@ set_discard_key(PySetObject *so, PyObject *key)
PyObject *old_key;
assert (PyAnySet_Check(so));
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -614,7 +614,7 @@ set_repr(PySetObject *so)
if (status != 0) {
if (status < 0)
return NULL;
- return PyString_FromFormat("%s(...)", so->ob_type->tp_name);
+ return PyBytes_FromFormat("%s(...)", so->ob_type->tp_name);
}
keys = PySequence_List((PyObject *)so);
@@ -625,8 +625,8 @@ set_repr(PySetObject *so)
if (listrepr == NULL)
goto done;
- result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
- PyString_AS_STRING(listrepr));
+ result = PyBytes_FromFormat("%s(%s)", so->ob_type->tp_name,
+ PyBytes_AS_STRING(listrepr));
Py_DECREF(listrepr);
done:
Py_ReprLeave((PyObject*)so);
@@ -681,8 +681,8 @@ set_contains_key(PySetObject *so, PyObject *key)
long hash;
setentry *entry;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyBytes_CheckExact(key) ||
+ (hash = ((PyBytesObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -979,7 +979,7 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
register PySetObject *so = NULL;
if (dummy == NULL) { /* Auto-initialize dummy */
- dummy = PyString_FromString("<dummy key>");
+ dummy = PyBytes_FromString("<dummy key>");
if (dummy == NULL)
return NULL;
}
@@ -2318,7 +2318,7 @@ test_c_api(PySetObject *so)
/* Exercise direct iteration */
i = 0, count = 0;
while (_PySet_Next((PyObject *)dup, &i, &x)) {
- s = PyString_AsString(x);
+ s = PyBytes_AsString(x);
assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
count++;
}
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 075418e..75048e3 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -19,7 +19,7 @@ this type and there is exactly one in existence.
static PyObject *
ellipsis_repr(PyObject *op)
{
- return PyString_FromString("Ellipsis");
+ return PyBytes_FromString("Ellipsis");
}
static PyTypeObject PyEllipsis_Type = {
@@ -228,14 +228,14 @@ slice_repr(PySliceObject *r)
{
PyObject *s, *comma;
- s = PyString_FromString("slice(");
- comma = PyString_FromString(", ");
- PyString_ConcatAndDel(&s, PyObject_Repr(r->start));
- PyString_Concat(&s, comma);
- PyString_ConcatAndDel(&s, PyObject_Repr(r->stop));
- PyString_Concat(&s, comma);
- PyString_ConcatAndDel(&s, PyObject_Repr(r->step));
- PyString_ConcatAndDel(&s, PyString_FromString(")"));
+ s = PyBytes_FromString("slice(");
+ comma = PyBytes_FromString(", ");
+ PyBytes_ConcatAndDel(&s, PyObject_Repr(r->start));
+ PyBytes_Concat(&s, comma);
+ PyBytes_ConcatAndDel(&s, PyObject_Repr(r->stop));
+ PyBytes_Concat(&s, comma);
+ PyBytes_ConcatAndDel(&s, PyObject_Repr(r->step));
+ PyBytes_ConcatAndDel(&s, PyBytes_FromString(")"));
Py_DECREF(comma);
return s;
}
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index 22dd292..05ccfea 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -778,7 +778,7 @@ FORMAT_STRING(PyObject* value, PyObject* args)
/* This is to allow things like u''.format('') */
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
goto done;
- if (!(PyString_Check(format_spec) || PyUnicode_Check(format_spec))) {
+ if (!(PyBytes_Check(format_spec) || PyUnicode_Check(format_spec))) {
PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
"or unicode, not %s", Py_TYPE(format_spec)->tp_name);
goto done;
diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h
index be8e8080..2e9c7ef 100644
--- a/Objects/stringlib/string_format.h
+++ b/Objects/stringlib/string_format.h
@@ -496,7 +496,7 @@ render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
#if PY_VERSION_HEX >= 0x03000000
assert(PyUnicode_Check(result));
#else
- assert(PyString_Check(result) || PyUnicode_Check(result));
+ assert(PyBytes_Check(result) || PyUnicode_Check(result));
/* Convert result to our type. We could be str, and result could
be unicode */
diff --git a/Objects/stringlib/stringdefs.h b/Objects/stringlib/stringdefs.h
index daaa2e2..bdc3a29 100644
--- a/Objects/stringlib/stringdefs.h
+++ b/Objects/stringlib/stringdefs.h
@@ -6,7 +6,7 @@
compiled as unicode. */
#define STRINGLIB_IS_UNICODE 0
-#define STRINGLIB_OBJECT PyStringObject
+#define STRINGLIB_OBJECT PyBytesObject
#define STRINGLIB_CHAR char
#define STRINGLIB_TYPE_NAME "string"
#define STRINGLIB_PARSE_CODE "S"
@@ -16,13 +16,13 @@
#define STRINGLIB_TOUPPER toupper
#define STRINGLIB_TOLOWER tolower
#define STRINGLIB_FILL memset
-#define STRINGLIB_STR PyString_AS_STRING
-#define STRINGLIB_LEN PyString_GET_SIZE
-#define STRINGLIB_NEW PyString_FromStringAndSize
-#define STRINGLIB_RESIZE _PyString_Resize
-#define STRINGLIB_CHECK PyString_Check
+#define STRINGLIB_STR PyBytes_AS_STRING
+#define STRINGLIB_LEN PyBytes_GET_SIZE
+#define STRINGLIB_NEW PyBytes_FromStringAndSize
+#define STRINGLIB_RESIZE _PyBytes_Resize
+#define STRINGLIB_CHECK PyBytes_Check
#define STRINGLIB_CMP memcmp
#define STRINGLIB_TOSTR PyObject_Str
-#define STRINGLIB_GROUPING _PyString_InsertThousandsGrouping
+#define STRINGLIB_GROUPING _PyBytes_InsertThousandsGrouping
#endif /* !STRINGLIB_STRINGDEFS_H */
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index ea1069d..0f4d4c3 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -12,8 +12,8 @@
int null_strings, one_strings;
#endif
-static PyStringObject *characters[UCHAR_MAX + 1];
-static PyStringObject *nullstring;
+static PyBytesObject *characters[UCHAR_MAX + 1];
+static PyBytesObject *nullstring;
/* This dictionary holds all interned strings. Note that references to
strings in this dictionary are *not* counted in the string's ob_refcnt.
@@ -26,19 +26,19 @@ static PyStringObject *nullstring;
static PyObject *interned;
/*
- For both PyString_FromString() and PyString_FromStringAndSize(), the
+ For both PyBytes_FromString() and PyBytes_FromStringAndSize(), the
parameter `size' denotes number of characters to allocate, not counting any
null terminating character.
- For PyString_FromString(), the parameter `str' points to a null-terminated
+ For PyBytes_FromString(), the parameter `str' points to a null-terminated
string containing exactly `size' bytes.
- For PyString_FromStringAndSize(), the parameter the parameter `str' is
+ For PyBytes_FromStringAndSize(), the parameter the parameter `str' is
either NULL or else points to a string containing at least `size' bytes.
- For PyString_FromStringAndSize(), the string in the `str' parameter does
+ For PyBytes_FromStringAndSize(), the string in the `str' parameter does
not have to be null-terminated. (Therefore it is safe to construct a
- substring by calling `PyString_FromStringAndSize(origstring, substrlen)'.)
- If `str' is NULL then PyString_FromStringAndSize() will allocate `size+1'
+ substring by calling `PyBytes_FromStringAndSize(origstring, substrlen)'.)
+ If `str' is NULL then PyBytes_FromStringAndSize() will allocate `size+1'
bytes (setting the last byte to the null terminating character) and you can
fill in the data yourself. If `str' is non-NULL then the resulting
PyString object must be treated as immutable and you must not fill in nor
@@ -48,16 +48,16 @@ static PyObject *interned;
items" in a variable-size object, will contain the number of bytes
allocated for string data, not counting the null terminating character. It
is therefore equal to the equal to the `size' parameter (for
- PyString_FromStringAndSize()) or the length of the string in the `str'
- parameter (for PyString_FromString()).
+ PyBytes_FromStringAndSize()) or the length of the string in the `str'
+ parameter (for PyBytes_FromString()).
*/
PyObject *
-PyString_FromStringAndSize(const char *str, Py_ssize_t size)
+PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
{
- register PyStringObject *op;
+ register PyBytesObject *op;
if (size < 0) {
PyErr_SetString(PyExc_SystemError,
- "Negative size passed to PyString_FromStringAndSize");
+ "Negative size passed to PyBytes_FromStringAndSize");
return NULL;
}
if (size == 0 && (op = nullstring) != NULL) {
@@ -78,10 +78,10 @@ PyString_FromStringAndSize(const char *str, Py_ssize_t size)
}
/* Inline PyObject_NewVar */
- op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
+ op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ PyObject_INIT_VAR(op, &PyBytes_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
if (str != NULL)
@@ -90,14 +90,14 @@ PyString_FromStringAndSize(const char *str, Py_ssize_t size)
/* share short strings */
if (size == 0) {
PyObject *t = (PyObject *)op;
- PyString_InternInPlace(&t);
- op = (PyStringObject *)t;
+ PyBytes_InternInPlace(&t);
+ op = (PyBytesObject *)t;
nullstring = op;
Py_INCREF(op);
} else if (size == 1 && str != NULL) {
PyObject *t = (PyObject *)op;
- PyString_InternInPlace(&t);
- op = (PyStringObject *)t;
+ PyBytes_InternInPlace(&t);
+ op = (PyBytesObject *)t;
characters[*str & UCHAR_MAX] = op;
Py_INCREF(op);
}
@@ -105,10 +105,10 @@ PyString_FromStringAndSize(const char *str, Py_ssize_t size)
}
PyObject *
-PyString_FromString(const char *str)
+PyBytes_FromString(const char *str)
{
register size_t size;
- register PyStringObject *op;
+ register PyBytesObject *op;
assert(str != NULL);
size = strlen(str);
@@ -133,24 +133,24 @@ PyString_FromString(const char *str)
}
/* Inline PyObject_NewVar */
- op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
+ op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ PyObject_INIT_VAR(op, &PyBytes_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, str, size+1);
/* share short strings */
if (size == 0) {
PyObject *t = (PyObject *)op;
- PyString_InternInPlace(&t);
- op = (PyStringObject *)t;
+ PyBytes_InternInPlace(&t);
+ op = (PyBytesObject *)t;
nullstring = op;
Py_INCREF(op);
} else if (size == 1) {
PyObject *t = (PyObject *)op;
- PyString_InternInPlace(&t);
- op = (PyStringObject *)t;
+ PyBytes_InternInPlace(&t);
+ op = (PyBytesObject *)t;
characters[*str & UCHAR_MAX] = op;
Py_INCREF(op);
}
@@ -158,7 +158,7 @@ PyString_FromString(const char *str)
}
PyObject *
-PyString_FromFormatV(const char *format, va_list vargs)
+PyBytes_FromFormatV(const char *format, va_list vargs)
{
va_list count;
Py_ssize_t n = 0;
@@ -233,11 +233,11 @@ PyString_FromFormatV(const char *format, va_list vargs)
/* step 2: fill the buffer */
/* Since we've analyzed how much space we need for the worst case,
use sprintf directly instead of the slower PyOS_snprintf. */
- string = PyString_FromStringAndSize(NULL, n);
+ string = PyBytes_FromStringAndSize(NULL, n);
if (!string)
return NULL;
- s = PyString_AsString(string);
+ s = PyBytes_AsString(string);
for (f = format; *f; f++) {
if (*f == '%') {
@@ -337,12 +337,12 @@ PyString_FromFormatV(const char *format, va_list vargs)
}
end:
- _PyString_Resize(&string, s - PyString_AS_STRING(string));
+ _PyBytes_Resize(&string, s - PyBytes_AS_STRING(string));
return string;
}
PyObject *
-PyString_FromFormat(const char *format, ...)
+PyBytes_FromFormat(const char *format, ...)
{
PyObject* ret;
va_list vargs;
@@ -352,34 +352,34 @@ PyString_FromFormat(const char *format, ...)
#else
va_start(vargs);
#endif
- ret = PyString_FromFormatV(format, vargs);
+ ret = PyBytes_FromFormatV(format, vargs);
va_end(vargs);
return ret;
}
-PyObject *PyString_Decode(const char *s,
+PyObject *PyBytes_Decode(const char *s,
Py_ssize_t size,
const char *encoding,
const char *errors)
{
PyObject *v, *str;
- str = PyString_FromStringAndSize(s, size);
+ str = PyBytes_FromStringAndSize(s, size);
if (str == NULL)
return NULL;
- v = PyString_AsDecodedString(str, encoding, errors);
+ v = PyBytes_AsDecodedString(str, encoding, errors);
Py_DECREF(str);
return v;
}
-PyObject *PyString_AsDecodedObject(PyObject *str,
+PyObject *PyBytes_AsDecodedObject(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- if (!PyString_Check(str)) {
+ if (!PyBytes_Check(str)) {
PyErr_BadArgument();
goto onError;
}
@@ -404,13 +404,13 @@ PyObject *PyString_AsDecodedObject(PyObject *str,
return NULL;
}
-PyObject *PyString_AsDecodedString(PyObject *str,
+PyObject *PyBytes_AsDecodedString(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- v = PyString_AsDecodedObject(str, encoding, errors);
+ v = PyBytes_AsDecodedObject(str, encoding, errors);
if (v == NULL)
goto onError;
@@ -424,7 +424,7 @@ PyObject *PyString_AsDecodedString(PyObject *str,
goto onError;
}
#endif
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string object (type=%.400s)",
Py_TYPE(v)->tp_name);
@@ -438,28 +438,28 @@ PyObject *PyString_AsDecodedString(PyObject *str,
return NULL;
}
-PyObject *PyString_Encode(const char *s,
+PyObject *PyBytes_Encode(const char *s,
Py_ssize_t size,
const char *encoding,
const char *errors)
{
PyObject *v, *str;
- str = PyString_FromStringAndSize(s, size);
+ str = PyBytes_FromStringAndSize(s, size);
if (str == NULL)
return NULL;
- v = PyString_AsEncodedString(str, encoding, errors);
+ v = PyBytes_AsEncodedString(str, encoding, errors);
Py_DECREF(str);
return v;
}
-PyObject *PyString_AsEncodedObject(PyObject *str,
+PyObject *PyBytes_AsEncodedObject(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- if (!PyString_Check(str)) {
+ if (!PyBytes_Check(str)) {
PyErr_BadArgument();
goto onError;
}
@@ -484,13 +484,13 @@ PyObject *PyString_AsEncodedObject(PyObject *str,
return NULL;
}
-PyObject *PyString_AsEncodedString(PyObject *str,
+PyObject *PyBytes_AsEncodedString(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- v = PyString_AsEncodedObject(str, encoding, errors);
+ v = PyBytes_AsEncodedObject(str, encoding, errors);
if (v == NULL)
goto onError;
@@ -504,7 +504,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
goto onError;
}
#endif
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
Py_TYPE(v)->tp_name);
@@ -521,7 +521,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
static void
string_dealloc(PyObject *op)
{
- switch (PyString_CHECK_INTERNED(op)) {
+ switch (PyBytes_CHECK_INTERNED(op)) {
case SSTATE_NOT_INTERNED:
break;
@@ -547,7 +547,7 @@ string_dealloc(PyObject *op)
the string is UTF-8 encoded and should be re-encoded in the
specified encoding. */
-PyObject *PyString_DecodeEscape(const char *s,
+PyObject *PyBytes_DecodeEscape(const char *s,
Py_ssize_t len,
const char *errors,
Py_ssize_t unicode,
@@ -558,10 +558,10 @@ PyObject *PyString_DecodeEscape(const char *s,
const char *end;
PyObject *v;
Py_ssize_t newlen = recode_encoding ? 4*len:len;
- v = PyString_FromStringAndSize((char *)NULL, newlen);
+ v = PyBytes_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
- p = buf = PyString_AsString(v);
+ p = buf = PyBytes_AsString(v);
end = s + len;
while (s < end) {
if (*s != '\\') {
@@ -585,9 +585,9 @@ PyObject *PyString_DecodeEscape(const char *s,
if (!w) goto failed;
/* Append bytes to output buffer. */
- assert(PyString_Check(w));
- r = PyString_AS_STRING(w);
- rn = PyString_GET_SIZE(w);
+ assert(PyBytes_Check(w));
+ r = PyBytes_AS_STRING(w);
+ rn = PyBytes_GET_SIZE(w);
Py_MEMCPY(p, r, rn);
p += rn;
Py_DECREF(w);
@@ -690,7 +690,7 @@ PyObject *PyString_DecodeEscape(const char *s,
}
}
if (p-buf < newlen)
- _PyString_Resize(&v, p - buf);
+ _PyBytes_Resize(&v, p - buf);
return v;
failed:
Py_DECREF(v);
@@ -705,7 +705,7 @@ string_getsize(register PyObject *op)
{
char *s;
Py_ssize_t len;
- if (PyString_AsStringAndSize(op, &s, &len))
+ if (PyBytes_AsStringAndSize(op, &s, &len))
return -1;
return len;
}
@@ -715,29 +715,29 @@ string_getbuffer(register PyObject *op)
{
char *s;
Py_ssize_t len;
- if (PyString_AsStringAndSize(op, &s, &len))
+ if (PyBytes_AsStringAndSize(op, &s, &len))
return NULL;
return s;
}
Py_ssize_t
-PyString_Size(register PyObject *op)
+PyBytes_Size(register PyObject *op)
{
- if (!PyString_Check(op))
+ if (!PyBytes_Check(op))
return string_getsize(op);
return Py_SIZE(op);
}
/*const*/ char *
-PyString_AsString(register PyObject *op)
+PyBytes_AsString(register PyObject *op)
{
- if (!PyString_Check(op))
+ if (!PyBytes_Check(op))
return string_getbuffer(op);
- return ((PyStringObject *)op) -> ob_sval;
+ return ((PyBytesObject *)op) -> ob_sval;
}
int
-PyString_AsStringAndSize(register PyObject *obj,
+PyBytes_AsStringAndSize(register PyObject *obj,
register char **s,
register Py_ssize_t *len)
{
@@ -746,7 +746,7 @@ PyString_AsStringAndSize(register PyObject *obj,
return -1;
}
- if (!PyString_Check(obj)) {
+ if (!PyBytes_Check(obj)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(obj)) {
obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
@@ -763,10 +763,10 @@ PyString_AsStringAndSize(register PyObject *obj,
}
}
- *s = PyString_AS_STRING(obj);
+ *s = PyBytes_AS_STRING(obj);
if (len != NULL)
- *len = PyString_GET_SIZE(obj);
- else if (strlen(*s) != (size_t)PyString_GET_SIZE(obj)) {
+ *len = PyBytes_GET_SIZE(obj);
+ else if (strlen(*s) != (size_t)PyBytes_GET_SIZE(obj)) {
PyErr_SetString(PyExc_TypeError,
"expected string without null bytes");
return -1;
@@ -784,23 +784,23 @@ PyString_AsStringAndSize(register PyObject *obj,
#include "stringlib/find.h"
#include "stringlib/partition.h"
-#define _Py_InsertThousandsGrouping _PyString_InsertThousandsGrouping
+#define _Py_InsertThousandsGrouping _PyBytes_InsertThousandsGrouping
#include "stringlib/localeutil.h"
static int
-string_print(PyStringObject *op, FILE *fp, int flags)
+string_print(PyBytesObject *op, FILE *fp, int flags)
{
Py_ssize_t i, str_len;
char c;
int quote;
/* XXX Ought to check for interrupts when writing long strings */
- if (! PyString_CheckExact(op)) {
+ if (! PyBytes_CheckExact(op)) {
int ret;
/* A str subclass may have its own __str__ method. */
- op = (PyStringObject *) PyObject_Str((PyObject *)op);
+ op = (PyBytesObject *) PyObject_Str((PyObject *)op);
if (op == NULL)
return -1;
ret = string_print(op, fp, flags);
@@ -863,9 +863,9 @@ string_print(PyStringObject *op, FILE *fp, int flags)
}
PyObject *
-PyString_Repr(PyObject *obj, int smartquotes)
+PyBytes_Repr(PyObject *obj, int smartquotes)
{
- register PyStringObject* op = (PyStringObject*) obj;
+ register PyBytesObject* op = (PyBytesObject*) obj;
size_t newsize = 2 + 4 * Py_SIZE(op);
PyObject *v;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_SIZE(op)) {
@@ -873,7 +873,7 @@ PyString_Repr(PyObject *obj, int smartquotes)
"string is too large to make repr");
return NULL;
}
- v = PyString_FromStringAndSize((char *)NULL, newsize);
+ v = PyBytes_FromStringAndSize((char *)NULL, newsize);
if (v == NULL) {
return NULL;
}
@@ -890,12 +890,12 @@ PyString_Repr(PyObject *obj, int smartquotes)
!memchr(op->ob_sval, '"', Py_SIZE(op)))
quote = '"';
- p = PyString_AS_STRING(v);
+ p = PyBytes_AS_STRING(v);
*p++ = quote;
for (i = 0; i < Py_SIZE(op); i++) {
/* There's at least enough room for a hex escape
and a closing quote. */
- assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
+ assert(newsize - (p - PyBytes_AS_STRING(v)) >= 5);
c = op->ob_sval[i];
if (c == quote || c == '\\')
*p++ = '\\', *p++ = c;
@@ -915,11 +915,11 @@ PyString_Repr(PyObject *obj, int smartquotes)
else
*p++ = c;
}
- assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
+ assert(newsize - (p - PyBytes_AS_STRING(v)) >= 1);
*p++ = quote;
*p = '\0';
- _PyString_Resize(
- &v, (p - PyString_AS_STRING(v)));
+ _PyBytes_Resize(
+ &v, (p - PyBytes_AS_STRING(v)));
return v;
}
}
@@ -927,36 +927,36 @@ PyString_Repr(PyObject *obj, int smartquotes)
static PyObject *
string_repr(PyObject *op)
{
- return PyString_Repr(op, 1);
+ return PyBytes_Repr(op, 1);
}
static PyObject *
string_str(PyObject *s)
{
- assert(PyString_Check(s));
- if (PyString_CheckExact(s)) {
+ assert(PyBytes_Check(s));
+ if (PyBytes_CheckExact(s)) {
Py_INCREF(s);
return s;
}
else {
/* Subtype -- return genuine string with the same value. */
- PyStringObject *t = (PyStringObject *) s;
- return PyString_FromStringAndSize(t->ob_sval, Py_SIZE(t));
+ PyBytesObject *t = (PyBytesObject *) s;
+ return PyBytes_FromStringAndSize(t->ob_sval, Py_SIZE(t));
}
}
static Py_ssize_t
-string_length(PyStringObject *a)
+string_length(PyBytesObject *a)
{
return Py_SIZE(a);
}
static PyObject *
-string_concat(register PyStringObject *a, register PyObject *bb)
+string_concat(register PyBytesObject *a, register PyObject *bb)
{
register Py_ssize_t size;
- register PyStringObject *op;
- if (!PyString_Check(bb)) {
+ register PyBytesObject *op;
+ if (!PyBytes_Check(bb)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(bb))
return PyUnicode_Concat((PyObject *)a, bb);
@@ -968,10 +968,10 @@ string_concat(register PyStringObject *a, register PyObject *bb)
Py_TYPE(bb)->tp_name);
return NULL;
}
-#define b ((PyStringObject *)bb)
+#define b ((PyBytesObject *)bb)
/* Optimize cases with empty left or right operand */
if ((Py_SIZE(a) == 0 || Py_SIZE(b) == 0) &&
- PyString_CheckExact(a) && PyString_CheckExact(b)) {
+ PyBytes_CheckExact(a) && PyBytes_CheckExact(b)) {
if (Py_SIZE(a) == 0) {
Py_INCREF(bb);
return bb;
@@ -987,10 +987,10 @@ string_concat(register PyStringObject *a, register PyObject *bb)
}
/* Inline PyObject_NewVar */
- op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
+ op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ PyObject_INIT_VAR(op, &PyBytes_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
@@ -1001,12 +1001,12 @@ string_concat(register PyStringObject *a, register PyObject *bb)
}
static PyObject *
-string_repeat(register PyStringObject *a, register Py_ssize_t n)
+string_repeat(register PyBytesObject *a, register Py_ssize_t n)
{
register Py_ssize_t i;
register Py_ssize_t j;
register Py_ssize_t size;
- register PyStringObject *op;
+ register PyBytesObject *op;
size_t nbytes;
if (n < 0)
n = 0;
@@ -1019,21 +1019,21 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
"repeated string is too long");
return NULL;
}
- if (size == Py_SIZE(a) && PyString_CheckExact(a)) {
+ if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
nbytes = (size_t)size;
- if (nbytes + sizeof(PyStringObject) <= nbytes) {
+ if (nbytes + sizeof(PyBytesObject) <= nbytes) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
- op = (PyStringObject *)
- PyObject_MALLOC(sizeof(PyStringObject) + nbytes);
+ op = (PyBytesObject *)
+ PyObject_MALLOC(sizeof(PyBytesObject) + nbytes);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ PyObject_INIT_VAR(op, &PyBytes_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
op->ob_sval[size] = '\0';
@@ -1057,7 +1057,7 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
/* String slice a[i:j] consists of characters a[i] ... a[j-1] */
static PyObject *
-string_slice(register PyStringObject *a, register Py_ssize_t i,
+string_slice(register PyBytesObject *a, register Py_ssize_t i,
register Py_ssize_t j)
/* j -- may be negative! */
{
@@ -1067,25 +1067,25 @@ string_slice(register PyStringObject *a, register Py_ssize_t i,
j = 0; /* Avoid signed/unsigned bug in next line */
if (j > Py_SIZE(a))
j = Py_SIZE(a);
- if (i == 0 && j == Py_SIZE(a) && PyString_CheckExact(a)) {
+ if (i == 0 && j == Py_SIZE(a) && PyBytes_CheckExact(a)) {
/* It's the same as a */
Py_INCREF(a);
return (PyObject *)a;
}
if (j < i)
j = i;
- return PyString_FromStringAndSize(a->ob_sval + i, j-i);
+ return PyBytes_FromStringAndSize(a->ob_sval + i, j-i);
}
static int
string_contains(PyObject *str_obj, PyObject *sub_obj)
{
- if (!PyString_CheckExact(sub_obj)) {
+ if (!PyBytes_CheckExact(sub_obj)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(sub_obj))
return PyUnicode_Contains(str_obj, sub_obj);
#endif
- if (!PyString_Check(sub_obj)) {
+ if (!PyBytes_Check(sub_obj)) {
PyErr_Format(PyExc_TypeError,
"'in <string>' requires string as left operand, "
"not %.200s", Py_TYPE(sub_obj)->tp_name);
@@ -1097,7 +1097,7 @@ string_contains(PyObject *str_obj, PyObject *sub_obj)
}
static PyObject *
-string_item(PyStringObject *a, register Py_ssize_t i)
+string_item(PyBytesObject *a, register Py_ssize_t i)
{
char pchar;
PyObject *v;
@@ -1108,7 +1108,7 @@ string_item(PyStringObject *a, register Py_ssize_t i)
pchar = a->ob_sval[i];
v = (PyObject *)characters[pchar & UCHAR_MAX];
if (v == NULL)
- v = PyString_FromStringAndSize(&pchar, 1);
+ v = PyBytes_FromStringAndSize(&pchar, 1);
else {
#ifdef COUNT_ALLOCS
one_strings++;
@@ -1119,7 +1119,7 @@ string_item(PyStringObject *a, register Py_ssize_t i)
}
static PyObject*
-string_richcompare(PyStringObject *a, PyStringObject *b, int op)
+string_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
{
int c;
Py_ssize_t len_a, len_b;
@@ -1127,7 +1127,7 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
PyObject *result;
/* Make sure both arguments are strings. */
- if (!(PyString_Check(a) && PyString_Check(b))) {
+ if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
result = Py_NotImplemented;
goto out;
}
@@ -1181,17 +1181,17 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
}
int
-_PyString_Eq(PyObject *o1, PyObject *o2)
+_PyBytes_Eq(PyObject *o1, PyObject *o2)
{
- PyStringObject *a = (PyStringObject*) o1;
- PyStringObject *b = (PyStringObject*) o2;
+ PyBytesObject *a = (PyBytesObject*) o1;
+ PyBytesObject *b = (PyBytesObject*) o2;
return Py_SIZE(a) == Py_SIZE(b)
&& *a->ob_sval == *b->ob_sval
&& memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0;
}
static long
-string_hash(PyStringObject *a)
+string_hash(PyBytesObject *a)
{
register Py_ssize_t len;
register unsigned char *p;
@@ -1212,14 +1212,14 @@ string_hash(PyStringObject *a)
}
static PyObject*
-string_subscript(PyStringObject* self, PyObject* item)
+string_subscript(PyBytesObject* self, PyObject* item)
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
- i += PyString_GET_SIZE(self);
+ i += PyBytes_GET_SIZE(self);
return string_item(self, i);
}
else if (PySlice_Check(item)) {
@@ -1229,27 +1229,27 @@ string_subscript(PyStringObject* self, PyObject* item)
PyObject* result;
if (PySlice_GetIndicesEx((PySliceObject*)item,
- PyString_GET_SIZE(self),
+ PyBytes_GET_SIZE(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
if (slicelength <= 0) {
- return PyString_FromStringAndSize("", 0);
+ return PyBytes_FromStringAndSize("", 0);
}
else if (start == 0 && step == 1 &&
- slicelength == PyString_GET_SIZE(self) &&
- PyString_CheckExact(self)) {
+ slicelength == PyBytes_GET_SIZE(self) &&
+ PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject *)self;
}
else if (step == 1) {
- return PyString_FromStringAndSize(
- PyString_AS_STRING(self) + start,
+ return PyBytes_FromStringAndSize(
+ PyBytes_AS_STRING(self) + start,
slicelength);
}
else {
- source_buf = PyString_AsString((PyObject*)self);
+ source_buf = PyBytes_AsString((PyObject*)self);
result_buf = (char *)PyMem_Malloc(slicelength);
if (result_buf == NULL)
return PyErr_NoMemory();
@@ -1259,7 +1259,7 @@ string_subscript(PyStringObject* self, PyObject* item)
result_buf[i] = source_buf[cur];
}
- result = PyString_FromStringAndSize(result_buf,
+ result = PyBytes_FromStringAndSize(result_buf,
slicelength);
PyMem_Free(result_buf);
return result;
@@ -1274,7 +1274,7 @@ string_subscript(PyStringObject* self, PyObject* item)
}
static Py_ssize_t
-string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
+string_buffer_getreadbuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1286,7 +1286,7 @@ string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **pt
}
static Py_ssize_t
-string_buffer_getwritebuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
+string_buffer_getwritebuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
{
PyErr_SetString(PyExc_TypeError,
"Cannot use string as modifiable buffer");
@@ -1294,7 +1294,7 @@ string_buffer_getwritebuf(PyStringObject *self, Py_ssize_t index, const void **p
}
static Py_ssize_t
-string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
+string_buffer_getsegcount(PyBytesObject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = Py_SIZE(self);
@@ -1302,7 +1302,7 @@ string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
}
static Py_ssize_t
-string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **ptr)
+string_buffer_getcharbuf(PyBytesObject *self, Py_ssize_t index, const char **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1314,7 +1314,7 @@ string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **pt
}
static int
-string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
+string_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags)
{
return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_SIZE(self),
0, flags);
@@ -1379,7 +1379,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
(maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
#define SPLIT_APPEND(data, left, right) \
- str = PyString_FromStringAndSize((data) + (left), \
+ str = PyBytes_FromStringAndSize((data) + (left), \
(right) - (left)); \
if (str == NULL) \
goto onError; \
@@ -1391,7 +1391,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
Py_DECREF(str);
#define SPLIT_ADD(data, left, right) { \
- str = PyString_FromStringAndSize((data) + (left), \
+ str = PyBytes_FromStringAndSize((data) + (left), \
(right) - (left)); \
if (str == NULL) \
goto onError; \
@@ -1416,9 +1416,9 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
#define RSKIP_NONSPACE(s, i) { while (i>=0 && !isspace(Py_CHARMASK(s[i]))) i--; }
Py_LOCAL_INLINE(PyObject *)
-split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
+split_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
{
- const char *s = PyString_AS_STRING(self);
+ const char *s = PyBytes_AS_STRING(self);
Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1433,7 +1433,7 @@ split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
if (i==len) break;
j = i; i++;
SKIP_NONSPACE(s, i, len);
- if (j == 0 && i == len && PyString_CheckExact(self)) {
+ if (j == 0 && i == len && PyBytes_CheckExact(self)) {
/* No whitespace in self, so just use it as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1458,9 +1458,9 @@ split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
}
Py_LOCAL_INLINE(PyObject *)
-split_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+split_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
- const char *s = PyString_AS_STRING(self);
+ const char *s = PyBytes_AS_STRING(self);
register Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1479,7 +1479,7 @@ split_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
}
}
}
- if (i == 0 && count == 0 && PyString_CheckExact(self)) {
+ if (i == 0 && count == 0 && PyBytes_CheckExact(self)) {
/* ch not in self, so just use self as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1506,11 +1506,11 @@ whitespace string is a separator and empty strings are removed\n\
from the result.");
static PyObject *
-string_split(PyStringObject *self, PyObject *args)
+string_split(PyBytesObject *self, PyObject *args)
{
- Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
+ Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
Py_ssize_t maxsplit = -1, count=0;
- const char *s = PyString_AS_STRING(self), *sub;
+ const char *s = PyBytes_AS_STRING(self), *sub;
PyObject *list, *str, *subobj = Py_None;
#ifdef USE_FAST
Py_ssize_t pos;
@@ -1522,9 +1522,9 @@ string_split(PyStringObject *self, PyObject *args)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
return split_whitespace(self, len, maxsplit);
- if (PyString_Check(subobj)) {
- sub = PyString_AS_STRING(subobj);
- n = PyString_GET_SIZE(subobj);
+ if (PyBytes_Check(subobj)) {
+ sub = PyBytes_AS_STRING(subobj);
+ n = PyBytes_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1583,14 +1583,14 @@ the separator itself, and the part after it. If the separator is not\n\
found, returns S and two empty strings.");
static PyObject *
-string_partition(PyStringObject *self, PyObject *sep_obj)
+string_partition(PyBytesObject *self, PyObject *sep_obj)
{
const char *sep;
Py_ssize_t sep_len;
- if (PyString_Check(sep_obj)) {
- sep = PyString_AS_STRING(sep_obj);
- sep_len = PyString_GET_SIZE(sep_obj);
+ if (PyBytes_Check(sep_obj)) {
+ sep = PyBytes_AS_STRING(sep_obj);
+ sep_len = PyBytes_GET_SIZE(sep_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
@@ -1601,7 +1601,7 @@ string_partition(PyStringObject *self, PyObject *sep_obj)
return stringlib_partition(
(PyObject*) self,
- PyString_AS_STRING(self), PyString_GET_SIZE(self),
+ PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
sep_obj, sep, sep_len
);
}
@@ -1614,14 +1614,14 @@ the part before it, the separator itself, and the part after it. If the\n\
separator is not found, returns two empty strings and S.");
static PyObject *
-string_rpartition(PyStringObject *self, PyObject *sep_obj)
+string_rpartition(PyBytesObject *self, PyObject *sep_obj)
{
const char *sep;
Py_ssize_t sep_len;
- if (PyString_Check(sep_obj)) {
- sep = PyString_AS_STRING(sep_obj);
- sep_len = PyString_GET_SIZE(sep_obj);
+ if (PyBytes_Check(sep_obj)) {
+ sep = PyBytes_AS_STRING(sep_obj);
+ sep_len = PyBytes_GET_SIZE(sep_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
@@ -1632,15 +1632,15 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj)
return stringlib_rpartition(
(PyObject*) self,
- PyString_AS_STRING(self), PyString_GET_SIZE(self),
+ PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
sep_obj, sep, sep_len
);
}
Py_LOCAL_INLINE(PyObject *)
-rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
+rsplit_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
{
- const char *s = PyString_AS_STRING(self);
+ const char *s = PyBytes_AS_STRING(self);
Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1655,7 +1655,7 @@ rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
if (i<0) break;
j = i; i--;
RSKIP_NONSPACE(s, i);
- if (j == len-1 && i < 0 && PyString_CheckExact(self)) {
+ if (j == len-1 && i < 0 && PyBytes_CheckExact(self)) {
/* No whitespace in self, so just use it as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1682,9 +1682,9 @@ rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
}
Py_LOCAL_INLINE(PyObject *)
-rsplit_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+rsplit_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
- const char *s = PyString_AS_STRING(self);
+ const char *s = PyBytes_AS_STRING(self);
register Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1702,7 +1702,7 @@ rsplit_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
}
}
}
- if (i < 0 && count == 0 && PyString_CheckExact(self)) {
+ if (i < 0 && count == 0 && PyBytes_CheckExact(self)) {
/* ch not in self, so just use self as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1731,9 +1731,9 @@ done. If sep is not specified or is None, any whitespace string\n\
is a separator.");
static PyObject *
-string_rsplit(PyStringObject *self, PyObject *args)
+string_rsplit(PyBytesObject *self, PyObject *args)
{
- Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
+ Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
Py_ssize_t maxsplit = -1, count=0;
const char *s, *sub;
PyObject *list, *str, *subobj = Py_None;
@@ -1744,9 +1744,9 @@ string_rsplit(PyStringObject *self, PyObject *args)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
return rsplit_whitespace(self, len, maxsplit);
- if (PyString_Check(subobj)) {
- sub = PyString_AS_STRING(subobj);
- n = PyString_GET_SIZE(subobj);
+ if (PyBytes_Check(subobj)) {
+ sub = PyBytes_AS_STRING(subobj);
+ n = PyBytes_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1769,7 +1769,7 @@ string_rsplit(PyStringObject *self, PyObject *args)
j = len;
i = j - n;
- s = PyString_AS_STRING(self);
+ s = PyBytes_AS_STRING(self);
while ( (i >= 0) && (maxsplit-- > 0) ) {
for (; i>=0; i--) {
if (Py_STRING_MATCH(s, i, sub, n)) {
@@ -1799,10 +1799,10 @@ Return a string which is the concatenation of the strings in the\n\
sequence. The separator between elements is S.");
static PyObject *
-string_join(PyStringObject *self, PyObject *orig)
+string_join(PyBytesObject *self, PyObject *orig)
{
- char *sep = PyString_AS_STRING(self);
- const Py_ssize_t seplen = PyString_GET_SIZE(self);
+ char *sep = PyBytes_AS_STRING(self);
+ const Py_ssize_t seplen = PyBytes_GET_SIZE(self);
PyObject *res = NULL;
char *p;
Py_ssize_t seqlen = 0;
@@ -1818,11 +1818,11 @@ string_join(PyStringObject *self, PyObject *orig)
seqlen = PySequence_Size(seq);
if (seqlen == 0) {
Py_DECREF(seq);
- return PyString_FromString("");
+ return PyBytes_FromString("");
}
if (seqlen == 1) {
item = PySequence_Fast_GET_ITEM(seq, 0);
- if (PyString_CheckExact(item) || PyUnicode_CheckExact(item)) {
+ if (PyBytes_CheckExact(item) || PyUnicode_CheckExact(item)) {
Py_INCREF(item);
Py_DECREF(seq);
return item;
@@ -1838,7 +1838,7 @@ string_join(PyStringObject *self, PyObject *orig)
for (i = 0; i < seqlen; i++) {
const size_t old_sz = sz;
item = PySequence_Fast_GET_ITEM(seq, i);
- if (!PyString_Check(item)){
+ if (!PyBytes_Check(item)){
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(item)) {
/* Defer to Unicode join.
@@ -1859,7 +1859,7 @@ string_join(PyStringObject *self, PyObject *orig)
Py_DECREF(seq);
return NULL;
}
- sz += PyString_GET_SIZE(item);
+ sz += PyBytes_GET_SIZE(item);
if (i != 0)
sz += seplen;
if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
@@ -1871,19 +1871,19 @@ string_join(PyStringObject *self, PyObject *orig)
}
/* Allocate result space. */
- res = PyString_FromStringAndSize((char*)NULL, sz);
+ res = PyBytes_FromStringAndSize((char*)NULL, sz);
if (res == NULL) {
Py_DECREF(seq);
return NULL;
}
/* Catenate everything. */
- p = PyString_AS_STRING(res);
+ p = PyBytes_AS_STRING(res);
for (i = 0; i < seqlen; ++i) {
size_t n;
item = PySequence_Fast_GET_ITEM(seq, i);
- n = PyString_GET_SIZE(item);
- Py_MEMCPY(p, PyString_AS_STRING(item), n);
+ n = PyBytes_GET_SIZE(item);
+ Py_MEMCPY(p, PyBytes_AS_STRING(item), n);
p += n;
if (i < seqlen - 1) {
Py_MEMCPY(p, sep, seplen);
@@ -1896,11 +1896,11 @@ string_join(PyStringObject *self, PyObject *orig)
}
PyObject *
-_PyString_Join(PyObject *sep, PyObject *x)
+_PyBytes_Join(PyObject *sep, PyObject *x)
{
- assert(sep != NULL && PyString_Check(sep));
+ assert(sep != NULL && PyBytes_Check(sep));
assert(x != NULL);
- return string_join((PyStringObject *)sep, x);
+ return string_join((PyBytesObject *)sep, x);
}
Py_LOCAL_INLINE(void)
@@ -1919,7 +1919,7 @@ string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
}
Py_LOCAL_INLINE(Py_ssize_t)
-string_find_internal(PyStringObject *self, PyObject *args, int dir)
+string_find_internal(PyBytesObject *self, PyObject *args, int dir)
{
PyObject *subobj;
const char *sub;
@@ -1940,9 +1940,9 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
if (!_PyEval_SliceIndex(obj_end, &end))
return -2;
- if (PyString_Check(subobj)) {
- sub = PyString_AS_STRING(subobj);
- sub_len = PyString_GET_SIZE(subobj);
+ if (PyBytes_Check(subobj)) {
+ sub = PyBytes_AS_STRING(subobj);
+ sub_len = PyBytes_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1956,11 +1956,11 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
if (dir > 0)
return stringlib_find_slice(
- PyString_AS_STRING(self), PyString_GET_SIZE(self),
+ PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
sub, sub_len, start, end);
else
return stringlib_rfind_slice(
- PyString_AS_STRING(self), PyString_GET_SIZE(self),
+ PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
sub, sub_len, start, end);
}
@@ -1975,7 +1975,7 @@ arguments start and end are interpreted as in slice notation.\n\
Return -1 on failure.");
static PyObject *
-string_find(PyStringObject *self, PyObject *args)
+string_find(PyBytesObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
@@ -1990,7 +1990,7 @@ PyDoc_STRVAR(index__doc__,
Like S.find() but raise ValueError when the substring is not found.");
static PyObject *
-string_index(PyStringObject *self, PyObject *args)
+string_index(PyBytesObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
@@ -2014,7 +2014,7 @@ arguments start and end are interpreted as in slice notation.\n\
Return -1 on failure.");
static PyObject *
-string_rfind(PyStringObject *self, PyObject *args)
+string_rfind(PyBytesObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
@@ -2029,7 +2029,7 @@ PyDoc_STRVAR(rindex__doc__,
Like S.rfind() but raise ValueError when the substring is not found.");
static PyObject *
-string_rindex(PyStringObject *self, PyObject *args)
+string_rindex(PyBytesObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
@@ -2044,12 +2044,12 @@ string_rindex(PyStringObject *self, PyObject *args)
Py_LOCAL_INLINE(PyObject *)
-do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
+do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
{
- char *s = PyString_AS_STRING(self);
- Py_ssize_t len = PyString_GET_SIZE(self);
- char *sep = PyString_AS_STRING(sepobj);
- Py_ssize_t seplen = PyString_GET_SIZE(sepobj);
+ char *s = PyBytes_AS_STRING(self);
+ Py_ssize_t len = PyBytes_GET_SIZE(self);
+ char *sep = PyBytes_AS_STRING(sepobj);
+ Py_ssize_t seplen = PyBytes_GET_SIZE(sepobj);
Py_ssize_t i, j;
i = 0;
@@ -2067,20 +2067,20 @@ do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
j++;
}
- if (i == 0 && j == len && PyString_CheckExact(self)) {
+ if (i == 0 && j == len && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*)self;
}
else
- return PyString_FromStringAndSize(s+i, j-i);
+ return PyBytes_FromStringAndSize(s+i, j-i);
}
Py_LOCAL_INLINE(PyObject *)
-do_strip(PyStringObject *self, int striptype)
+do_strip(PyBytesObject *self, int striptype)
{
- char *s = PyString_AS_STRING(self);
- Py_ssize_t len = PyString_GET_SIZE(self), i, j;
+ char *s = PyBytes_AS_STRING(self);
+ Py_ssize_t len = PyBytes_GET_SIZE(self), i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
@@ -2097,17 +2097,17 @@ do_strip(PyStringObject *self, int striptype)
j++;
}
- if (i == 0 && j == len && PyString_CheckExact(self)) {
+ if (i == 0 && j == len && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*)self;
}
else
- return PyString_FromStringAndSize(s+i, j-i);
+ return PyBytes_FromStringAndSize(s+i, j-i);
}
Py_LOCAL_INLINE(PyObject *)
-do_argstrip(PyStringObject *self, int striptype, PyObject *args)
+do_argstrip(PyBytesObject *self, int striptype, PyObject *args)
{
PyObject *sep = NULL;
@@ -2115,7 +2115,7 @@ do_argstrip(PyStringObject *self, int striptype, PyObject *args)
return NULL;
if (sep != NULL && sep != Py_None) {
- if (PyString_Check(sep))
+ if (PyBytes_Check(sep))
return do_xstrip(self, striptype, sep);
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep)) {
@@ -2152,7 +2152,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_strip(PyStringObject *self, PyObject *args)
+string_strip(PyBytesObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, BOTHSTRIP); /* Common case */
@@ -2169,7 +2169,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_lstrip(PyStringObject *self, PyObject *args)
+string_lstrip(PyBytesObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, LEFTSTRIP); /* Common case */
@@ -2186,7 +2186,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_rstrip(PyStringObject *self, PyObject *args)
+string_rstrip(PyBytesObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, RIGHTSTRIP); /* Common case */
@@ -2206,19 +2206,19 @@ Return a copy of the string S converted to lowercase.");
#endif
static PyObject *
-string_lower(PyStringObject *self)
+string_lower(PyBytesObject *self)
{
char *s;
- Py_ssize_t i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyBytes_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(NULL, n);
+ newobj = PyBytes_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
- s = PyString_AS_STRING(newobj);
+ s = PyBytes_AS_STRING(newobj);
- Py_MEMCPY(s, PyString_AS_STRING(self), n);
+ Py_MEMCPY(s, PyBytes_AS_STRING(self), n);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
@@ -2239,19 +2239,19 @@ Return a copy of the string S converted to uppercase.");
#endif
static PyObject *
-string_upper(PyStringObject *self)
+string_upper(PyBytesObject *self)
{
char *s;
- Py_ssize_t i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyBytes_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(NULL, n);
+ newobj = PyBytes_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
- s = PyString_AS_STRING(newobj);
+ s = PyBytes_AS_STRING(newobj);
- Py_MEMCPY(s, PyString_AS_STRING(self), n);
+ Py_MEMCPY(s, PyBytes_AS_STRING(self), n);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
@@ -2269,17 +2269,17 @@ Return a titlecased version of S, i.e. words start with uppercase\n\
characters, all remaining cased characters have lowercase.");
static PyObject*
-string_title(PyStringObject *self)
+string_title(PyBytesObject *self)
{
- char *s = PyString_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyString_GET_SIZE(self);
+ char *s = PyBytes_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyBytes_GET_SIZE(self);
int previous_is_cased = 0;
PyObject *newobj;
- newobj = PyString_FromStringAndSize(NULL, n);
+ newobj = PyBytes_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
@@ -2304,16 +2304,16 @@ Return a copy of the string S with only its first character\n\
capitalized.");
static PyObject *
-string_capitalize(PyStringObject *self)
+string_capitalize(PyBytesObject *self)
{
- char *s = PyString_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyString_GET_SIZE(self);
+ char *s = PyBytes_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyBytes_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(NULL, n);
+ newobj = PyBytes_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
if (0 < n) {
int c = Py_CHARMASK(*s++);
if (islower(c))
@@ -2342,10 +2342,10 @@ string S[start:end]. Optional arguments start and end are interpreted\n\
as in slice notation.");
static PyObject *
-string_count(PyStringObject *self, PyObject *args)
+string_count(PyBytesObject *self, PyObject *args)
{
PyObject *sub_obj;
- const char *str = PyString_AS_STRING(self), *sub;
+ const char *str = PyBytes_AS_STRING(self), *sub;
Py_ssize_t sub_len;
Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;
@@ -2353,9 +2353,9 @@ string_count(PyStringObject *self, PyObject *args)
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
return NULL;
- if (PyString_Check(sub_obj)) {
- sub = PyString_AS_STRING(sub_obj);
- sub_len = PyString_GET_SIZE(sub_obj);
+ if (PyBytes_Check(sub_obj)) {
+ sub = PyBytes_AS_STRING(sub_obj);
+ sub_len = PyBytes_GET_SIZE(sub_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sub_obj)) {
@@ -2370,7 +2370,7 @@ string_count(PyStringObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
return NULL;
- string_adjust_indices(&start, &end, PyString_GET_SIZE(self));
+ string_adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
return PyInt_FromSsize_t(
stringlib_count(str + start, end - start, sub, sub_len)
@@ -2384,16 +2384,16 @@ Return a copy of the string S with uppercase characters\n\
converted to lowercase and vice versa.");
static PyObject *
-string_swapcase(PyStringObject *self)
+string_swapcase(PyBytesObject *self)
{
- char *s = PyString_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyString_GET_SIZE(self);
+ char *s = PyBytes_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyBytes_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(NULL, n);
+ newobj = PyBytes_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyString_AsString(newobj);
+ s_new = PyBytes_AsString(newobj);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
@@ -2419,7 +2419,7 @@ remaining characters have been mapped through the given\n\
translation table, which must be a string of length 256.");
static PyObject *
-string_translate(PyStringObject *self, PyObject *args)
+string_translate(PyBytesObject *self, PyObject *args)
{
register char *input, *output;
const char *table;
@@ -2435,9 +2435,9 @@ string_translate(PyStringObject *self, PyObject *args)
&tableobj, &delobj))
return NULL;
- if (PyString_Check(tableobj)) {
- table = PyString_AS_STRING(tableobj);
- tablen = PyString_GET_SIZE(tableobj);
+ if (PyBytes_Check(tableobj)) {
+ table = PyBytes_AS_STRING(tableobj);
+ tablen = PyBytes_GET_SIZE(tableobj);
}
else if (tableobj == Py_None) {
table = NULL;
@@ -2466,9 +2466,9 @@ string_translate(PyStringObject *self, PyObject *args)
}
if (delobj != NULL) {
- if (PyString_Check(delobj)) {
- del_table = PyString_AS_STRING(delobj);
- dellen = PyString_GET_SIZE(delobj);
+ if (PyBytes_Check(delobj)) {
+ del_table = PyBytes_AS_STRING(delobj);
+ dellen = PyBytes_GET_SIZE(delobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(delobj)) {
@@ -2485,12 +2485,12 @@ string_translate(PyStringObject *self, PyObject *args)
dellen = 0;
}
- inlen = PyString_GET_SIZE(input_obj);
- result = PyString_FromStringAndSize((char *)NULL, inlen);
+ inlen = PyBytes_GET_SIZE(input_obj);
+ result = PyBytes_FromStringAndSize((char *)NULL, inlen);
if (result == NULL)
return NULL;
- output_start = output = PyString_AsString(result);
- input = PyString_AS_STRING(input_obj);
+ output_start = output = PyBytes_AsString(result);
+ input = PyBytes_AS_STRING(input_obj);
if (dellen == 0 && table != NULL) {
/* If no deletions are required, use faster code */
@@ -2499,7 +2499,7 @@ string_translate(PyStringObject *self, PyObject *args)
if (Py_CHARMASK((*output++ = table[c])) != c)
changed = 1;
}
- if (changed || !PyString_CheckExact(input_obj))
+ if (changed || !PyBytes_CheckExact(input_obj))
return result;
Py_DECREF(result);
Py_INCREF(input_obj);
@@ -2524,14 +2524,14 @@ string_translate(PyStringObject *self, PyObject *args)
continue;
changed = 1;
}
- if (!changed && PyString_CheckExact(input_obj)) {
+ if (!changed && PyBytes_CheckExact(input_obj)) {
Py_DECREF(result);
Py_INCREF(input_obj);
return input_obj;
}
/* Fix the size of the resulting string */
if (inlen > 0)
- _PyString_Resize(&result, output - output_start);
+ _PyBytes_Resize(&result, output - output_start);
return result;
}
@@ -2546,16 +2546,16 @@ string_translate(PyStringObject *self, PyObject *args)
/* String ops must return a string. */
/* If the object is subclass of string, create a copy */
-Py_LOCAL(PyStringObject *)
-return_self(PyStringObject *self)
+Py_LOCAL(PyBytesObject *)
+return_self(PyBytesObject *self)
{
- if (PyString_CheckExact(self)) {
+ if (PyBytes_CheckExact(self)) {
Py_INCREF(self);
return self;
}
- return (PyStringObject *)PyString_FromStringAndSize(
- PyString_AS_STRING(self),
- PyString_GET_SIZE(self));
+ return (PyBytesObject *)PyBytes_FromStringAndSize(
+ PyBytes_AS_STRING(self),
+ PyBytes_GET_SIZE(self));
}
Py_LOCAL_INLINE(Py_ssize_t)
@@ -2665,17 +2665,17 @@ countstring(const char *target, Py_ssize_t target_len,
/* Algorithms for different cases of string replacement */
/* len(self)>=1, from="", len(to)>=1, maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_interleave(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_interleave(PyBytesObject *self,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
{
char *self_s, *result_s;
Py_ssize_t self_len, result_len;
Py_ssize_t count, i, product;
- PyStringObject *result;
+ PyBytesObject *result;
- self_len = PyString_GET_SIZE(self);
+ self_len = PyBytes_GET_SIZE(self);
/* 1 at the end plus 1 after every character */
count = self_len+1;
@@ -2697,12 +2697,12 @@ replace_interleave(PyStringObject *self,
return NULL;
}
- if (! (result = (PyStringObject *)
- PyString_FromStringAndSize(NULL, result_len)) )
+ if (! (result = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, result_len)) )
return NULL;
- self_s = PyString_AS_STRING(self);
- result_s = PyString_AS_STRING(result);
+ self_s = PyBytes_AS_STRING(self);
+ result_s = PyBytes_AS_STRING(result);
/* TODO: special case single character, which doesn't need memcpy */
@@ -2725,18 +2725,18 @@ replace_interleave(PyStringObject *self,
/* Special case for deleting a single character */
/* len(self)>=1, len(from)==1, to="", maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_delete_single_character(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_delete_single_character(PyBytesObject *self,
char from_c, Py_ssize_t maxcount)
{
char *self_s, *result_s;
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count;
- PyStringObject *result;
+ PyBytesObject *result;
- self_len = PyString_GET_SIZE(self);
- self_s = PyString_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
count = countchar(self_s, self_len, from_c, maxcount);
if (count == 0) {
@@ -2746,10 +2746,10 @@ replace_delete_single_character(PyStringObject *self,
result_len = self_len - count; /* from_len == 1 */
assert(result_len>=0);
- if ( (result = (PyStringObject *)
- PyString_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2768,18 +2768,18 @@ replace_delete_single_character(PyStringObject *self,
/* len(self)>=1, len(from)>=2, to="", maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_delete_substring(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_delete_substring(PyBytesObject *self,
const char *from_s, Py_ssize_t from_len,
Py_ssize_t maxcount) {
char *self_s, *result_s;
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, offset;
- PyStringObject *result;
+ PyBytesObject *result;
- self_len = PyString_GET_SIZE(self);
- self_s = PyString_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
count = countstring(self_s, self_len,
from_s, from_len,
@@ -2794,11 +2794,11 @@ replace_delete_substring(PyStringObject *self,
result_len = self_len - (count * from_len);
assert (result_len>=0);
- if ( (result = (PyStringObject *)
- PyString_FromStringAndSize(NULL, result_len)) == NULL )
+ if ( (result = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, result_len)) == NULL )
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2820,18 +2820,18 @@ replace_delete_substring(PyStringObject *self,
}
/* len(self)>=1, len(from)==len(to)==1, maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_single_character_in_place(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_single_character_in_place(PyBytesObject *self,
char from_c, char to_c,
Py_ssize_t maxcount)
{
char *self_s, *result_s, *start, *end, *next;
Py_ssize_t self_len;
- PyStringObject *result;
+ PyBytesObject *result;
/* The result string will be the same size */
- self_s = PyString_AS_STRING(self);
- self_len = PyString_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
next = findchar(self_s, self_len, from_c);
@@ -2841,10 +2841,10 @@ replace_single_character_in_place(PyStringObject *self,
}
/* Need to make a new string */
- result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
+ result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
if (result == NULL)
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len);
/* change everything in-place, starting with this one */
@@ -2865,8 +2865,8 @@ replace_single_character_in_place(PyStringObject *self,
}
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_substring_in_place(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_substring_in_place(PyBytesObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
@@ -2874,12 +2874,12 @@ replace_substring_in_place(PyStringObject *self,
char *result_s, *start, *end;
char *self_s;
Py_ssize_t self_len, offset;
- PyStringObject *result;
+ PyBytesObject *result;
/* The result string will be the same size */
- self_s = PyString_AS_STRING(self);
- self_len = PyString_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
offset = findstring(self_s, self_len,
from_s, from_len,
@@ -2890,10 +2890,10 @@ replace_substring_in_place(PyStringObject *self,
}
/* Need to make a new string */
- result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
+ result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
if (result == NULL)
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len);
/* change everything in-place, starting with this one */
@@ -2916,8 +2916,8 @@ replace_substring_in_place(PyStringObject *self,
}
/* len(self)>=1, len(from)==1, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_single_character(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_single_character(PyBytesObject *self,
char from_c,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
@@ -2926,10 +2926,10 @@ replace_single_character(PyStringObject *self,
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, product;
- PyStringObject *result;
+ PyBytesObject *result;
- self_s = PyString_AS_STRING(self);
- self_len = PyString_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
count = countchar(self_s, self_len, from_c, maxcount);
if (count == 0) {
@@ -2950,10 +2950,10 @@ replace_single_character(PyStringObject *self,
return NULL;
}
- if ( (result = (PyStringObject *)
- PyString_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2983,8 +2983,8 @@ replace_single_character(PyStringObject *self,
}
/* len(self)>=1, len(from)>=2, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyStringObject *)
-replace_substring(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace_substring(PyBytesObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount) {
@@ -2992,10 +2992,10 @@ replace_substring(PyStringObject *self,
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, offset, product;
- PyStringObject *result;
+ PyBytesObject *result;
- self_s = PyString_AS_STRING(self);
- self_len = PyString_GET_SIZE(self);
+ self_s = PyBytes_AS_STRING(self);
+ self_len = PyBytes_GET_SIZE(self);
count = countstring(self_s, self_len,
from_s, from_len,
@@ -3018,10 +3018,10 @@ replace_substring(PyStringObject *self,
return NULL;
}
- if ( (result = (PyStringObject *)
- PyString_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyString_AS_STRING(result);
+ result_s = PyBytes_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -3053,15 +3053,15 @@ replace_substring(PyStringObject *self,
}
-Py_LOCAL(PyStringObject *)
-replace(PyStringObject *self,
+Py_LOCAL(PyBytesObject *)
+replace(PyBytesObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
{
if (maxcount < 0) {
maxcount = PY_SSIZE_T_MAX;
- } else if (maxcount == 0 || PyString_GET_SIZE(self) == 0) {
+ } else if (maxcount == 0 || PyBytes_GET_SIZE(self) == 0) {
/* nothing to do; return the original string */
return return_self(self);
}
@@ -3084,7 +3084,7 @@ replace(PyStringObject *self,
/* Except for "".replace("", "A") == "A" there is no way beyond this */
/* point for an empty self string to generate a non-empty string */
/* Special case so the remaining code always gets a non-empty string */
- if (PyString_GET_SIZE(self) == 0) {
+ if (PyBytes_GET_SIZE(self) == 0) {
return return_self(self);
}
@@ -3131,7 +3131,7 @@ old replaced by new. If the optional argument count is\n\
given, only the first count occurrences are replaced.");
static PyObject *
-string_replace(PyStringObject *self, PyObject *args)
+string_replace(PyBytesObject *self, PyObject *args)
{
Py_ssize_t count = -1;
PyObject *from, *to;
@@ -3141,9 +3141,9 @@ string_replace(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count))
return NULL;
- if (PyString_Check(from)) {
- from_s = PyString_AS_STRING(from);
- from_len = PyString_GET_SIZE(from);
+ if (PyBytes_Check(from)) {
+ from_s = PyBytes_AS_STRING(from);
+ from_len = PyBytes_GET_SIZE(from);
}
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(from))
@@ -3153,9 +3153,9 @@ string_replace(PyStringObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(from, &from_s, &from_len))
return NULL;
- if (PyString_Check(to)) {
- to_s = PyString_AS_STRING(to);
- to_len = PyString_GET_SIZE(to);
+ if (PyBytes_Check(to)) {
+ to_s = PyBytes_AS_STRING(to);
+ to_len = PyBytes_GET_SIZE(to);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(to))
@@ -3165,7 +3165,7 @@ string_replace(PyStringObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(to, &to_s, &to_len))
return NULL;
- return (PyObject *)replace((PyStringObject *) self,
+ return (PyObject *)replace((PyBytesObject *) self,
from_s, from_len,
to_s, to_len, count);
}
@@ -3177,17 +3177,17 @@ string_replace(PyStringObject *self, PyObject *args)
* -1 on error, 0 if not found and 1 if found.
*/
Py_LOCAL(int)
-_string_tailmatch(PyStringObject *self, PyObject *substr, Py_ssize_t start,
+_string_tailmatch(PyBytesObject *self, PyObject *substr, Py_ssize_t start,
Py_ssize_t end, int direction)
{
- Py_ssize_t len = PyString_GET_SIZE(self);
+ Py_ssize_t len = PyBytes_GET_SIZE(self);
Py_ssize_t slen;
const char* sub;
const char* str;
- if (PyString_Check(substr)) {
- sub = PyString_AS_STRING(substr);
- slen = PyString_GET_SIZE(substr);
+ if (PyBytes_Check(substr)) {
+ sub = PyBytes_AS_STRING(substr);
+ slen = PyBytes_GET_SIZE(substr);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(substr))
@@ -3196,7 +3196,7 @@ _string_tailmatch(PyStringObject *self, PyObject *substr, Py_ssize_t start,
#endif
else if (PyObject_AsCharBuffer(substr, &sub, &slen))
return -1;
- str = PyString_AS_STRING(self);
+ str = PyBytes_AS_STRING(self);
string_adjust_indices(&start, &end, len);
@@ -3227,7 +3227,7 @@ With optional end, stop comparing S at that position.\n\
prefix can also be a tuple of strings to try.");
static PyObject *
-string_startswith(PyStringObject *self, PyObject *args)
+string_startswith(PyBytesObject *self, PyObject *args)
{
Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -3268,7 +3268,7 @@ With optional end, stop comparing S at that position.\n\
suffix can also be a tuple of strings to try.");
static PyObject *
-string_endswith(PyStringObject *self, PyObject *args)
+string_endswith(PyBytesObject *self, PyObject *args)
{
Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -3311,7 +3311,7 @@ a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\
codecs.register_error that is able to handle UnicodeEncodeErrors.");
static PyObject *
-string_encode(PyStringObject *self, PyObject *args)
+string_encode(PyBytesObject *self, PyObject *args)
{
char *encoding = NULL;
char *errors = NULL;
@@ -3319,10 +3319,10 @@ string_encode(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors))
return NULL;
- v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
+ v = PyBytes_AsEncodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
@@ -3348,7 +3348,7 @@ as well as any other name registerd with codecs.register_error that is\n\
able to handle UnicodeDecodeErrors.");
static PyObject *
-string_decode(PyStringObject *self, PyObject *args)
+string_decode(PyBytesObject *self, PyObject *args)
{
char *encoding = NULL;
char *errors = NULL;
@@ -3356,10 +3356,10 @@ string_decode(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
return NULL;
- v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
+ v = PyBytes_AsDecodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
@@ -3381,7 +3381,7 @@ Return a copy of S where all tab characters are expanded using spaces.\n\
If tabsize is not given, a tab size of 8 characters is assumed.");
static PyObject*
-string_expandtabs(PyStringObject *self, PyObject *args)
+string_expandtabs(PyBytesObject *self, PyObject *args)
{
const char *e, *p, *qe;
char *q;
@@ -3395,8 +3395,8 @@ string_expandtabs(PyStringObject *self, PyObject *args)
/* First pass: determine size of output string */
i = 0; /* chars up to and including most recent \n or \r */
j = 0; /* chars since most recent \n or \r (use in tab calculations) */
- e = PyString_AS_STRING(self) + PyString_GET_SIZE(self); /* end of input */
- for (p = PyString_AS_STRING(self); p < e; p++)
+ e = PyBytes_AS_STRING(self) + PyBytes_GET_SIZE(self); /* end of input */
+ for (p = PyBytes_AS_STRING(self); p < e; p++)
if (*p == '\t') {
if (tabsize > 0) {
incr = tabsize - (j % tabsize);
@@ -3421,15 +3421,15 @@ string_expandtabs(PyStringObject *self, PyObject *args)
goto overflow1;
/* Second pass: create output string and fill it */
- u = PyString_FromStringAndSize(NULL, i + j);
+ u = PyBytes_FromStringAndSize(NULL, i + j);
if (!u)
return NULL;
j = 0; /* same as in first pass */
- q = PyString_AS_STRING(u); /* next output char */
- qe = PyString_AS_STRING(u) + PyString_GET_SIZE(u); /* end of output */
+ q = PyBytes_AS_STRING(u); /* next output char */
+ qe = PyBytes_AS_STRING(u) + PyBytes_GET_SIZE(u); /* end of output */
- for (p = PyString_AS_STRING(self); p < e; p++)
+ for (p = PyBytes_AS_STRING(self); p < e; p++)
if (*p == '\t') {
if (tabsize > 0) {
i = tabsize - (j % tabsize);
@@ -3460,7 +3460,7 @@ string_expandtabs(PyStringObject *self, PyObject *args)
}
Py_LOCAL_INLINE(PyObject *)
-pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
+pad(PyBytesObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
{
PyObject *u;
@@ -3469,21 +3469,21 @@ pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
if (right < 0)
right = 0;
- if (left == 0 && right == 0 && PyString_CheckExact(self)) {
+ if (left == 0 && right == 0 && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject *)self;
}
- u = PyString_FromStringAndSize(NULL,
- left + PyString_GET_SIZE(self) + right);
+ u = PyBytes_FromStringAndSize(NULL,
+ left + PyBytes_GET_SIZE(self) + right);
if (u) {
if (left)
- memset(PyString_AS_STRING(u), fill, left);
- Py_MEMCPY(PyString_AS_STRING(u) + left,
- PyString_AS_STRING(self),
- PyString_GET_SIZE(self));
+ memset(PyBytes_AS_STRING(u), fill, left);
+ Py_MEMCPY(PyBytes_AS_STRING(u) + left,
+ PyBytes_AS_STRING(self),
+ PyBytes_GET_SIZE(self));
if (right)
- memset(PyString_AS_STRING(u) + left + PyString_GET_SIZE(self),
+ memset(PyBytes_AS_STRING(u) + left + PyBytes_GET_SIZE(self),
fill, right);
}
@@ -3497,7 +3497,7 @@ PyDoc_STRVAR(ljust__doc__,
"done using the specified fill character (default is a space).");
static PyObject *
-string_ljust(PyStringObject *self, PyObject *args)
+string_ljust(PyBytesObject *self, PyObject *args)
{
Py_ssize_t width;
char fillchar = ' ';
@@ -3505,12 +3505,12 @@ string_ljust(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
return NULL;
- if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
+ if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- return pad(self, 0, width - PyString_GET_SIZE(self), fillchar);
+ return pad(self, 0, width - PyBytes_GET_SIZE(self), fillchar);
}
@@ -3521,7 +3521,7 @@ PyDoc_STRVAR(rjust__doc__,
"done using the specified fill character (default is a space)");
static PyObject *
-string_rjust(PyStringObject *self, PyObject *args)
+string_rjust(PyBytesObject *self, PyObject *args)
{
Py_ssize_t width;
char fillchar = ' ';
@@ -3529,12 +3529,12 @@ string_rjust(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar))
return NULL;
- if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
+ if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- return pad(self, width - PyString_GET_SIZE(self), 0, fillchar);
+ return pad(self, width - PyBytes_GET_SIZE(self), 0, fillchar);
}
@@ -3545,7 +3545,7 @@ PyDoc_STRVAR(center__doc__,
"done using the specified fill character (default is a space)");
static PyObject *
-string_center(PyStringObject *self, PyObject *args)
+string_center(PyBytesObject *self, PyObject *args)
{
Py_ssize_t marg, left;
Py_ssize_t width;
@@ -3554,12 +3554,12 @@ string_center(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar))
return NULL;
- if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
+ if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- marg = width - PyString_GET_SIZE(self);
+ marg = width - PyBytes_GET_SIZE(self);
left = marg / 2 + (marg & width & 1);
return pad(self, left, marg - left, fillchar);
@@ -3572,7 +3572,7 @@ PyDoc_STRVAR(zfill__doc__,
"of the specified width. The string S is never truncated.");
static PyObject *
-string_zfill(PyStringObject *self, PyObject *args)
+string_zfill(PyBytesObject *self, PyObject *args)
{
Py_ssize_t fill;
PyObject *s;
@@ -3582,26 +3582,26 @@ string_zfill(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n:zfill", &width))
return NULL;
- if (PyString_GET_SIZE(self) >= width) {
- if (PyString_CheckExact(self)) {
+ if (PyBytes_GET_SIZE(self) >= width) {
+ if (PyBytes_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
else
- return PyString_FromStringAndSize(
- PyString_AS_STRING(self),
- PyString_GET_SIZE(self)
+ return PyBytes_FromStringAndSize(
+ PyBytes_AS_STRING(self),
+ PyBytes_GET_SIZE(self)
);
}
- fill = width - PyString_GET_SIZE(self);
+ fill = width - PyBytes_GET_SIZE(self);
s = pad(self, fill, 0, '0');
if (s == NULL)
return NULL;
- p = PyString_AS_STRING(s);
+ p = PyBytes_AS_STRING(s);
if (p[fill] == '+' || p[fill] == '-') {
/* move sign to beginning of string */
p[0] = p[fill];
@@ -3618,22 +3618,22 @@ Return True if all characters in S are whitespace\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isspace(PyStringObject *self)
+string_isspace(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1 &&
+ if (PyBytes_GET_SIZE(self) == 1 &&
isspace(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
for (; p < e; p++) {
if (!isspace(*p))
return PyBool_FromLong(0);
@@ -3649,22 +3649,22 @@ Return True if all characters in S are alphabetic\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isalpha(PyStringObject *self)
+string_isalpha(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1 &&
+ if (PyBytes_GET_SIZE(self) == 1 &&
isalpha(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
for (; p < e; p++) {
if (!isalpha(*p))
return PyBool_FromLong(0);
@@ -3680,22 +3680,22 @@ Return True if all characters in S are alphanumeric\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isalnum(PyStringObject *self)
+string_isalnum(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1 &&
+ if (PyBytes_GET_SIZE(self) == 1 &&
isalnum(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
for (; p < e; p++) {
if (!isalnum(*p))
return PyBool_FromLong(0);
@@ -3711,22 +3711,22 @@ Return True if all characters in S are digits\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isdigit(PyStringObject *self)
+string_isdigit(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1 &&
+ if (PyBytes_GET_SIZE(self) == 1 &&
isdigit(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
for (; p < e; p++) {
if (!isdigit(*p))
return PyBool_FromLong(0);
@@ -3742,22 +3742,22 @@ Return True if all cased characters in S are lowercase and there is\n\
at least one cased character in S, False otherwise.");
static PyObject*
-string_islower(PyStringObject *self)
+string_islower(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
int cased;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1)
+ if (PyBytes_GET_SIZE(self) == 1)
return PyBool_FromLong(islower(*p) != 0);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
if (isupper(*p))
@@ -3776,22 +3776,22 @@ Return True if all cased characters in S are uppercase and there is\n\
at least one cased character in S, False otherwise.");
static PyObject*
-string_isupper(PyStringObject *self)
+string_isupper(PyBytesObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
int cased;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1)
+ if (PyBytes_GET_SIZE(self) == 1)
return PyBool_FromLong(isupper(*p) != 0);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
if (islower(*p))
@@ -3812,22 +3812,22 @@ characters and lowercase characters only cased ones. Return False\n\
otherwise.");
static PyObject*
-string_istitle(PyStringObject *self, PyObject *uncased)
+string_istitle(PyBytesObject *self, PyObject *uncased)
{
register const unsigned char *p
- = (unsigned char *) PyString_AS_STRING(self);
+ = (unsigned char *) PyBytes_AS_STRING(self);
register const unsigned char *e;
int cased, previous_is_cased;
/* Shortcut for single character strings */
- if (PyString_GET_SIZE(self) == 1)
+ if (PyBytes_GET_SIZE(self) == 1)
return PyBool_FromLong(isupper(*p) != 0);
/* Special case for empty strings */
- if (PyString_GET_SIZE(self) == 0)
+ if (PyBytes_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyString_GET_SIZE(self);
+ e = p + PyBytes_GET_SIZE(self);
cased = 0;
previous_is_cased = 0;
for (; p < e; p++) {
@@ -3860,7 +3860,7 @@ Line breaks are not included in the resulting list unless keepends\n\
is given and true.");
static PyObject*
-string_splitlines(PyStringObject *self, PyObject *args)
+string_splitlines(PyBytesObject *self, PyObject *args)
{
register Py_ssize_t i;
register Py_ssize_t j;
@@ -3873,8 +3873,8 @@ string_splitlines(PyStringObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
return NULL;
- data = PyString_AS_STRING(self);
- len = PyString_GET_SIZE(self);
+ data = PyBytes_AS_STRING(self);
+ len = PyBytes_GET_SIZE(self);
/* This does not use the preallocated list because splitlines is
usually run with hundreds of newlines. The overhead of
@@ -3926,7 +3926,7 @@ string_splitlines(PyStringObject *self, PyObject *args)
#undef PREALLOC_SIZE
static PyObject *
-string_getnewargs(PyStringObject *v)
+string_getnewargs(PyBytesObject *v)
{
return Py_BuildValue("(s#)", v->ob_sval, Py_SIZE(v));
}
@@ -4011,12 +4011,12 @@ string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *x = NULL;
static char *kwlist[] = {"object", 0};
- if (type != &PyString_Type)
+ if (type != &PyBytes_Type)
return str_subtype_new(type, args, kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:str", kwlist, &x))
return NULL;
if (x == NULL)
- return PyString_FromString("");
+ return PyBytes_FromString("");
return PyObject_Str(x);
}
@@ -4026,18 +4026,18 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *tmp, *pnew;
Py_ssize_t n;
- assert(PyType_IsSubtype(type, &PyString_Type));
- tmp = string_new(&PyString_Type, args, kwds);
+ assert(PyType_IsSubtype(type, &PyBytes_Type));
+ tmp = string_new(&PyBytes_Type, args, kwds);
if (tmp == NULL)
return NULL;
- assert(PyString_CheckExact(tmp));
- n = PyString_GET_SIZE(tmp);
+ assert(PyBytes_CheckExact(tmp));
+ n = PyBytes_GET_SIZE(tmp);
pnew = type->tp_alloc(type, n);
if (pnew != NULL) {
- Py_MEMCPY(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1);
- ((PyStringObject *)pnew)->ob_shash =
- ((PyStringObject *)tmp)->ob_shash;
- ((PyStringObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;
+ Py_MEMCPY(PyBytes_AS_STRING(pnew), PyBytes_AS_STRING(tmp), n+1);
+ ((PyBytesObject *)pnew)->ob_shash =
+ ((PyBytesObject *)tmp)->ob_shash;
+ ((PyBytesObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;
}
Py_DECREF(tmp);
return pnew;
@@ -4054,11 +4054,11 @@ basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
string_mod(PyObject *v, PyObject *w)
{
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- return PyString_Format(v, w);
+ return PyBytes_Format(v, w);
}
PyDoc_STRVAR(basestring_doc,
@@ -4121,10 +4121,10 @@ PyDoc_STRVAR(string_doc,
Return a nice string representation of the object.\n\
If the argument is a string, the return value is the same object.");
-PyTypeObject PyString_Type = {
+PyTypeObject PyBytes_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"str",
- sizeof(PyStringObject),
+ sizeof(PyBytesObject),
sizeof(char),
string_dealloc, /* tp_dealloc */
(printfunc)string_print, /* tp_print */
@@ -4166,25 +4166,25 @@ PyTypeObject PyString_Type = {
};
void
-PyString_Concat(register PyObject **pv, register PyObject *w)
+PyBytes_Concat(register PyObject **pv, register PyObject *w)
{
register PyObject *v;
if (*pv == NULL)
return;
- if (w == NULL || !PyString_Check(*pv)) {
+ if (w == NULL || !PyBytes_Check(*pv)) {
Py_DECREF(*pv);
*pv = NULL;
return;
}
- v = string_concat((PyStringObject *) *pv, w);
+ v = string_concat((PyBytesObject *) *pv, w);
Py_DECREF(*pv);
*pv = v;
}
void
-PyString_ConcatAndDel(register PyObject **pv, register PyObject *w)
+PyBytes_ConcatAndDel(register PyObject **pv, register PyObject *w)
{
- PyString_Concat(pv, w);
+ PyBytes_Concat(pv, w);
Py_XDECREF(w);
}
@@ -4204,13 +4204,13 @@ PyString_ConcatAndDel(register PyObject **pv, register PyObject *w)
*/
int
-_PyString_Resize(PyObject **pv, Py_ssize_t newsize)
+_PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyObject *v;
- register PyStringObject *sv;
+ register PyBytesObject *sv;
v = *pv;
- if (!PyString_Check(v) || Py_REFCNT(v) != 1 || newsize < 0 ||
- PyString_CHECK_INTERNED(v)) {
+ if (!PyBytes_Check(v) || Py_REFCNT(v) != 1 || newsize < 0 ||
+ PyBytes_CHECK_INTERNED(v)) {
*pv = 0;
Py_DECREF(v);
PyErr_BadInternalCall();
@@ -4220,14 +4220,14 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
_Py_DEC_REFTOTAL;
_Py_ForgetReference(v);
*pv = (PyObject *)
- PyObject_REALLOC((char *)v, sizeof(PyStringObject) + newsize);
+ PyObject_REALLOC((char *)v, sizeof(PyBytesObject) + newsize);
if (*pv == NULL) {
PyObject_Del(v);
PyErr_NoMemory();
return -1;
}
_Py_NewReference(*pv);
- sv = (PyStringObject *) *pv;
+ sv = (PyBytesObject *) *pv;
Py_SIZE(sv) = newsize;
sv->ob_sval[newsize] = '\0';
sv->ob_shash = -1; /* invalidate cached hash value */
@@ -4313,7 +4313,7 @@ formatfloat(char *buf, size_t buflen, int flags,
return (int)strlen(buf);
}
-/* _PyString_FormatLong emulates the format codes d, u, o, x and X, and
+/* _PyBytes_FormatLong emulates the format codes d, u, o, x and X, and
* the F_ALT flag, for Python's long (unbounded) ints. It's not used for
* Python's regular ints.
* Return value: a new PyString*, or NULL if error.
@@ -4335,7 +4335,7 @@ formatfloat(char *buf, size_t buflen, int flags,
* produce a '-' sign, but can for Python's unbounded ints.
*/
PyObject*
-_PyString_FormatLong(PyObject *val, int flags, int prec, int type,
+_PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
char **pbuf, int *plen)
{
PyObject *result = NULL;
@@ -4366,7 +4366,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
if (!result)
return NULL;
- buf = PyString_AsString(result);
+ buf = PyBytes_AsString(result);
if (!buf) {
Py_DECREF(result);
return NULL;
@@ -4377,9 +4377,9 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
PyErr_BadInternalCall();
return NULL;
}
- llen = PyString_Size(result);
+ llen = PyBytes_Size(result);
if (llen > INT_MAX) {
- PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
+ PyErr_SetString(PyExc_ValueError, "string too large in _PyBytes_FormatLong");
return NULL;
}
len = (int)llen;
@@ -4425,14 +4425,14 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
/* Fill with leading zeroes to meet minimum width. */
if (prec > numdigits) {
- PyObject *r1 = PyString_FromStringAndSize(NULL,
+ PyObject *r1 = PyBytes_FromStringAndSize(NULL,
numnondigits + prec);
char *b1;
if (!r1) {
Py_DECREF(result);
return NULL;
}
- b1 = PyString_AS_STRING(r1);
+ b1 = PyBytes_AS_STRING(r1);
for (i = 0; i < numnondigits; ++i)
*b1++ = *buf++;
for (i = 0; i < prec - numdigits; i++)
@@ -4442,7 +4442,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
*b1 = '\0';
Py_DECREF(result);
result = r1;
- buf = PyString_AS_STRING(result);
+ buf = PyBytes_AS_STRING(result);
len = numnondigits + prec;
}
@@ -4536,7 +4536,7 @@ Py_LOCAL_INLINE(int)
formatchar(char *buf, size_t buflen, PyObject *v)
{
/* presume that the buffer is at least 2 characters long */
- if (PyString_Check(v)) {
+ if (PyBytes_Check(v)) {
if (!PyArg_Parse(v, "c;%c requires int or char", &buf[0]))
return -1;
}
@@ -4559,7 +4559,7 @@ formatchar(char *buf, size_t buflen, PyObject *v)
#define FORMATBUFLEN (size_t)120
PyObject *
-PyString_Format(PyObject *format, PyObject *args)
+PyBytes_Format(PyObject *format, PyObject *args)
{
char *fmt, *res;
Py_ssize_t arglen, argidx;
@@ -4570,18 +4570,18 @@ PyString_Format(PyObject *format, PyObject *args)
PyObject *v, *w;
#endif
PyObject *dict = NULL;
- if (format == NULL || !PyString_Check(format) || args == NULL) {
+ if (format == NULL || !PyBytes_Check(format) || args == NULL) {
PyErr_BadInternalCall();
return NULL;
}
orig_args = args;
- fmt = PyString_AS_STRING(format);
- fmtcnt = PyString_GET_SIZE(format);
+ fmt = PyBytes_AS_STRING(format);
+ fmtcnt = PyBytes_GET_SIZE(format);
reslen = rescnt = fmtcnt + 100;
- result = PyString_FromStringAndSize((char *)NULL, reslen);
+ result = PyBytes_FromStringAndSize((char *)NULL, reslen);
if (result == NULL)
return NULL;
- res = PyString_AsString(result);
+ res = PyBytes_AsString(result);
if (PyTuple_Check(args)) {
arglen = PyTuple_GET_SIZE(args);
argidx = 0;
@@ -4598,9 +4598,9 @@ PyString_Format(PyObject *format, PyObject *args)
if (--rescnt < 0) {
rescnt = fmtcnt + 100;
reslen += rescnt;
- if (_PyString_Resize(&result, reslen) < 0)
+ if (_PyBytes_Resize(&result, reslen) < 0)
return NULL;
- res = PyString_AS_STRING(result)
+ res = PyBytes_AS_STRING(result)
+ reslen - rescnt;
--rescnt;
}
@@ -4655,7 +4655,7 @@ PyString_Format(PyObject *format, PyObject *args)
"incomplete format key");
goto error;
}
- key = PyString_FromStringAndSize(keystart,
+ key = PyBytes_FromStringAndSize(keystart,
keylen);
if (key == NULL)
goto error;
@@ -4796,14 +4796,14 @@ PyString_Format(PyObject *format, PyObject *args)
temp = PyObject_Repr(v);
if (temp == NULL)
goto error;
- if (!PyString_Check(temp)) {
+ if (!PyBytes_Check(temp)) {
PyErr_SetString(PyExc_TypeError,
"%s argument has non-string str()");
Py_DECREF(temp);
goto error;
}
- pbuf = PyString_AS_STRING(temp);
- len = PyString_GET_SIZE(temp);
+ pbuf = PyBytes_AS_STRING(temp);
+ len = PyBytes_GET_SIZE(temp);
if (prec >= 0 && len > prec)
len = prec;
break;
@@ -4843,7 +4843,7 @@ PyString_Format(PyObject *format, PyObject *args)
int ilen;
isnumok = 1;
- temp = _PyString_FormatLong(iobj, flags,
+ temp = _PyBytes_FormatLong(iobj, flags,
prec, c, &pbuf, &ilen);
Py_DECREF(iobj);
len = ilen;
@@ -4901,7 +4901,7 @@ PyString_Format(PyObject *format, PyObject *args)
"at index %zd",
c, c,
(Py_ssize_t)(fmt - 1 -
- PyString_AsString(format)));
+ PyBytes_AsString(format)));
goto error;
}
if (sign) {
@@ -4927,11 +4927,11 @@ PyString_Format(PyObject *format, PyObject *args)
Py_XDECREF(temp);
return PyErr_NoMemory();
}
- if (_PyString_Resize(&result, reslen) < 0) {
+ if (_PyBytes_Resize(&result, reslen) < 0) {
Py_XDECREF(temp);
return NULL;
}
- res = PyString_AS_STRING(result)
+ res = PyBytes_AS_STRING(result)
+ reslen - rescnt;
}
if (sign) {
@@ -4995,7 +4995,7 @@ PyString_Format(PyObject *format, PyObject *args)
if (args_owned) {
Py_DECREF(args);
}
- _PyString_Resize(&result, reslen - rescnt);
+ _PyBytes_Resize(&result, reslen - rescnt);
return result;
#ifdef Py_USING_UNICODE
@@ -5024,11 +5024,11 @@ PyString_Format(PyObject *format, PyObject *args)
args_owned = 1;
/* Take what we have of the result and let the Unicode formatting
function format the rest of the input. */
- rescnt = res - PyString_AS_STRING(result);
- if (_PyString_Resize(&result, rescnt))
+ rescnt = res - PyBytes_AS_STRING(result);
+ if (_PyBytes_Resize(&result, rescnt))
goto error;
- fmtcnt = PyString_GET_SIZE(format) - \
- (fmt - PyString_AS_STRING(format));
+ fmtcnt = PyBytes_GET_SIZE(format) - \
+ (fmt - PyBytes_AS_STRING(format));
format = PyUnicode_Decode(fmt, fmtcnt, NULL, NULL);
if (format == NULL)
goto error;
@@ -5054,17 +5054,17 @@ PyString_Format(PyObject *format, PyObject *args)
}
void
-PyString_InternInPlace(PyObject **p)
+PyBytes_InternInPlace(PyObject **p)
{
- register PyStringObject *s = (PyStringObject *)(*p);
+ register PyBytesObject *s = (PyBytesObject *)(*p);
PyObject *t;
- if (s == NULL || !PyString_Check(s))
- Py_FatalError("PyString_InternInPlace: strings only please!");
+ if (s == NULL || !PyBytes_Check(s))
+ Py_FatalError("PyBytes_InternInPlace: strings only please!");
/* If it's a string subclass, we don't really know what putting
it in the interned dict might do. */
- if (!PyString_CheckExact(s))
+ if (!PyBytes_CheckExact(s))
return;
- if (PyString_CHECK_INTERNED(s))
+ if (PyBytes_CHECK_INTERNED(s))
return;
if (interned == NULL) {
interned = PyDict_New();
@@ -5088,32 +5088,32 @@ PyString_InternInPlace(PyObject **p)
/* The two references in interned are not counted by refcnt.
The string deallocator will take care of this */
Py_REFCNT(s) -= 2;
- PyString_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
+ PyBytes_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
}
void
-PyString_InternImmortal(PyObject **p)
+PyBytes_InternImmortal(PyObject **p)
{
- PyString_InternInPlace(p);
- if (PyString_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
- PyString_CHECK_INTERNED(*p) = SSTATE_INTERNED_IMMORTAL;
+ PyBytes_InternInPlace(p);
+ if (PyBytes_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
+ PyBytes_CHECK_INTERNED(*p) = SSTATE_INTERNED_IMMORTAL;
Py_INCREF(*p);
}
}
PyObject *
-PyString_InternFromString(const char *cp)
+PyBytes_InternFromString(const char *cp)
{
- PyObject *s = PyString_FromString(cp);
+ PyObject *s = PyBytes_FromString(cp);
if (s == NULL)
return NULL;
- PyString_InternInPlace(&s);
+ PyBytes_InternInPlace(&s);
return s;
}
void
-PyString_Fini(void)
+PyBytes_Fini(void)
{
int i;
for (i = 0; i < UCHAR_MAX + 1; i++) {
@@ -5127,7 +5127,7 @@ PyString_Fini(void)
void _Py_ReleaseInternedStrings(void)
{
PyObject *keys;
- PyStringObject *s;
+ PyBytesObject *s;
Py_ssize_t i, n;
Py_ssize_t immortal_size = 0, mortal_size = 0;
@@ -5148,7 +5148,7 @@ void _Py_ReleaseInternedStrings(void)
fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n",
n);
for (i = 0; i < n; i++) {
- s = (PyStringObject *) PyList_GET_ITEM(keys, i);
+ s = (PyBytesObject *) PyList_GET_ITEM(keys, i);
switch (s->ob_sstate) {
case SSTATE_NOT_INTERNED:
/* XXX Shouldn't happen */
diff --git a/Objects/structseq.c b/Objects/structseq.c
index b6126ba..c348254 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -270,7 +270,7 @@ structseq_repr(PyStructSequence *obj)
Py_DECREF(tup);
return NULL;
}
- crepr = PyString_AsString(repr);
+ crepr = PyBytes_AsString(repr);
if (crepr == NULL) {
Py_DECREF(tup);
Py_DECREF(repr);
@@ -306,7 +306,7 @@ structseq_repr(PyStructSequence *obj)
*pbuf++ = ')';
*pbuf = '\0';
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyObject *
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index e9cb3ef..0524aae 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -218,7 +218,7 @@ tuplerepr(PyTupleObject *v)
n = Py_SIZE(v);
if (n == 0)
- return PyString_FromString("()");
+ return PyBytes_FromString("()");
/* While not mutable, it is still possible to end up with a cycle in a
tuple through an object that stores itself within a tuple (and thus
@@ -226,7 +226,7 @@ tuplerepr(PyTupleObject *v)
possible within a type. */
i = Py_ReprEnter((PyObject *)v);
if (i != 0) {
- return i > 0 ? PyString_FromString("(...)") : NULL;
+ return i > 0 ? PyBytes_FromString("(...)") : NULL;
}
pieces = PyTuple_New(n);
@@ -246,29 +246,29 @@ tuplerepr(PyTupleObject *v)
/* Add "()" decorations to the first and last items. */
assert(n > 0);
- s = PyString_FromString("(");
+ s = PyBytes_FromString("(");
if (s == NULL)
goto Done;
temp = PyTuple_GET_ITEM(pieces, 0);
- PyString_ConcatAndDel(&s, temp);
+ PyBytes_ConcatAndDel(&s, temp);
PyTuple_SET_ITEM(pieces, 0, s);
if (s == NULL)
goto Done;
- s = PyString_FromString(n == 1 ? ",)" : ")");
+ s = PyBytes_FromString(n == 1 ? ",)" : ")");
if (s == NULL)
goto Done;
temp = PyTuple_GET_ITEM(pieces, n-1);
- PyString_ConcatAndDel(&temp, s);
+ PyBytes_ConcatAndDel(&temp, s);
PyTuple_SET_ITEM(pieces, n-1, temp);
if (temp == NULL)
goto Done;
/* Paste them all together with ", " between. */
- s = PyString_FromString(", ");
+ s = PyBytes_FromString(", ");
if (s == NULL)
goto Done;
- result = _PyString_Join(s, pieces);
+ result = _PyBytes_Join(s, pieces);
Py_DECREF(s);
Done:
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index c3aa090..2ea3d29 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -19,10 +19,10 @@
>> (8*sizeof(unsigned int) - MCACHE_SIZE_EXP))
#define MCACHE_HASH_METHOD(type, name) \
MCACHE_HASH((type)->tp_version_tag, \
- ((PyStringObject *)(name))->ob_shash)
+ ((PyBytesObject *)(name))->ob_shash)
#define MCACHE_CACHEABLE_NAME(name) \
- PyString_CheckExact(name) && \
- PyString_GET_SIZE(name) <= MCACHE_MAX_ATTR_SIZE
+ PyBytes_CheckExact(name) && \
+ PyBytes_GET_SIZE(name) <= MCACHE_MAX_ATTR_SIZE
struct method_cache_entry {
unsigned int version;
@@ -218,7 +218,7 @@ type_name(PyTypeObject *type, void *context)
s = type->tp_name;
else
s++;
- return PyString_FromString(s);
+ return PyBytes_FromString(s);
}
}
@@ -237,14 +237,14 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
"can't delete %s.__name__", type->tp_name);
return -1;
}
- if (!PyString_Check(value)) {
+ if (!PyBytes_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;
}
- if (strlen(PyString_AS_STRING(value))
- != (size_t)PyString_GET_SIZE(value)) {
+ if (strlen(PyBytes_AS_STRING(value))
+ != (size_t)PyBytes_GET_SIZE(value)) {
PyErr_Format(PyExc_ValueError,
"__name__ must not contain null bytes");
return -1;
@@ -257,7 +257,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
Py_DECREF(et->ht_name);
et->ht_name = value;
- type->tp_name = PyString_AS_STRING(value);
+ type->tp_name = PyBytes_AS_STRING(value);
return 0;
}
@@ -280,9 +280,9 @@ type_module(PyTypeObject *type, void *context)
else {
s = strrchr(type->tp_name, '.');
if (s != NULL)
- return PyString_FromStringAndSize(
+ return PyBytes_FromStringAndSize(
type->tp_name, (Py_ssize_t)(s - type->tp_name));
- return PyString_FromString("__builtin__");
+ return PyBytes_FromString("__builtin__");
}
}
@@ -556,7 +556,7 @@ type_get_doc(PyTypeObject *type, void *context)
{
PyObject *result;
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL)
- return PyString_FromString(type->tp_doc);
+ return PyBytes_FromString(type->tp_doc);
result = PyDict_GetItemString(type->tp_dict, "__doc__");
if (result == NULL) {
result = Py_None;
@@ -645,7 +645,7 @@ type_repr(PyTypeObject *type)
mod = type_module(type, NULL);
if (mod == NULL)
PyErr_Clear();
- else if (!PyString_Check(mod)) {
+ else if (!PyBytes_Check(mod)) {
Py_DECREF(mod);
mod = NULL;
}
@@ -658,14 +658,14 @@ type_repr(PyTypeObject *type)
else
kind = "type";
- if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) {
- rtn = PyString_FromFormat("<%s '%s.%s'>",
+ if (mod != NULL && strcmp(PyBytes_AS_STRING(mod), "__builtin__")) {
+ rtn = PyBytes_FromFormat("<%s '%s.%s'>",
kind,
- PyString_AS_STRING(mod),
- PyString_AS_STRING(name));
+ PyBytes_AS_STRING(mod),
+ PyBytes_AS_STRING(name));
}
else
- rtn = PyString_FromFormat("<%s '%s'>", kind, type->tp_name);
+ rtn = PyBytes_FromFormat("<%s '%s'>", kind, type->tp_name);
Py_XDECREF(mod);
Py_DECREF(name);
@@ -1137,7 +1137,7 @@ lookup_maybe(PyObject *self, char *attrstr, PyObject **attrobj)
PyObject *res;
if (*attrobj == NULL) {
- *attrobj = PyString_InternFromString(attrstr);
+ *attrobj = PyBytes_InternFromString(attrstr);
if (*attrobj == NULL)
return NULL;
}
@@ -1329,7 +1329,7 @@ class_name(PyObject *cls)
}
if (name == NULL)
return NULL;
- if (!PyString_Check(name)) {
+ if (!PyBytes_Check(name)) {
Py_DECREF(name);
return NULL;
}
@@ -1351,7 +1351,7 @@ check_duplicates(PyObject *list)
o = class_name(o);
PyErr_Format(PyExc_TypeError,
"duplicate base class %s",
- o ? PyString_AS_STRING(o) : "?");
+ o ? PyBytes_AS_STRING(o) : "?");
Py_XDECREF(o);
return -1;
}
@@ -1397,7 +1397,7 @@ consistent method resolution\norder (MRO) for bases");
while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
PyObject *name = class_name(k);
off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s",
- name ? PyString_AS_STRING(name) : "?");
+ name ? PyBytes_AS_STRING(name) : "?");
Py_XDECREF(name);
if (--n && (size_t)(off+1) < sizeof(buf)) {
buf[off++] = ',';
@@ -1750,7 +1750,7 @@ get_dict_descriptor(PyTypeObject *type)
PyObject *descr;
if (dict_str == NULL) {
- dict_str = PyString_InternFromString("__dict__");
+ dict_str = PyBytes_InternFromString("__dict__");
if (dict_str == NULL)
return NULL;
}
@@ -1899,14 +1899,14 @@ valid_identifier(PyObject *s)
unsigned char *p;
Py_ssize_t i, n;
- if (!PyString_Check(s)) {
+ if (!PyBytes_Check(s)) {
PyErr_Format(PyExc_TypeError,
"__slots__ items must be strings, not '%.200s'",
Py_TYPE(s)->tp_name);
return 0;
}
- p = (unsigned char *) PyString_AS_STRING(s);
- n = PyString_GET_SIZE(s);
+ p = (unsigned char *) PyBytes_AS_STRING(s);
+ n = PyBytes_GET_SIZE(s);
/* We must reject an empty name. As a hack, we bump the
length to 1 so that the loop will balk on the trailing \0. */
if (n == 0)
@@ -2108,7 +2108,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
/* Have slots */
/* Make it into a tuple */
- if (PyString_Check(slots) || PyUnicode_Check(slots))
+ if (PyBytes_Check(slots) || PyUnicode_Check(slots))
slots = PyTuple_Pack(1, slots);
else
slots = PySequence_Tuple(slots);
@@ -2146,8 +2146,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
char *s;
if (!valid_identifier(tmp))
goto bad_slots;
- assert(PyString_Check(tmp));
- s = PyString_AS_STRING(tmp);
+ assert(PyBytes_Check(tmp));
+ s = PyBytes_AS_STRING(tmp);
if (strcmp(s, "__dict__") == 0) {
if (!may_add_dict || add_dict) {
PyErr_SetString(PyExc_TypeError,
@@ -2179,7 +2179,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
for (i = j = 0; i < nslots; i++) {
char *s;
tmp = PyTuple_GET_ITEM(slots, i);
- s = PyString_AS_STRING(tmp);
+ s = PyBytes_AS_STRING(tmp);
if ((add_dict && strcmp(s, "__dict__") == 0) ||
(add_weak && strcmp(s, "__weakref__") == 0))
continue;
@@ -2272,7 +2272,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type->tp_as_sequence = &et->as_sequence;
type->tp_as_mapping = &et->as_mapping;
type->tp_as_buffer = &et->as_buffer;
- type->tp_name = PyString_AS_STRING(name);
+ type->tp_name = PyBytes_AS_STRING(name);
/* Set tp_base and tp_bases */
type->tp_bases = bases;
@@ -2305,14 +2305,14 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
*/
{
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
- if (doc != NULL && PyString_Check(doc)) {
- const size_t n = (size_t)PyString_GET_SIZE(doc);
+ if (doc != NULL && PyBytes_Check(doc)) {
+ const size_t n = (size_t)PyBytes_GET_SIZE(doc);
char *tp_doc = (char *)PyObject_MALLOC(n+1);
if (tp_doc == NULL) {
Py_DECREF(type);
return NULL;
}
- memcpy(tp_doc, PyString_AS_STRING(doc), n+1);
+ memcpy(tp_doc, PyBytes_AS_STRING(doc), n+1);
type->tp_doc = tp_doc;
}
}
@@ -2335,7 +2335,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
slotoffset = base->tp_basicsize;
if (slots != NULL) {
for (i = 0; i < nslots; i++, mp++) {
- mp->name = PyString_AS_STRING(
+ mp->name = PyBytes_AS_STRING(
PyTuple_GET_ITEM(slots, i));
mp->type = T_OBJECT_EX;
mp->offset = slotoffset;
@@ -2536,7 +2536,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
/* Give up */
PyErr_Format(PyExc_AttributeError,
"type object '%.50s' has no attribute '%.400s'",
- type->tp_name, PyString_AS_STRING(name));
+ type->tp_name, PyBytes_AS_STRING(name));
return NULL;
}
@@ -2855,7 +2855,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (sorted_methods == NULL)
goto error;
if (comma == NULL) {
- comma = PyString_InternFromString(", ");
+ comma = PyBytes_InternFromString(", ");
if (comma == NULL)
goto error;
}
@@ -2863,7 +2863,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
"O", sorted_methods);
if (joined == NULL)
goto error;
- joined_str = PyString_AsString(joined);
+ joined_str = PyBytes_AsString(joined);
if (joined_str == NULL)
goto error;
@@ -2897,20 +2897,20 @@ object_repr(PyObject *self)
mod = type_module(type, NULL);
if (mod == NULL)
PyErr_Clear();
- else if (!PyString_Check(mod)) {
+ else if (!PyBytes_Check(mod)) {
Py_DECREF(mod);
mod = NULL;
}
name = type_name(type, NULL);
if (name == NULL)
return NULL;
- if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__"))
- rtn = PyString_FromFormat("<%s.%s object at %p>",
- PyString_AS_STRING(mod),
- PyString_AS_STRING(name),
+ if (mod != NULL && strcmp(PyBytes_AS_STRING(mod), "__builtin__"))
+ rtn = PyBytes_FromFormat("<%s.%s object at %p>",
+ PyBytes_AS_STRING(mod),
+ PyBytes_AS_STRING(name),
self);
else
- rtn = PyString_FromFormat("<%s object at %p>",
+ rtn = PyBytes_FromFormat("<%s object at %p>",
type->tp_name, self);
Py_XDECREF(mod);
Py_DECREF(name);
@@ -3070,7 +3070,7 @@ import_copyreg(void)
static PyObject *copyreg_str;
if (!copyreg_str) {
- copyreg_str = PyString_InternFromString("copy_reg");
+ copyreg_str = PyBytes_InternFromString("copy_reg");
if (copyreg_str == NULL)
return NULL;
}
@@ -3376,7 +3376,7 @@ object_format(PyObject *self, PyObject *args)
return NULL;
if (PyUnicode_Check(format_spec)) {
self_as_str = PyObject_Unicode(self);
- } else if (PyString_Check(format_spec)) {
+ } else if (PyBytes_Check(format_spec)) {
self_as_str = PyObject_Str(self);
} else {
PyErr_SetString(PyExc_TypeError, "argument to __format__ must be unicode or str");
@@ -3619,7 +3619,7 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
type->tp_flags |= Py_TPFLAGS_INT_SUBCLASS;
else if (PyType_IsSubtype(base, &PyLong_Type))
type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
- else if (PyType_IsSubtype(base, &PyString_Type))
+ else if (PyType_IsSubtype(base, &PyBytes_Type))
type->tp_flags |= Py_TPFLAGS_STRING_SUBCLASS;
#ifdef Py_USING_UNICODE
else if (PyType_IsSubtype(base, &PyUnicode_Type))
@@ -3958,7 +3958,7 @@ PyType_Ready(PyTypeObject *type)
*/
if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
if (type->tp_doc != NULL) {
- PyObject *doc = PyString_FromString(type->tp_doc);
+ PyObject *doc = PyBytes_FromString(type->tp_doc);
if (doc == NULL)
goto error;
PyDict_SetItemString(type->tp_dict, "__doc__", doc);
@@ -4846,7 +4846,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
descrgetfunc f;
if (getitem_str == NULL) {
- getitem_str = PyString_InternFromString("__getitem__");
+ getitem_str = PyBytes_InternFromString("__getitem__");
if (getitem_str == NULL)
return NULL;
}
@@ -5214,7 +5214,7 @@ slot_tp_repr(PyObject *self)
return res;
}
PyErr_Clear();
- return PyString_FromFormat("<%s object at %p>",
+ return PyBytes_FromFormat("<%s object at %p>",
Py_TYPE(self)->tp_name, self);
}
@@ -5322,13 +5322,13 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
static PyObject *getattr_str = NULL;
if (getattr_str == NULL) {
- getattr_str = PyString_InternFromString("__getattr__");
+ getattr_str = PyBytes_InternFromString("__getattr__");
if (getattr_str == NULL)
return NULL;
}
if (getattribute_str == NULL) {
getattribute_str =
- PyString_InternFromString("__getattribute__");
+ PyBytes_InternFromString("__getattribute__");
if (getattribute_str == NULL)
return NULL;
}
@@ -5469,7 +5469,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
static PyObject *get_str = NULL;
if (get_str == NULL) {
- get_str = PyString_InternFromString("__get__");
+ get_str = PyBytes_InternFromString("__get__");
if (get_str == NULL)
return NULL;
}
@@ -5539,7 +5539,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_ssize_t i, n;
if (new_str == NULL) {
- new_str = PyString_InternFromString("__new__");
+ new_str = PyBytes_InternFromString("__new__");
if (new_str == NULL)
return NULL;
}
@@ -6069,7 +6069,7 @@ init_slotdefs(void)
if (initialized)
return;
for (p = slotdefs; p->name; p++) {
- p->name_strobj = PyString_InternFromString(p->name);
+ p->name_strobj = PyBytes_InternFromString(p->name);
if (!p->name_strobj)
Py_FatalError("Out of memory interning slotdef names");
}
@@ -6284,12 +6284,12 @@ super_repr(PyObject *self)
superobject *su = (superobject *)self;
if (su->obj_type)
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"<super: <class '%s'>, <%s object>>",
su->type ? su->type->tp_name : "NULL",
su->obj_type->tp_name);
else
- return PyString_FromFormat(
+ return PyBytes_FromFormat(
"<super: <class '%s'>, NULL>",
su->type ? su->type->tp_name : "NULL");
}
@@ -6303,9 +6303,9 @@ super_getattro(PyObject *self, PyObject *name)
if (!skip) {
/* We want __class__ to return the class of the super object
(i.e. super, or a subclass), not the class of su->obj. */
- skip = (PyString_Check(name) &&
- PyString_GET_SIZE(name) == 9 &&
- strcmp(PyString_AS_STRING(name), "__class__") == 0);
+ skip = (PyBytes_Check(name) &&
+ PyBytes_GET_SIZE(name) == 9 &&
+ strcmp(PyBytes_AS_STRING(name), "__class__") == 0);
}
if (!skip) {
@@ -6397,7 +6397,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
PyObject *class_attr;
if (class_str == NULL) {
- class_str = PyString_FromString("__class__");
+ class_str = PyBytes_FromString("__class__");
if (class_str == NULL)
return NULL;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index c008bd6..7af560c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1080,9 +1080,9 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
#endif
/* 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 (PyByteArray_Check(obj)) {
/* Python 2.x specific */
@@ -1254,7 +1254,7 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
v = PyCodec_Encode(unicode, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
Py_TYPE(v)->tp_name);
@@ -1654,13 +1654,13 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
char * start;
if (size == 0)
- return PyString_FromStringAndSize(NULL, 0);
+ return PyBytes_FromStringAndSize(NULL, 0);
- v = PyString_FromStringAndSize(NULL, cbAllocated);
+ v = PyBytes_FromStringAndSize(NULL, cbAllocated);
if (v == NULL)
return NULL;
- start = out = PyString_AS_STRING(v);
+ start = out = PyBytes_AS_STRING(v);
for (;i < size; ++i) {
Py_UNICODE ch = s[i];
@@ -1726,7 +1726,7 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
*out++ = '-';
}
- _PyString_Resize(&v, out - start);
+ _PyBytes_Resize(&v, out - start);
return v;
}
@@ -1991,10 +1991,10 @@ PyUnicode_EncodeUTF8(const Py_UNICODE *s,
nallocated = size * 4;
if (nallocated / 4 != size) /* overflow! */
return PyErr_NoMemory();
- v = PyString_FromStringAndSize(NULL, nallocated);
+ v = PyBytes_FromStringAndSize(NULL, nallocated);
if (v == NULL)
return NULL;
- p = PyString_AS_STRING(v);
+ p = PyBytes_AS_STRING(v);
}
for (i = 0; i < size;) {
@@ -2042,13 +2042,13 @@ encodeUCS4:
/* This was stack allocated. */
nneeded = p - stackbuf;
assert(nneeded <= nallocated);
- v = PyString_FromStringAndSize(stackbuf, nneeded);
+ v = PyBytes_FromStringAndSize(stackbuf, nneeded);
}
else {
/* Cut back to size actually needed. */
- nneeded = p - PyString_AS_STRING(v);
+ nneeded = p - PyBytes_AS_STRING(v);
assert(nneeded <= nallocated);
- _PyString_Resize(&v, nneeded);
+ _PyBytes_Resize(&v, nneeded);
}
return v;
@@ -2276,12 +2276,12 @@ PyUnicode_EncodeUTF32(const Py_UNICODE *s,
0xDC00 <= s[i+1] && s[i+1] <= 0xDFFF)
pairs++;
#endif
- v = PyString_FromStringAndSize(NULL,
+ v = PyBytes_FromStringAndSize(NULL,
4 * (size - pairs + (byteorder == 0)));
if (v == NULL)
return NULL;
- p = (unsigned char *)PyString_AS_STRING(v);
+ p = (unsigned char *)PyBytes_AS_STRING(v);
if (byteorder == 0)
STORECHAR(0xFEFF);
if (size == 0)
@@ -2541,12 +2541,12 @@ PyUnicode_EncodeUTF16(const Py_UNICODE *s,
if (s[i] >= 0x10000)
pairs++;
#endif
- v = PyString_FromStringAndSize(NULL,
+ v = PyBytes_FromStringAndSize(NULL,
2 * (size + pairs + (byteorder == 0)));
if (v == NULL)
return NULL;
- p = (unsigned char *)PyString_AS_STRING(v);
+ p = (unsigned char *)PyBytes_AS_STRING(v);
if (byteorder == 0)
STORECHAR(0xFEFF);
if (size == 0)
@@ -2889,7 +2889,7 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
escape.
*/
- repr = PyString_FromStringAndSize(NULL,
+ repr = PyBytes_FromStringAndSize(NULL,
2
#ifdef Py_UNICODE_WIDE
+ 10*size
@@ -2900,7 +2900,7 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
if (repr == NULL)
return NULL;
- p = PyString_AS_STRING(repr);
+ p = PyBytes_AS_STRING(repr);
if (quotes) {
*p++ = 'u';
@@ -2912,7 +2912,7 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
/* Escape quotes and backslashes */
if ((quotes &&
- ch == (Py_UNICODE) PyString_AS_STRING(repr)[1]) || ch == '\\') {
+ ch == (Py_UNICODE) PyBytes_AS_STRING(repr)[1]) || ch == '\\') {
*p++ = '\\';
*p++ = (char) ch;
continue;
@@ -2998,10 +2998,10 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
*p++ = (char) ch;
}
if (quotes)
- *p++ = PyString_AS_STRING(repr)[1];
+ *p++ = PyBytes_AS_STRING(repr)[1];
*p = '\0';
- _PyString_Resize(&repr, p - PyString_AS_STRING(repr));
+ _PyBytes_Resize(&repr, p - PyBytes_AS_STRING(repr));
return repr;
}
@@ -3150,16 +3150,16 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
static const char *hexdigit = "0123456789abcdef";
#ifdef Py_UNICODE_WIDE
- repr = PyString_FromStringAndSize(NULL, 10 * size);
+ repr = PyBytes_FromStringAndSize(NULL, 10 * size);
#else
- repr = PyString_FromStringAndSize(NULL, 6 * size);
+ repr = PyBytes_FromStringAndSize(NULL, 6 * size);
#endif
if (repr == NULL)
return NULL;
if (size == 0)
return repr;
- p = q = PyString_AS_STRING(repr);
+ p = q = PyBytes_AS_STRING(repr);
while (size-- > 0) {
Py_UNICODE ch = *s++;
#ifdef Py_UNICODE_WIDE
@@ -3218,7 +3218,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
*p++ = (char) ch;
}
*p = '\0';
- _PyString_Resize(&repr, p - q);
+ _PyBytes_Resize(&repr, p - q);
return repr;
}
@@ -3458,12 +3458,12 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
/* 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)
return res;
- str = PyString_AS_STRING(res);
+ str = PyBytes_AS_STRING(res);
ressize = size;
while (p<endp) {
@@ -3513,7 +3513,7 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
p = collend;
break;
case 4: /* xmlcharrefreplace */
- respos = str-PyString_AS_STRING(res);
+ respos = str-PyBytes_AS_STRING(res);
/* determine replacement size (temporarily (mis)uses p) */
for (p = collstart, repsize = 0; p < collend; ++p) {
if (*p<10)
@@ -3540,9 +3540,9 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
if (requiredsize > ressize) {
if (requiredsize<2*ressize)
requiredsize = 2*ressize;
- if (_PyString_Resize(&res, requiredsize))
+ if (_PyBytes_Resize(&res, requiredsize))
goto onError;
- str = PyString_AS_STRING(res) + respos;
+ str = PyBytes_AS_STRING(res) + respos;
ressize = requiredsize;
}
/* generate replacement (temporarily (mis)uses p) */
@@ -3560,17 +3560,17 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
/* need more space? (at least enough for what we
have+the replacement+the rest of the string, so
we won't have to check space for encodable characters) */
- respos = str-PyString_AS_STRING(res);
+ respos = str-PyBytes_AS_STRING(res);
repsize = PyUnicode_GET_SIZE(repunicode);
requiredsize = respos+repsize+(endp-collend);
if (requiredsize > ressize) {
if (requiredsize<2*ressize)
requiredsize = 2*ressize;
- if (_PyString_Resize(&res, requiredsize)) {
+ if (_PyBytes_Resize(&res, requiredsize)) {
Py_DECREF(repunicode);
goto onError;
}
- str = PyString_AS_STRING(res) + respos;
+ str = PyBytes_AS_STRING(res) + respos;
ressize = requiredsize;
}
/* check if there is anything unencodable in the replacement
@@ -3591,10 +3591,10 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
}
}
/* Resize if we allocated to much */
- respos = str-PyString_AS_STRING(res);
+ respos = str-PyBytes_AS_STRING(res);
if (respos<ressize)
/* If this falls res will be NULL */
- _PyString_Resize(&res, respos);
+ _PyBytes_Resize(&res, respos);
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
return res;
@@ -3671,7 +3671,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
goto onError;
}
}
- if (p - PyUnicode_AS_UNICODE(v) < PyString_GET_SIZE(v))
+ if (p - PyUnicode_AS_UNICODE(v) < PyBytes_GET_SIZE(v))
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
goto onError;
Py_XDECREF(errorHandler);
@@ -3849,20 +3849,20 @@ static int encode_mbcs(PyObject **repr,
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;
@@ -4329,7 +4329,7 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping)
}
return x;
}
- else if (PyString_Check(x))
+ else if (PyBytes_Check(x))
return x;
else {
/* wrong return value */
@@ -4343,11 +4343,11 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping)
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 0;
}
return 1;
@@ -4368,7 +4368,7 @@ charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
{
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);
@@ -4378,7 +4378,7 @@ charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
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;
}
@@ -4397,19 +4397,19 @@ charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
Py_DECREF(rep);
return enc_EXCEPTION;
}
- outstart = PyString_AS_STRING(*outobj);
+ outstart = PyBytes_AS_STRING(*outobj);
outstart[(*outpos)++] = (char)PyInt_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;
}
@@ -4560,7 +4560,7 @@ PyObject *PyUnicode_EncodeCharmap(const Py_UNICODE *p,
/* 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)
@@ -4585,8 +4585,8 @@ PyObject *PyUnicode_EncodeCharmap(const Py_UNICODE *p,
}
/* Resize if we allocated to much */
- if (respos<PyString_GET_SIZE(res)) {
- if (_PyString_Resize(&res, respos))
+ if (respos<PyBytes_GET_SIZE(res)) {
+ if (_PyBytes_Resize(&res, respos))
goto onError;
}
Py_XDECREF(exc);
@@ -5484,7 +5484,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
item = PySequence_Fast_GET_ITEM(fseq, i);
/* Convert item to Unicode. */
- if (! PyUnicode_Check(item) && ! PyString_Check(item)) {
+ if (! PyUnicode_Check(item) && ! PyBytes_Check(item)) {
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string or Unicode,"
" %.80s found",
@@ -6488,7 +6488,7 @@ unicode_encode(PyUnicodeObject *self, PyObject *args)
v = PyUnicode_AsEncodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
@@ -6524,7 +6524,7 @@ unicode_decode(PyUnicodeObject *self, PyObject *args)
v = PyUnicode_AsDecodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyString_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
@@ -7154,7 +7154,7 @@ do_argstrip(PyUnicodeObject *self, int striptype, PyObject *args)
if (sep != NULL && sep != Py_None) {
if (PyUnicode_Check(sep))
return _PyUnicode_XStrip(self, striptype, sep);
- else if (PyString_Check(sep)) {
+ else if (PyBytes_Check(sep)) {
PyObject *res;
sep = PyUnicode_FromObject(sep);
if (sep==NULL)
@@ -8071,8 +8071,8 @@ unicode_buffer_getcharbuf(PyUnicodeObject *self,
str = _PyUnicode_AsDefaultEncodedString((PyObject *)self, NULL);
if (str == NULL)
return -1;
- *ptr = (void *) PyString_AS_STRING(str);
- return PyString_GET_SIZE(str);
+ *ptr = (void *) PyBytes_AS_STRING(str);
+ return PyBytes_GET_SIZE(str);
}
/* Helpers for PyUnicode_Format() */
@@ -8191,7 +8191,7 @@ formatlong(PyObject *val, int flags, int prec, int type)
PyObject *str; /* temporary string object. */
PyUnicodeObject *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_New(len);
@@ -8293,10 +8293,10 @@ formatchar(Py_UNICODE *buf,
buf[0] = PyUnicode_AS_UNICODE(v)[0];
}
- else if (PyString_Check(v)) {
- if (PyString_GET_SIZE(v) != 1)
+ else if (PyBytes_Check(v)) {
+ if (PyBytes_GET_SIZE(v) != 1)
goto onError;
- buf[0] = (Py_UNICODE)PyString_AS_STRING(v)[0];
+ buf[0] = (Py_UNICODE)PyBytes_AS_STRING(v)[0];
}
else {
@@ -8579,10 +8579,10 @@ PyObject *PyUnicode_Format(PyObject *format,
goto onError;
if (PyUnicode_Check(temp))
/* nothing to do */;
- else if (PyString_Check(temp)) {
+ else if (PyBytes_Check(temp)) {
/* convert to string to Unicode */
- unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
- PyString_GET_SIZE(temp),
+ unicode = PyUnicode_Decode(PyBytes_AS_STRING(temp),
+ PyBytes_GET_SIZE(temp),
NULL,
"strict");
Py_DECREF(temp);
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 1aee5a5..2899bc70 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -166,8 +166,8 @@ weakref_repr(PyWeakReference *self)
"__name__");
if (nameobj == NULL)
PyErr_Clear();
- else if (PyString_Check(nameobj))
- name = PyString_AS_STRING(nameobj);
+ else if (PyBytes_Check(nameobj))
+ name = PyBytes_AS_STRING(nameobj);
PyOS_snprintf(buffer, sizeof(buffer),
name ? "<weakref at %p; to '%.50s' at %p (%s)>"
: "<weakref at %p; to '%.50s' at %p>",
@@ -177,7 +177,7 @@ weakref_repr(PyWeakReference *self)
name);
Py_XDECREF(nameobj);
}
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
/* Weak references only support equality, not ordering. Two weak references
@@ -448,7 +448,7 @@ proxy_repr(PyWeakReference *proxy)
"<weakproxy at %p to %.100s at %p>", proxy,
Py_TYPE(PyWeakref_GET_OBJECT(proxy))->tp_name,
PyWeakref_GET_OBJECT(proxy));
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}