mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Use unicode and remove support for some uses of str8.
This commit is contained in:
parent
5b0fdc9d0a
commit
6ea45d3341
8 changed files with 59 additions and 100 deletions
|
@ -420,8 +420,8 @@ class HexBin:
|
||||||
|
|
||||||
self.FName = fname
|
self.FName = fname
|
||||||
self.FInfo = FInfo()
|
self.FInfo = FInfo()
|
||||||
self.FInfo.Creator = str8(creator)
|
self.FInfo.Creator = creator
|
||||||
self.FInfo.Type = str8(type)
|
self.FInfo.Type = type
|
||||||
self.FInfo.Flags = flags
|
self.FInfo.Flags = flags
|
||||||
|
|
||||||
self.state = _DID_HEADER
|
self.state = _DID_HEADER
|
||||||
|
|
|
@ -261,22 +261,19 @@ getcodec(PyObject *self, PyObject *encoding)
|
||||||
const MultibyteCodec *codec;
|
const MultibyteCodec *codec;
|
||||||
const char *enc;
|
const char *enc;
|
||||||
|
|
||||||
if (PyUnicode_Check(encoding)) {
|
if (!PyUnicode_Check(encoding)) {
|
||||||
encoding = _PyUnicode_AsDefaultEncodedString(encoding, NULL);
|
|
||||||
if (encoding == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(encoding)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"encoding name must be a string.");
|
"encoding name must be a string.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
enc = PyUnicode_AsString(encoding, NULL);
|
||||||
|
if (enc == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
cofunc = getmultibytecodec();
|
cofunc = getmultibytecodec();
|
||||||
if (cofunc == NULL)
|
if (cofunc == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
enc = PyString_AS_STRING(encoding);
|
|
||||||
for (codec = codec_list; codec->encoding[0]; codec++)
|
for (codec = codec_list; codec->encoding[0]; codec++)
|
||||||
if (strcmp(codec->encoding, enc) == 0)
|
if (strcmp(codec->encoding, enc) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -85,16 +85,20 @@ internal_error_callback(const char *errors)
|
||||||
else if (strcmp(errors, "replace") == 0)
|
else if (strcmp(errors, "replace") == 0)
|
||||||
return ERROR_REPLACE;
|
return ERROR_REPLACE;
|
||||||
else
|
else
|
||||||
return PyString_FromString(errors);
|
return PyUnicode_FromString(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
call_error_callback(PyObject *errors, PyObject *exc)
|
call_error_callback(PyObject *errors, PyObject *exc)
|
||||||
{
|
{
|
||||||
PyObject *args, *cb, *r;
|
PyObject *args, *cb, *r;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
assert(PyString_Check(errors));
|
assert(PyUnicode_Check(errors));
|
||||||
cb = PyCodec_LookupError(PyString_AS_STRING(errors));
|
str = PyUnicode_AsString(errors);
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
|
cb = PyCodec_LookupError(str);
|
||||||
if (cb == NULL)
|
if (cb == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -129,7 +133,7 @@ codecctx_errors_get(MultibyteStatefulCodecContext *self)
|
||||||
return self->errors;
|
return self->errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyString_FromString(errors);
|
return PyUnicode_FromString(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -137,18 +141,18 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
|
||||||
void *closure)
|
void *closure)
|
||||||
{
|
{
|
||||||
PyObject *cb;
|
PyObject *cb;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
if (PyUnicode_Check(value)) {
|
if (!PyUnicode_Check(value)) {
|
||||||
value = _PyUnicode_AsDefaultEncodedString(value, NULL);
|
|
||||||
if (value == NULL)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(value)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "errors must be a string");
|
PyErr_SetString(PyExc_TypeError, "errors must be a string");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = internal_error_callback(PyString_AS_STRING(value));
|
str = PyUnicode_AsString(value);
|
||||||
|
if (str == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
cb = internal_error_callback(str);
|
||||||
if (cb == NULL)
|
if (cb == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
@ -1281,13 +1281,6 @@ PyNumber_Long(PyObject *o)
|
||||||
}
|
}
|
||||||
if (PyLong_Check(o)) /* A long subclass without nb_long */
|
if (PyLong_Check(o)) /* A long subclass without nb_long */
|
||||||
return _PyLong_Copy((PyLongObject *)o);
|
return _PyLong_Copy((PyLongObject *)o);
|
||||||
if (PyString_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));
|
|
||||||
if (PyUnicode_Check(o))
|
if (PyUnicode_Check(o))
|
||||||
/* The above check is done in PyLong_FromUnicode(). */
|
/* The above check is done in PyLong_FromUnicode(). */
|
||||||
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
|
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
|
||||||
|
|
|
@ -74,11 +74,7 @@ PyFloat_FromString(PyObject *v)
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
|
|
||||||
if (PyString_Check(v)) {
|
if (PyUnicode_Check(v)) {
|
||||||
s = PyString_AS_STRING(v);
|
|
||||||
len = PyString_GET_SIZE(v);
|
|
||||||
}
|
|
||||||
else if (PyUnicode_Check(v)) {
|
|
||||||
s_buffer = (char *)PyMem_MALLOC(PyUnicode_GET_SIZE(v)+1);
|
s_buffer = (char *)PyMem_MALLOC(PyUnicode_GET_SIZE(v)+1);
|
||||||
if (s_buffer == NULL)
|
if (s_buffer == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
@ -843,7 +839,7 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return float_subtype_new(type, args, kwds); /* Wimp out */
|
return float_subtype_new(type, args, kwds); /* Wimp out */
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyString_Check(x))
|
if (PyUnicode_Check(x))
|
||||||
return PyFloat_FromString(x);
|
return PyFloat_FromString(x);
|
||||||
return PyNumber_Float(x);
|
return PyNumber_Float(x);
|
||||||
}
|
}
|
||||||
|
@ -894,18 +890,15 @@ float_getformat(PyTypeObject *v, PyObject* arg)
|
||||||
char* s;
|
char* s;
|
||||||
float_format_type r;
|
float_format_type r;
|
||||||
|
|
||||||
if (PyUnicode_Check(arg)) {
|
if (!PyUnicode_Check(arg)) {
|
||||||
arg = _PyUnicode_AsDefaultEncodedString(arg, NULL);
|
|
||||||
if (arg == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(arg)) {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__getformat__() argument must be string, not %.500s",
|
"__getformat__() argument must be string, not %.500s",
|
||||||
Py_Type(arg)->tp_name);
|
Py_Type(arg)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = PyString_AS_STRING(arg);
|
s = PyUnicode_AsString(arg);
|
||||||
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
if (strcmp(s, "double") == 0) {
|
if (strcmp(s, "double") == 0) {
|
||||||
r = double_format;
|
r = double_format;
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,7 +357,7 @@ _PyObject_Dump(PyObject* op)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyObject_Repr(PyObject *v)
|
PyObject_Repr(PyObject *v)
|
||||||
{
|
{
|
||||||
PyObject *ress, *resu;
|
PyObject *res;
|
||||||
if (PyErr_CheckSignals())
|
if (PyErr_CheckSignals())
|
||||||
return NULL;
|
return NULL;
|
||||||
#ifdef USE_STACKCHECK
|
#ifdef USE_STACKCHECK
|
||||||
|
@ -371,21 +371,15 @@ PyObject_Repr(PyObject *v)
|
||||||
else if (Py_Type(v)->tp_repr == NULL)
|
else if (Py_Type(v)->tp_repr == NULL)
|
||||||
return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v);
|
return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v);
|
||||||
else {
|
else {
|
||||||
ress = (*v->ob_type->tp_repr)(v);
|
res = (*v->ob_type->tp_repr)(v);
|
||||||
if (!ress)
|
if (res != NULL && !PyUnicode_Check(res)) {
|
||||||
return NULL;
|
|
||||||
if (PyUnicode_Check(ress))
|
|
||||||
return ress;
|
|
||||||
if (!PyString_Check(ress)) {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__repr__ returned non-string (type %.200s)",
|
"__repr__ returned non-string (type %.200s)",
|
||||||
ress->ob_type->tp_name);
|
res->ob_type->tp_name);
|
||||||
Py_DECREF(ress);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
resu = PyUnicode_FromObject(ress);
|
return res;
|
||||||
Py_DECREF(ress);
|
|
||||||
return resu;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +407,7 @@ _PyObject_Str(PyObject *v)
|
||||||
{
|
{
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return PyString_FromString("<NULL>");
|
return PyUnicode_FromString("<NULL>");
|
||||||
if (PyString_CheckExact(v)) {
|
if (PyString_CheckExact(v)) {
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -55,17 +55,15 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
|
||||||
"can't delete %s.__name__", type->tp_name);
|
"can't delete %s.__name__", type->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (PyUnicode_Check(value)) {
|
if (!PyUnicode_Check(value)) {
|
||||||
value = _PyUnicode_AsDefaultEncodedString(value, NULL);
|
|
||||||
if (value == NULL)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(value)) {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can only assign string to %s.__name__, not '%s'",
|
"can only assign string to %s.__name__, not '%s'",
|
||||||
type->tp_name, Py_Type(value)->tp_name);
|
type->tp_name, Py_Type(value)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
value = _PyUnicode_AsDefaultEncodedString(value, NULL);
|
||||||
|
if (value == NULL)
|
||||||
|
return -1;
|
||||||
if (strlen(PyString_AS_STRING(value))
|
if (strlen(PyString_AS_STRING(value))
|
||||||
!= (size_t)PyString_GET_SIZE(value)) {
|
!= (size_t)PyString_GET_SIZE(value)) {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
|
@ -1918,22 +1916,15 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
|
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
|
||||||
if (doc != NULL) {
|
if (doc != NULL && PyUnicode_Check(doc)) {
|
||||||
char *tp_doc;
|
|
||||||
const char *str = NULL;
|
|
||||||
size_t n;
|
size_t n;
|
||||||
if (PyString_Check(doc)) {
|
char *tp_doc;
|
||||||
str = PyString_AS_STRING(doc);
|
const char *str = PyUnicode_AsString(doc);
|
||||||
n = (size_t)PyString_GET_SIZE(doc);
|
|
||||||
} else if (PyUnicode_Check(doc)) {
|
|
||||||
str = PyUnicode_AsString(doc);
|
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
n = strlen(str);
|
n = strlen(str);
|
||||||
}
|
|
||||||
if (str != NULL) {
|
|
||||||
tp_doc = (char *)PyObject_MALLOC(n+1);
|
tp_doc = (char *)PyObject_MALLOC(n+1);
|
||||||
if (tp_doc == NULL) {
|
if (tp_doc == NULL) {
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
|
@ -1943,7 +1934,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
||||||
type->tp_doc = tp_doc;
|
type->tp_doc = tp_doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Special-case __new__: if it's a plain function,
|
/* Special-case __new__: if it's a plain function,
|
||||||
make it a static function */
|
make it a static function */
|
||||||
|
|
|
@ -40,7 +40,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
|
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
|
||||||
name = PyTuple_GET_ITEM(args, 1);
|
name = PyTuple_GET_ITEM(args, 1);
|
||||||
if ((!PyString_Check(name) && !PyUnicode_Check(name))) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"__build_class__: name is not a string");
|
"__build_class__: name is not a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -631,8 +631,7 @@ builtin_exec(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
else if (locals == Py_None)
|
else if (locals == Py_None)
|
||||||
locals = globals;
|
locals = globals;
|
||||||
if (!PyString_Check(prog) &&
|
if (!PyUnicode_Check(prog) &&
|
||||||
!PyUnicode_Check(prog) &&
|
|
||||||
!PyCode_Check(prog)) {
|
!PyCode_Check(prog)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"exec() arg 1 must be a string, file, or code "
|
"exec() arg 1 must be a string, file, or code "
|
||||||
|
@ -695,23 +694,15 @@ globals and locals. If only globals is given, locals defaults to it.");
|
||||||
static PyObject *
|
static PyObject *
|
||||||
builtin_getattr(PyObject *self, PyObject *args)
|
builtin_getattr(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *v, *result, *dflt = NULL, *release = NULL;
|
PyObject *v, *result, *dflt = NULL;
|
||||||
PyObject *name;
|
PyObject *name;
|
||||||
|
|
||||||
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
|
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyString_Check(name)) {
|
|
||||||
release = PyString_AsDecodedObject(name, NULL, NULL);
|
|
||||||
if (!release)
|
|
||||||
return NULL;
|
|
||||||
name = release;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyUnicode_Check(name)) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"getattr(): attribute name must be string");
|
"getattr(): attribute name must be string");
|
||||||
Py_XDECREF(release);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result = PyObject_GetAttr(v, name);
|
result = PyObject_GetAttr(v, name);
|
||||||
|
@ -722,7 +713,6 @@ builtin_getattr(PyObject *self, PyObject *args)
|
||||||
Py_INCREF(dflt);
|
Py_INCREF(dflt);
|
||||||
result = dflt;
|
result = dflt;
|
||||||
}
|
}
|
||||||
Py_XDECREF(release);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1221,17 +1211,15 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
if (file == NULL || file == Py_None)
|
if (file == NULL || file == Py_None)
|
||||||
file = PySys_GetObject("stdout");
|
file = PySys_GetObject("stdout");
|
||||||
|
|
||||||
if (sep && sep != Py_None && !PyString_Check(sep) &&
|
if (sep && sep != Py_None && !PyUnicode_Check(sep)) {
|
||||||
!PyUnicode_Check(sep)) {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"sep must be None, str or unicode, not %.200s",
|
"sep must be None or a string, not %.200s",
|
||||||
sep->ob_type->tp_name);
|
sep->ob_type->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (end && end != Py_None && !PyString_Check(end) &&
|
if (end && end != Py_None && !PyUnicode_Check(end)) {
|
||||||
!PyUnicode_Check(end)) {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"end must be None, str or unicode, not %.200s",
|
"end must be None or a string, not %.200s",
|
||||||
end->ob_type->tp_name);
|
end->ob_type->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1383,7 +1371,7 @@ builtin_input(PyObject *self, PyObject *args)
|
||||||
result = NULL;
|
result = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = PyString_FromStringAndSize(s, len-1);
|
result = PyUnicode_FromStringAndSize(s, len-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PyMem_FREE(s);
|
PyMem_FREE(s);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue