[Python-checkins] bpo-40024: Update _elementtree to use PyModule_AddType() (GH-19205)
Dong-hee Na
webhook-mailer at python.org
Sun Mar 29 10:12:20 EDT 2020
https://github.com/python/cpython/commit/016bdd519d76c282bbe0220c67a49226b6262638
commit: 016bdd519d76c282bbe0220c67a49226b6262638
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-03-29T16:12:11+02:00
summary:
bpo-40024: Update _elementtree to use PyModule_AddType() (GH-19205)
files:
M Modules/_elementtree.c
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index d2cad89448114..49c372d86b02b 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;
}
More information about the Python-checkins
mailing list