mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
This commit is contained in:
parent
f75976617b
commit
339d0f720e
42 changed files with 465 additions and 185 deletions
|
|
@ -583,8 +583,10 @@ PyNumber_Remainder(PyObject *v, PyObject *w)
|
|||
{
|
||||
if (PyString_Check(v))
|
||||
return PyString_Format(v, w);
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(v))
|
||||
return PyUnicode_Format(v, w);
|
||||
#endif
|
||||
return binary_op(v, w, NB_SLOT(nb_remainder), "%");
|
||||
}
|
||||
|
||||
|
|
@ -707,8 +709,10 @@ PyNumber_InPlaceRemainder(PyObject *v, PyObject *w)
|
|||
{
|
||||
if (PyString_Check(v))
|
||||
return PyString_Format(v, w);
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(v))
|
||||
return PyUnicode_Format(v, w);
|
||||
#endif
|
||||
else
|
||||
return binary_iop(v, w, NB_SLOT(nb_inplace_remainder),
|
||||
NB_SLOT(nb_remainder), "%=");
|
||||
|
|
@ -821,10 +825,12 @@ PyNumber_Int(PyObject *o)
|
|||
if (PyString_Check(o))
|
||||
return int_from_string(PyString_AS_STRING(o),
|
||||
PyString_GET_SIZE(o));
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(o))
|
||||
return PyInt_FromUnicode(PyUnicode_AS_UNICODE(o),
|
||||
PyUnicode_GET_SIZE(o),
|
||||
10);
|
||||
#endif
|
||||
m = o->ob_type->tp_as_number;
|
||||
if (m && m->nb_int)
|
||||
return m->nb_int(o);
|
||||
|
|
@ -873,11 +879,13 @@ PyNumber_Long(PyObject *o)
|
|||
*/
|
||||
return long_from_string(PyString_AS_STRING(o),
|
||||
PyString_GET_SIZE(o));
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(o))
|
||||
/* The above check is done in PyLong_FromUnicode(). */
|
||||
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
|
||||
PyUnicode_GET_SIZE(o),
|
||||
10);
|
||||
#endif
|
||||
m = o->ob_type->tp_as_number;
|
||||
if (m && m->nb_long)
|
||||
return m->nb_long(o);
|
||||
|
|
|
|||
|
|
@ -611,14 +611,15 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
|
|||
int sw_error=0;
|
||||
int sign;
|
||||
char buffer[256]; /* For errors */
|
||||
char s_buffer[256];
|
||||
int len;
|
||||
|
||||
if (PyString_Check(v)) {
|
||||
s = PyString_AS_STRING(v);
|
||||
len = PyString_GET_SIZE(v);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(v)) {
|
||||
char s_buffer[256];
|
||||
if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"complex() literal too large to convert");
|
||||
|
|
@ -632,6 +633,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
|
|||
s = s_buffer;
|
||||
len = (int)strlen(s);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(v, &s, &len)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"complex() arg is not a string");
|
||||
|
|
|
|||
|
|
@ -109,7 +109,9 @@ PyFloat_FromString(PyObject *v, char **pend)
|
|||
const char *s, *last, *end;
|
||||
double x;
|
||||
char buffer[256]; /* for errors */
|
||||
#ifdef Py_USING_UNICODE
|
||||
char s_buffer[256]; /* for objects convertible to a char buffer */
|
||||
#endif
|
||||
int len;
|
||||
|
||||
if (pend)
|
||||
|
|
@ -118,6 +120,7 @@ PyFloat_FromString(PyObject *v, char **pend)
|
|||
s = PyString_AS_STRING(v);
|
||||
len = PyString_GET_SIZE(v);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(v)) {
|
||||
if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
@ -132,6 +135,7 @@ PyFloat_FromString(PyObject *v, char **pend)
|
|||
s = s_buffer;
|
||||
len = (int)strlen(s);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(v, &s, &len)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"float() needs a string argument");
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@ PyInt_FromString(char *s, char **pend, int base)
|
|||
return PyInt_FromLong(x);
|
||||
}
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
PyObject *
|
||||
PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
|
||||
{
|
||||
|
|
@ -216,6 +217,7 @@ PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
|
|||
return NULL;
|
||||
return PyInt_FromString(buffer, NULL, base);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Methods */
|
||||
|
||||
|
|
@ -765,10 +767,12 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
return PyNumber_Int(x);
|
||||
if (PyString_Check(x))
|
||||
return PyInt_FromString(PyString_AS_STRING(x), NULL, base);
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(x))
|
||||
return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),
|
||||
PyUnicode_GET_SIZE(x),
|
||||
base);
|
||||
#endif
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"int() can't convert non-string with explicit base");
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -971,6 +971,7 @@ PyLong_FromString(char *str, char **pend, int base)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
PyObject *
|
||||
PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
|
||||
{
|
||||
|
|
@ -986,6 +987,7 @@ PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
|
|||
|
||||
return PyLong_FromString(buffer, NULL, base);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* forward */
|
||||
static PyLongObject *x_divrem
|
||||
|
|
@ -2054,10 +2056,12 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
return PyNumber_Long(x);
|
||||
else if (PyString_Check(x))
|
||||
return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(x))
|
||||
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
|
||||
PyUnicode_GET_SIZE(x),
|
||||
base);
|
||||
#endif
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"long() can't convert non-string with explicit base");
|
||||
|
|
|
|||
|
|
@ -246,6 +246,7 @@ PyObject_Repr(PyObject *v)
|
|||
res = (*v->ob_type->tp_repr)(v);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(res)) {
|
||||
PyObject* str;
|
||||
str = PyUnicode_AsUnicodeEscapeString(res);
|
||||
|
|
@ -255,6 +256,7 @@ PyObject_Repr(PyObject *v)
|
|||
else
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
if (!PyString_Check(res)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__repr__ returned non-string (type %.200s)",
|
||||
|
|
@ -283,6 +285,7 @@ PyObject_Str(PyObject *v)
|
|||
res = (*v->ob_type->tp_str)(v);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(res)) {
|
||||
PyObject* str;
|
||||
str = PyUnicode_AsEncodedString(res, NULL, NULL);
|
||||
|
|
@ -292,6 +295,7 @@ PyObject_Str(PyObject *v)
|
|||
else
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
if (!PyString_Check(res)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__str__ returned non-string (type %.200s)",
|
||||
|
|
@ -302,6 +306,7 @@ PyObject_Str(PyObject *v)
|
|||
return res;
|
||||
}
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
PyObject *
|
||||
PyObject_Unicode(PyObject *v)
|
||||
{
|
||||
|
|
@ -350,6 +355,7 @@ PyObject_Unicode(PyObject *v)
|
|||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Macro to get the tp_richcompare field of a type if defined */
|
||||
|
|
@ -523,6 +529,7 @@ default_3way_compare(PyObject *v, PyObject *w)
|
|||
return (vv < ww) ? -1 : (vv > ww) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* Special case for Unicode */
|
||||
if (PyUnicode_Check(v) || PyUnicode_Check(w)) {
|
||||
c = PyUnicode_Compare(v, w);
|
||||
|
|
@ -537,6 +544,7 @@ default_3way_compare(PyObject *v, PyObject *w)
|
|||
return -2;
|
||||
PyErr_Clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* None is smaller than anything */
|
||||
if (v == Py_None)
|
||||
|
|
@ -1032,6 +1040,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
|
|||
{
|
||||
PyTypeObject *tp = v->ob_type;
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* The Unicode to string conversion is done here because the
|
||||
existing tp_getattro slots expect a string object as name
|
||||
and we wouldn't want to break those. */
|
||||
|
|
@ -1040,6 +1049,8 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
|
|||
if (name == NULL)
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!PyString_Check(name)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
|
|
@ -1073,6 +1084,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
|
|||
PyTypeObject *tp = v->ob_type;
|
||||
int err;
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* The Unicode to string conversion is done here because the
|
||||
existing tp_setattro slots expect a string object as name
|
||||
and we wouldn't want to break those. */
|
||||
|
|
@ -1081,7 +1093,9 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
|
|||
if (name == NULL)
|
||||
return -1;
|
||||
}
|
||||
else if (!PyString_Check(name)){
|
||||
else
|
||||
#endif
|
||||
if (!PyString_Check(name)){
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -173,8 +173,14 @@ PyObject *PyString_AsDecodedObject(PyObject *str,
|
|||
goto onError;
|
||||
}
|
||||
|
||||
if (encoding == NULL)
|
||||
if (encoding == NULL) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
encoding = PyUnicode_GetDefaultEncoding();
|
||||
#else
|
||||
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
||||
goto onError;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Decode via the codec registry */
|
||||
v = PyCodec_Decode(str, encoding, errors);
|
||||
|
|
@ -197,6 +203,7 @@ PyObject *PyString_AsDecodedString(PyObject *str,
|
|||
if (v == NULL)
|
||||
goto onError;
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* Convert Unicode to a string using the default encoding */
|
||||
if (PyUnicode_Check(v)) {
|
||||
PyObject *temp = v;
|
||||
|
|
@ -205,6 +212,7 @@ PyObject *PyString_AsDecodedString(PyObject *str,
|
|||
if (v == NULL)
|
||||
goto onError;
|
||||
}
|
||||
#endif
|
||||
if (!PyString_Check(v)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"decoder did not return a string object (type=%.400s)",
|
||||
|
|
@ -245,8 +253,14 @@ PyObject *PyString_AsEncodedObject(PyObject *str,
|
|||
goto onError;
|
||||
}
|
||||
|
||||
if (encoding == NULL)
|
||||
if (encoding == NULL) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
encoding = PyUnicode_GetDefaultEncoding();
|
||||
#else
|
||||
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
||||
goto onError;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Encode via the codec registry */
|
||||
v = PyCodec_Encode(str, encoding, errors);
|
||||
|
|
@ -269,6 +283,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
|
|||
if (v == NULL)
|
||||
goto onError;
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* Convert Unicode to a string using the default encoding */
|
||||
if (PyUnicode_Check(v)) {
|
||||
PyObject *temp = v;
|
||||
|
|
@ -277,6 +292,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
|
|||
if (v == NULL)
|
||||
goto onError;
|
||||
}
|
||||
#endif
|
||||
if (!PyString_Check(v)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"encoder did not return a string object (type=%.400s)",
|
||||
|
|
@ -344,12 +360,15 @@ PyString_AsStringAndSize(register PyObject *obj,
|
|||
}
|
||||
|
||||
if (!PyString_Check(obj)) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(obj)) {
|
||||
obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
|
||||
if (obj == NULL)
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected string or Unicode object, "
|
||||
"%.200s found", obj->ob_type->tp_name);
|
||||
|
|
@ -477,8 +496,10 @@ string_concat(register PyStringObject *a, register PyObject *bb)
|
|||
register unsigned int size;
|
||||
register PyStringObject *op;
|
||||
if (!PyString_Check(bb)) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(bb))
|
||||
return PyUnicode_Concat((PyObject *)a, bb);
|
||||
#endif
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"cannot add type \"%.200s\" to string",
|
||||
bb->ob_type->tp_name);
|
||||
|
|
@ -586,8 +607,10 @@ string_contains(PyObject *a, PyObject *el)
|
|||
{
|
||||
register char *s, *end;
|
||||
register char c;
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(el))
|
||||
return PyUnicode_Contains(a, el);
|
||||
#endif
|
||||
if (!PyString_Check(el) || PyString_Size(el) != 1) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"'in <string>' requires character as left operand");
|
||||
|
|
@ -868,8 +891,10 @@ string_split(PyStringObject *self, PyObject *args)
|
|||
sub = PyString_AS_STRING(subobj);
|
||||
n = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj))
|
||||
return PyUnicode_Split((PyObject *)self, subobj, maxsplit);
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
|
||||
return NULL;
|
||||
if (n == 0) {
|
||||
|
|
@ -969,6 +994,7 @@ string_join(PyStringObject *self, PyObject *orig)
|
|||
const size_t old_sz = sz;
|
||||
item = PySequence_Fast_GET_ITEM(seq, i);
|
||||
if (!PyString_Check(item)){
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(item)) {
|
||||
/* Defer to Unicode join.
|
||||
* CAUTION: There's no gurantee that the
|
||||
|
|
@ -980,6 +1006,7 @@ string_join(PyStringObject *self, PyObject *orig)
|
|||
Py_DECREF(seq);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"sequence item %i: expected string,"
|
||||
" %.80s found",
|
||||
|
|
@ -1046,8 +1073,10 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
|
|||
sub = PyString_AS_STRING(subobj);
|
||||
n = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj))
|
||||
return PyUnicode_Find((PyObject *)self, subobj, i, last, 1);
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
|
||||
return -2;
|
||||
|
||||
|
|
@ -1381,6 +1410,7 @@ string_count(PyStringObject *self, PyObject *args)
|
|||
sub = PyString_AS_STRING(subobj);
|
||||
n = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj)) {
|
||||
int count;
|
||||
count = PyUnicode_Count((PyObject *)self, subobj, i, last);
|
||||
|
|
@ -1389,6 +1419,7 @@ string_count(PyStringObject *self, PyObject *args)
|
|||
else
|
||||
return PyInt_FromLong((long) count);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1481,6 +1512,7 @@ string_translate(PyStringObject *self, PyObject *args)
|
|||
table1 = PyString_AS_STRING(tableobj);
|
||||
tablen = PyString_GET_SIZE(tableobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(tableobj)) {
|
||||
/* Unicode .translate() does not support the deletechars
|
||||
parameter; instead a mapping to None will cause characters
|
||||
|
|
@ -1492,6 +1524,7 @@ string_translate(PyStringObject *self, PyObject *args)
|
|||
}
|
||||
return PyUnicode_Translate((PyObject *)self, tableobj, NULL);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(tableobj, &table1, &tablen))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1500,11 +1533,13 @@ string_translate(PyStringObject *self, PyObject *args)
|
|||
del_table = PyString_AS_STRING(delobj);
|
||||
dellen = PyString_GET_SIZE(delobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(delobj)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"deletions are implemented differently for unicode");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1729,9 +1764,11 @@ string_replace(PyStringObject *self, PyObject *args)
|
|||
sub = PyString_AS_STRING(subobj);
|
||||
sub_len = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj))
|
||||
return PyUnicode_Replace((PyObject *)self,
|
||||
subobj, replobj, count);
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1739,9 +1776,11 @@ string_replace(PyStringObject *self, PyObject *args)
|
|||
repl = PyString_AS_STRING(replobj);
|
||||
repl_len = PyString_GET_SIZE(replobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(replobj))
|
||||
return PyUnicode_Replace((PyObject *)self,
|
||||
subobj, replobj, count);
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(replobj, &repl, &repl_len))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1792,6 +1831,7 @@ string_startswith(PyStringObject *self, PyObject *args)
|
|||
prefix = PyString_AS_STRING(subobj);
|
||||
plen = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj)) {
|
||||
int rc;
|
||||
rc = PyUnicode_Tailmatch((PyObject *)self,
|
||||
|
|
@ -1801,6 +1841,7 @@ string_startswith(PyStringObject *self, PyObject *args)
|
|||
else
|
||||
return PyInt_FromLong((long) rc);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &prefix, &plen))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1850,6 +1891,7 @@ string_endswith(PyStringObject *self, PyObject *args)
|
|||
suffix = PyString_AS_STRING(subobj);
|
||||
slen = PyString_GET_SIZE(subobj);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_Check(subobj)) {
|
||||
int rc;
|
||||
rc = PyUnicode_Tailmatch((PyObject *)self,
|
||||
|
|
@ -1859,6 +1901,7 @@ string_endswith(PyStringObject *self, PyObject *args)
|
|||
else
|
||||
return PyInt_FromLong((long) rc);
|
||||
}
|
||||
#endif
|
||||
else if (PyObject_AsCharBuffer(subobj, &suffix, &slen))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -2876,7 +2919,10 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
char *fmt, *res;
|
||||
int fmtcnt, rescnt, reslen, arglen, argidx;
|
||||
int args_owned = 0;
|
||||
PyObject *result, *orig_args, *v, *w;
|
||||
PyObject *result, *orig_args;
|
||||
#ifdef Py_USING_UNICODE
|
||||
PyObject *v, *w;
|
||||
#endif
|
||||
PyObject *dict = NULL;
|
||||
if (format == NULL || !PyString_Check(format) || args == NULL) {
|
||||
PyErr_BadInternalCall();
|
||||
|
|
@ -2926,8 +2972,10 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
int sign;
|
||||
int len;
|
||||
char formatbuf[FORMATBUFLEN]; /* For format{float,int,char}() */
|
||||
#ifdef Py_USING_UNICODE
|
||||
char *fmt_start = fmt;
|
||||
int argidx_start = argidx;
|
||||
#endif
|
||||
|
||||
fmt++;
|
||||
if (*fmt == '(') {
|
||||
|
|
@ -3078,11 +3126,13 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
break;
|
||||
case 's':
|
||||
case 'r':
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(v)) {
|
||||
fmt = fmt_start;
|
||||
argidx = argidx_start;
|
||||
goto unicode;
|
||||
}
|
||||
#endif
|
||||
if (c == 's')
|
||||
temp = PyObject_Str(v);
|
||||
else
|
||||
|
|
@ -3240,6 +3290,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
_PyString_Resize(&result, reslen - rescnt);
|
||||
return result;
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
unicode:
|
||||
if (args_owned) {
|
||||
Py_DECREF(args);
|
||||
|
|
@ -3284,6 +3335,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
Py_DECREF(v);
|
||||
Py_DECREF(args);
|
||||
return w;
|
||||
#endif /* Py_USING_UNICODE */
|
||||
|
||||
error:
|
||||
Py_DECREF(result);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue