bpo-38677: Fix arraymodule error handling in module initialization. (GH-17039)

This commit is contained in:
Marco Paolini 2019-11-15 08:42:51 +00:00 committed by Serhiy Storchaka
parent 57d3ab85a4
commit b44ffc8b40
1 changed files with 12 additions and 8 deletions

View File

@ -3040,9 +3040,15 @@ array_modexec(PyObject *m)
Py_TYPE(&PyArrayIter_Type) = &PyType_Type; Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
Py_INCREF((PyObject *)&Arraytype); Py_INCREF((PyObject *)&Arraytype);
PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype); if (PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype) < 0) {
Py_DECREF((PyObject *)&Arraytype);
return -1;
}
Py_INCREF((PyObject *)&Arraytype); Py_INCREF((PyObject *)&Arraytype);
PyModule_AddObject(m, "array", (PyObject *)&Arraytype); if (PyModule_AddObject(m, "array", (PyObject *)&Arraytype) < 0) {
Py_DECREF((PyObject *)&Arraytype);
return -1;
}
for (descr=descriptors; descr->typecode != '\0'; descr++) { for (descr=descriptors; descr->typecode != '\0'; descr++) {
size++; size++;
@ -3053,13 +3059,11 @@ array_modexec(PyObject *m)
*p++ = (char)descr->typecode; *p++ = (char)descr->typecode;
} }
typecodes = PyUnicode_DecodeASCII(buffer, p - buffer, NULL); typecodes = PyUnicode_DecodeASCII(buffer, p - buffer, NULL);
if (PyModule_AddObject(m, "typecodes", typecodes) < 0) {
PyModule_AddObject(m, "typecodes", typecodes); Py_XDECREF(typecodes);
return -1;
if (PyErr_Occurred()) {
Py_DECREF(m);
m = NULL;
} }
return 0; return 0;
} }