diff -r b02d256b8827 Objects/typeobject.c --- a/Objects/typeobject.c Sun Dec 27 15:51:32 2015 +0200 +++ b/Objects/typeobject.c Sun Dec 27 19:51:38 2015 +0200 @@ -420,7 +420,7 @@ type_set_name(PyTypeObject *type, PyObje if (PyUnicode_Contains(value, tmp) != 0) { Py_DECREF(tmp); PyErr_Format(PyExc_ValueError, - "__name__ must not contain null bytes"); + "__name__ must not contain null characters"); return -1; } Py_DECREF(tmp); @@ -2284,8 +2284,8 @@ type_new(PyTypeObject *metatype, PyObjec PyTypeObject *type = NULL, *base, *tmptype, *winner; PyHeapTypeObject *et; PyMemberDef *mp; - Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak; - int j, may_add_dict, may_add_weak; + Py_ssize_t i, nbases, nslots, slotoffset, tp_name_size; + int j, may_add_dict, may_add_weak, add_dict, add_weak; _Py_IDENTIFIER(__qualname__); _Py_IDENTIFIER(__slots__); @@ -2508,9 +2508,14 @@ type_new(PyTypeObject *metatype, PyObjec type->tp_as_sequence = &et->as_sequence; type->tp_as_mapping = &et->as_mapping; type->tp_as_buffer = &et->as_buffer; - type->tp_name = _PyUnicode_AsString(name); + type->tp_name = PyUnicode_AsUTF8AndSize(name, &tp_name_size); if (!type->tp_name) goto error; + if (strlen(type->tp_name) != (size_t)tp_name_size) { + PyErr_Format(PyExc_ValueError, + "name must not contain null characters"); + goto error; + } /* Set tp_base and tp_bases */ type->tp_bases = bases;