diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-17 18:11:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-17 18:11:04 (GMT) |
commit | 4ab46d794961491ed185c195d53da7ee6a16e646 (patch) | |
tree | d8c39fb69ba33674cf8a240f6d068d0cf710d7a3 /Modules | |
parent | 132a7d7cdbc7cb89fa1c1f4e8192241c3d68f549 (diff) | |
download | cpython-4ab46d794961491ed185c195d53da7ee6a16e646.zip cpython-4ab46d794961491ed185c195d53da7ee6a16e646.tar.gz cpython-4ab46d794961491ed185c195d53da7ee6a16e646.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_functoolsmodule.c | 7 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index e109b33..a571045 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -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; } diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index d7a1ef0..0e5cbbd 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4630,7 +4630,7 @@ PyInit_itertools(void) { int i; PyObject *m; - char *name; + const char *name; PyTypeObject *typelist[] = { &accumulate_type, &combinations_type, @@ -4663,10 +4663,9 @@ PyInit_itertools(void) for (i=0 ; typelist[i] != NULL ; i++) { if (PyType_Ready(typelist[i]) < 0) 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; |