diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-03-22 16:17:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 16:17:34 (GMT) |
commit | 05e4a296ecc127641160a04f39cc02c0f66a8c27 (patch) | |
tree | 59e73090785087a5e15175c815a20986e59a5728 /Python/modsupport.c | |
parent | b33e52511a59c6da7132c226b7f7489b092a33eb (diff) | |
download | cpython-05e4a296ecc127641160a04f39cc02c0f66a8c27.zip cpython-05e4a296ecc127641160a04f39cc02c0f66a8c27.tar.gz cpython-05e4a296ecc127641160a04f39cc02c0f66a8c27.tar.bz2 |
bpo-40024: Add PyModule_AddType() helper function (GH-19088)
Diffstat (limited to 'Python/modsupport.c')
-rw-r--r-- | Python/modsupport.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c index 7271af3..a8e78c3 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -678,3 +678,22 @@ PyModule_AddStringConstant(PyObject *m, const char *name, const char *value) Py_DECREF(o); return -1; } + +int +PyModule_AddType(PyObject *module, PyTypeObject *type) +{ + if (PyType_Ready(type) < 0) { + return -1; + } + + const char *name = _PyType_Name(type); + assert(name != NULL); + + Py_INCREF(type); + if (PyModule_AddObject(module, name, (PyObject *)type) < 0) { + Py_DECREF(type); + return -1; + } + + return 0; +} |