mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Use unicode and remove support for some uses of str8.
This commit is contained in:
parent
6ea45d3341
commit
ed2b7397a0
5 changed files with 15 additions and 31 deletions
|
@ -649,11 +649,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
|
||||||
char s_buffer[256];
|
char s_buffer[256];
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
|
|
||||||
if (PyString_Check(v)) {
|
if (PyUnicode_Check(v)) {
|
||||||
s = PyString_AS_STRING(v);
|
|
||||||
len = PyString_GET_SIZE(v);
|
|
||||||
}
|
|
||||||
else if (PyUnicode_Check(v)) {
|
|
||||||
if (PyUnicode_GET_SIZE(v) >= (Py_ssize_t)sizeof(s_buffer)) {
|
if (PyUnicode_GET_SIZE(v) >= (Py_ssize_t)sizeof(s_buffer)) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"complex() literal too large to convert");
|
"complex() literal too large to convert");
|
||||||
|
@ -833,7 +829,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
Py_INCREF(r);
|
Py_INCREF(r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (PyString_Check(r) || PyUnicode_Check(r)) {
|
if (PyUnicode_Check(r)) {
|
||||||
if (i != NULL) {
|
if (i != NULL) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"complex() can't take second arg"
|
"complex() can't take second arg"
|
||||||
|
@ -842,7 +838,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
return complex_subtype_from_string(type, r);
|
return complex_subtype_from_string(type, r);
|
||||||
}
|
}
|
||||||
if (i != NULL && (PyString_Check(i) || PyUnicode_Check(i))) {
|
if (i != NULL && PyUnicode_Check(i)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"complex() second arg can't be a string");
|
"complex() second arg can't be a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -833,10 +833,7 @@ SyntaxError_str(PySyntaxErrorObject *self)
|
||||||
/* XXX -- do all the additional formatting with filename and
|
/* XXX -- do all the additional formatting with filename and
|
||||||
lineno here */
|
lineno here */
|
||||||
|
|
||||||
if (self->filename) {
|
if (self->filename && PyUnicode_Check(self->filename)) {
|
||||||
if (PyString_Check(self->filename))
|
|
||||||
filename = PyString_AsString(self->filename);
|
|
||||||
else if (PyUnicode_Check(self->filename))
|
|
||||||
filename = PyUnicode_AsString(self->filename);
|
filename = PyUnicode_AsString(self->filename);
|
||||||
}
|
}
|
||||||
have_lineno = (self->lineno != NULL) && PyInt_CheckExact(self->lineno);
|
have_lineno = (self->lineno != NULL) && PyInt_CheckExact(self->lineno);
|
||||||
|
|
|
@ -1942,6 +1942,7 @@ static int
|
||||||
is_default_cmp(PyObject *cmpfunc)
|
is_default_cmp(PyObject *cmpfunc)
|
||||||
{
|
{
|
||||||
PyCFunctionObject *f;
|
PyCFunctionObject *f;
|
||||||
|
const char *module;
|
||||||
if (cmpfunc == NULL || cmpfunc == Py_None)
|
if (cmpfunc == NULL || cmpfunc == Py_None)
|
||||||
return 1;
|
return 1;
|
||||||
if (!PyCFunction_Check(cmpfunc))
|
if (!PyCFunction_Check(cmpfunc))
|
||||||
|
@ -1949,9 +1950,12 @@ is_default_cmp(PyObject *cmpfunc)
|
||||||
f = (PyCFunctionObject *)cmpfunc;
|
f = (PyCFunctionObject *)cmpfunc;
|
||||||
if (f->m_self != NULL)
|
if (f->m_self != NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (!PyString_Check(f->m_module))
|
if (!PyUnicode_Check(f->m_module))
|
||||||
return 0;
|
return 0;
|
||||||
if (strcmp(PyString_AS_STRING(f->m_module), "__builtin__") != 0)
|
module = PyUnicode_AsString(f->m_module);
|
||||||
|
if (module == NULL)
|
||||||
|
return 0;
|
||||||
|
if (strcmp(module, "__builtin__") != 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (strcmp(f->m_ml->ml_name, "cmp") != 0)
|
if (strcmp(f->m_ml->ml_name, "cmp") != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -3517,19 +3517,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return PyLong_FromLong(0L);
|
return PyLong_FromLong(0L);
|
||||||
if (base == -909)
|
if (base == -909)
|
||||||
return PyNumber_Long(x);
|
return PyNumber_Long(x);
|
||||||
else if (PyString_Check(x) || PyBytes_Check(x)) {
|
else if (PyBytes_Check(x)) {
|
||||||
/* Since PyLong_FromString doesn't have a length parameter,
|
/* Since PyLong_FromString doesn't have a length parameter,
|
||||||
* check here for possible NULs in the string. */
|
* check here for possible NULs in the string. */
|
||||||
char *string;
|
char *string = PyBytes_AS_STRING(x);
|
||||||
int size;
|
int size = PyBytes_GET_SIZE(x);
|
||||||
if (PyBytes_Check(x)) {
|
|
||||||
string = PyBytes_AS_STRING(x);
|
|
||||||
size = PyBytes_GET_SIZE(x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
string = PyString_AS_STRING(x);
|
|
||||||
size = PyString_GET_SIZE(x);
|
|
||||||
}
|
|
||||||
if (strlen(string) != size) {
|
if (strlen(string) != size) {
|
||||||
/* We only see this if there's a null byte in x,
|
/* We only see this if there's a null byte in x,
|
||||||
x is a str8 or a bytes, *and* a base is given. */
|
x is a str8 or a bytes, *and* a base is given. */
|
||||||
|
|
|
@ -66,17 +66,12 @@ PyModule_GetName(PyObject *m)
|
||||||
d = ((PyModuleObject *)m)->md_dict;
|
d = ((PyModuleObject *)m)->md_dict;
|
||||||
if (d == NULL ||
|
if (d == NULL ||
|
||||||
(nameobj = PyDict_GetItemString(d, "__name__")) == NULL ||
|
(nameobj = PyDict_GetItemString(d, "__name__")) == NULL ||
|
||||||
!(PyString_Check(nameobj) || PyUnicode_Check(nameobj)))
|
!PyUnicode_Check(nameobj))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_SystemError, "nameless module");
|
PyErr_SetString(PyExc_SystemError, "nameless module");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (PyUnicode_Check(nameobj)) {
|
return PyUnicode_AsString(nameobj);
|
||||||
nameobj = _PyUnicode_AsDefaultEncodedString(nameobj, NULL);
|
|
||||||
if (nameobj == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return PyString_AsString(nameobj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue