summaryrefslogtreecommitdiffstats
path: root/Modules/_tkinter.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-25 11:34:49 (GMT)
committerGitHub <noreply@github.com>2023-07-25 11:34:49 (GMT)
commit329e4a1a3f8c53d9d120d2eed93b95a04b826f2f (patch)
tree8bbe3eb47cf37493fcd3289d98643605e0217c78 /Modules/_tkinter.c
parentf443b54a2f14e386a91fe4b09f41a265445008b8 (diff)
downloadcpython-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 'Modules/_tkinter.c')
-rw-r--r--Modules/_tkinter.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 76af803..1605606 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -3197,7 +3197,7 @@ static struct PyModuleDef _tkintermodule = {
PyMODINIT_FUNC
PyInit__tkinter(void)
{
- PyObject *m, *uexe, *cexe, *o;
+ PyObject *m, *uexe, *cexe;
tcl_lock = PyThread_allocate_lock();
if (tcl_lock == NULL)
@@ -3207,17 +3207,11 @@ PyInit__tkinter(void)
if (m == NULL)
return NULL;
- o = PyErr_NewException("_tkinter.TclError", NULL, NULL);
- if (o == NULL) {
+ Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL);
+ if (PyModule_AddObjectRef(m, "TclError", Tkinter_TclError)) {
Py_DECREF(m);
return NULL;
}
- if (PyModule_AddObject(m, "TclError", Py_NewRef(o))) {
- Py_DECREF(o);
- Py_DECREF(m);
- return NULL;
- }
- Tkinter_TclError = o;
if (PyModule_AddIntConstant(m, "READABLE", TCL_READABLE)) {
Py_DECREF(m);
@@ -3264,41 +3258,23 @@ PyInit__tkinter(void)
return NULL;
}
- o = PyType_FromSpec(&Tkapp_Type_spec);
- if (o == NULL) {
- Py_DECREF(m);
- return NULL;
- }
- if (PyModule_AddObject(m, "TkappType", o)) {
- Py_DECREF(o);
+ Tkapp_Type = PyType_FromSpec(&Tkapp_Type_spec);
+ if (PyModule_AddObjectRef(m, "TkappType", Tkapp_Type)) {
Py_DECREF(m);
return NULL;
}
- Tkapp_Type = o;
- o = PyType_FromSpec(&Tktt_Type_spec);
- if (o == NULL) {
+ Tktt_Type = PyType_FromSpec(&Tktt_Type_spec);
+ if (PyModule_AddObjectRef(m, "TkttType", Tktt_Type)) {
Py_DECREF(m);
return NULL;
}
- if (PyModule_AddObject(m, "TkttType", o)) {
- Py_DECREF(o);
- Py_DECREF(m);
- return NULL;
- }
- Tktt_Type = o;
- o = PyType_FromSpec(&PyTclObject_Type_spec);
- if (o == NULL) {
- Py_DECREF(m);
- return NULL;
- }
- if (PyModule_AddObject(m, "Tcl_Obj", o)) {
- Py_DECREF(o);
+ PyTclObject_Type = PyType_FromSpec(&PyTclObject_Type_spec);
+ if (PyModule_AddObjectRef(m, "Tcl_Obj", PyTclObject_Type)) {
Py_DECREF(m);
return NULL;
}
- PyTclObject_Type = o;
/* This helps the dynamic loader; in Unicode aware Tcl versions