diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-03-29 14:12:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 14:12:11 (GMT) |
commit | 016bdd519d76c282bbe0220c67a49226b6262638 (patch) | |
tree | 7be9c5202ee5ecc18703f394d2432eb81a38d2d9 /Modules/_elementtree.c | |
parent | 34a49aa3e4d023b5f9e9029f4f1ec68f1a8a8120 (diff) | |
download | cpython-016bdd519d76c282bbe0220c67a49226b6262638.zip cpython-016bdd519d76c282bbe0220c67a49226b6262638.tar.gz cpython-016bdd519d76c282bbe0220c67a49226b6262638.tar.bz2 |
bpo-40024: Update _elementtree to use PyModule_AddType() (GH-19205)
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index d2cad89..49c372d 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -4419,16 +4419,22 @@ PyInit__elementtree(void) "xml.etree.ElementTree.ParseError", PyExc_SyntaxError, NULL ); Py_INCREF(st->parseerror_obj); - PyModule_AddObject(m, "ParseError", st->parseerror_obj); - - Py_INCREF((PyObject *)&Element_Type); - PyModule_AddObject(m, "Element", (PyObject *)&Element_Type); + if (PyModule_AddObject(m, "ParseError", st->parseerror_obj) < 0) { + Py_DECREF(st->parseerror_obj); + return NULL; + } - Py_INCREF((PyObject *)&TreeBuilder_Type); - PyModule_AddObject(m, "TreeBuilder", (PyObject *)&TreeBuilder_Type); + PyTypeObject *types[] = { + &Element_Type, + &TreeBuilder_Type, + &XMLParser_Type + }; - Py_INCREF((PyObject *)&XMLParser_Type); - PyModule_AddObject(m, "XMLParser", (PyObject *)&XMLParser_Type); + for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) { + if (PyModule_AddType(m, types[i]) < 0) { + return NULL; + } + } return m; } |