diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-07-25 11:34:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 11:34:49 (GMT) |
commit | 329e4a1a3f8c53d9d120d2eed93b95a04b826f2f (patch) | |
tree | 8bbe3eb47cf37493fcd3289d98643605e0217c78 /Doc/extending | |
parent | f443b54a2f14e386a91fe4b09f41a265445008b8 (diff) | |
download | cpython-329e4a1a3f8c53d9d120d2eed93b95a04b826f2f.zip cpython-329e4a1a3f8c53d9d120d2eed93b95a04b826f2f.tar.gz cpython-329e4a1a3f8c53d9d120d2eed93b95a04b826f2f.tar.bz2 |
gh-86493: Modernize modules initialization code (GH-106858)
Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecated
PyModule_AddObject().
Diffstat (limited to 'Doc/extending')
-rw-r--r-- | Doc/extending/extending.rst | 7 | ||||
-rw-r--r-- | Doc/extending/newtypes_tutorial.rst | 8 |
2 files changed, 4 insertions, 11 deletions
diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 0c5da49..00a9edc 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -221,9 +221,7 @@ with an exception object:: return NULL; SpamError = PyErr_NewException("spam.error", NULL, NULL); - Py_XINCREF(SpamError); - if (PyModule_AddObject(m, "error", SpamError) < 0) { - Py_XDECREF(SpamError); + if (PyModule_AddObjectRef(m, "error", SpamError) < 0) { Py_CLEAR(SpamError); Py_DECREF(m); return NULL; @@ -1281,8 +1279,7 @@ function must take care of initializing the C API pointer array:: /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void *)PySpam_API, "spam._C_API", NULL); - if (PyModule_AddObject(m, "_C_API", c_api_object) < 0) { - Py_XDECREF(c_api_object); + if (PyModule_Add(m, "_C_API", c_api_object) < 0) { Py_DECREF(m); return NULL; } diff --git a/Doc/extending/newtypes_tutorial.rst b/Doc/extending/newtypes_tutorial.rst index ba09fb1..4f9c889 100644 --- a/Doc/extending/newtypes_tutorial.rst +++ b/Doc/extending/newtypes_tutorial.rst @@ -180,9 +180,7 @@ This initializes the :class:`Custom` type, filling in a number of members to the appropriate default values, including :attr:`ob_type` that we initially set to ``NULL``. :: - Py_INCREF(&CustomType); - if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) { - Py_DECREF(&CustomType); + if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) { Py_DECREF(m); return NULL; } @@ -862,9 +860,7 @@ function:: if (m == NULL) return NULL; - Py_INCREF(&SubListType); - if (PyModule_AddObject(m, "SubList", (PyObject *) &SubListType) < 0) { - Py_DECREF(&SubListType); + if (PyModule_AddObjectRef(m, "SubList", (PyObject *) &SubListType) < 0) { Py_DECREF(m); return NULL; } |