gh-86493: Modernize modules initialization code (GH-106858)

Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecated
PyModule_AddObject().
This commit is contained in:
Serhiy Storchaka 2023-07-25 14:34:49 +03:00 committed by GitHub
parent f443b54a2f
commit 329e4a1a3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 84 additions and 292 deletions

View file

@ -3163,9 +3163,8 @@ array_modexec(PyObject *m)
CREATE_TYPE(m, state->ArrayIterType, &arrayiter_spec);
Py_SET_TYPE(state->ArrayIterType, &PyType_Type);
if (PyModule_AddObject(m, "ArrayType",
Py_NewRef((PyObject *)state->ArrayType)) < 0) {
Py_DECREF((PyObject *)state->ArrayType);
if (PyModule_AddObjectRef(m, "ArrayType",
(PyObject *)state->ArrayType) < 0) {
return -1;
}
@ -3193,8 +3192,7 @@ array_modexec(PyObject *m)
*p++ = (char)descr->typecode;
}
typecodes = PyUnicode_DecodeASCII(buffer, p - buffer, NULL);
if (PyModule_AddObject(m, "typecodes", typecodes) < 0) {
Py_XDECREF(typecodes);
if (PyModule_Add(m, "typecodes", typecodes) < 0) {
return -1;
}