mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Fixes for issue 1752184, ensuring type objects are always created
with a PyUnicode name.
This commit is contained in:
parent
15c974651f
commit
e845c0f922
4 changed files with 15 additions and 6 deletions
|
@ -45,6 +45,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
|
||||||
{
|
{
|
||||||
PyHeapTypeObject* et;
|
PyHeapTypeObject* et;
|
||||||
char *tp_name;
|
char *tp_name;
|
||||||
|
PyObject *tmp;
|
||||||
|
|
||||||
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
|
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
@ -62,14 +63,22 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
|
||||||
type->tp_name, Py_Type(value)->tp_name);
|
type->tp_name, Py_Type(value)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tp_name = PyUnicode_AsString(value);
|
|
||||||
if (tp_name == NULL)
|
/* Check absence of null characters */
|
||||||
|
tmp = PyUnicode_FromStringAndSize("\0", 1);
|
||||||
|
if (tmp == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (strlen(tp_name) != (size_t)PyUnicode_GET_SIZE(value)) {
|
if (PyUnicode_Contains(value, tmp) != 0) {
|
||||||
|
Py_DECREF(tmp);
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"__name__ must not contain null bytes");
|
"__name__ must not contain null bytes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(tmp);
|
||||||
|
|
||||||
|
tp_name = PyUnicode_AsString(value);
|
||||||
|
if (tp_name == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
et = (PyHeapTypeObject*)type;
|
et = (PyHeapTypeObject*)type;
|
||||||
|
|
||||||
|
|
|
@ -415,7 +415,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(fnames, i, field);
|
PyTuple_SET_ITEM(fnames, i, field);
|
||||||
}
|
}
|
||||||
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
|
result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
|
||||||
type, base, "_fields", fnames, "__module__", "_ast");
|
type, base, "_fields", fnames, "__module__", "_ast");
|
||||||
Py_DECREF(fnames);
|
Py_DECREF(fnames);
|
||||||
return (PyTypeObject*)result;
|
return (PyTypeObject*)result;
|
||||||
|
|
|
@ -410,7 +410,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(fnames, i, field);
|
PyTuple_SET_ITEM(fnames, i, field);
|
||||||
}
|
}
|
||||||
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
|
result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
|
||||||
type, base, "_fields", fnames, "__module__", "_ast");
|
type, base, "_fields", fnames, "__module__", "_ast");
|
||||||
Py_DECREF(fnames);
|
Py_DECREF(fnames);
|
||||||
return (PyTypeObject*)result;
|
return (PyTypeObject*)result;
|
||||||
|
|
|
@ -608,7 +608,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
/* Create a real new-style class. */
|
/* Create a real new-style class. */
|
||||||
result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
|
result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
|
||||||
dot+1, bases, dict);
|
dot+1, bases, dict);
|
||||||
failure:
|
failure:
|
||||||
Py_XDECREF(bases);
|
Py_XDECREF(bases);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue