bpo-31497: Add private helper _PyType_Name(). (#3630)

This function returns the last component of tp_name after a dot.
Returns tp_name itself if it doesn't contain a dot.
This commit is contained in:
Serhiy Storchaka 2017-09-17 21:11:04 +03:00 committed by GitHub
parent 132a7d7cdb
commit 4ab46d7949
6 changed files with 26 additions and 33 deletions

View file

@ -1284,7 +1284,7 @@ PyInit__functools(void)
{
int i;
PyObject *m;
char *name;
const char *name;
PyTypeObject *typelist[] = {
&partial_type,
&lru_cache_type,
@ -1306,10 +1306,9 @@ PyInit__functools(void)
Py_DECREF(m);
return NULL;
}
name = strchr(typelist[i]->tp_name, '.');
assert (name != NULL);
name = _PyType_Name(typelist[i]);
Py_INCREF(typelist[i]);
PyModule_AddObject(m, name+1, (PyObject *)typelist[i]);
PyModule_AddObject(m, name, (PyObject *)typelist[i]);
}
return m;
}