Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ace8ba8

Browse files
author
Thomas Heller
committed
Revert a wrong commit.
1 parent f630dac commit ace8ba8

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

Objects/typeobject.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ static int
4444
type_set_name(PyTypeObject *type, PyObject *value, void *context)
4545
{
4646
PyHeapTypeObject* et;
47-
char *name;
4847

4948
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
5049
PyErr_Format(PyExc_TypeError,
@@ -56,25 +55,19 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
5655
"can't delete %s.__name__", type->tp_name);
5756
return -1;
5857
}
59-
if (PyString_Check(value)) {
60-
value = PyUnicode_FromStringAndSize(PyString_AS_STRING(value),
61-
PyString_GET_SIZE(value));
58+
if (PyUnicode_Check(value)) {
59+
value = _PyUnicode_AsDefaultEncodedString(value, NULL);
6260
if (value == NULL)
6361
return -1;
64-
/* XXX Isn't here a refcount leak? */
6562
}
66-
if (!PyUnicode_Check(value)) {
63+
if (!PyString_Check(value)) {
6764
PyErr_Format(PyExc_TypeError,
6865
"can only assign string to %s.__name__, not '%s'",
6966
type->tp_name, value->ob_type->tp_name);
7067
return -1;
7168
}
72-
73-
name = PyUnicode_AsString(value);
74-
if (name == NULL)
75-
return -1;
76-
77-
if (strlen(name) != PyUnicode_GET_SIZE(value)) {
69+
if (strlen(PyString_AS_STRING(value))
70+
!= (size_t)PyString_GET_SIZE(value)) {
7871
PyErr_Format(PyExc_ValueError,
7972
"__name__ must not contain null bytes");
8073
return -1;
@@ -87,7 +80,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
8780
Py_DECREF(et->ht_name);
8881
et->ht_name = value;
8982

90-
type->tp_name = name;
83+
type->tp_name = PyString_AS_STRING(value);
9184

9285
return 0;
9386
}
@@ -1665,7 +1658,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
16651658
}
16661659

16671660
/* Check arguments: (name, bases, dict) */
1668-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist,
1661+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:type", kwlist,
16691662
&name,
16701663
&PyTuple_Type, &bases,
16711664
&PyDict_Type, &dict))

Python/errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
575575
goto failure;
576576
}
577577
/* Create a real new-style class. */
578-
result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
578+
result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
579579
dot+1, bases, dict);
580580
failure:
581581
Py_XDECREF(bases);

0 commit comments

Comments
 (0)