Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Switch to PyModule_AddObjectRef
  • Loading branch information
ZeroIntensity authored Aug 30, 2024
commit 36c65afe57d6d4d25f15a946c13dd2c31ba424e5
14 changes: 7 additions & 7 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3419,7 +3419,7 @@ PyInit__tkinter(void)
#endif

Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL);
if (PyModule_AddObject(m, "TclError", Tkinter_TclError)) {
if (PyModule_AddObjectRef(m, "TclError", Tkinter_TclError)) {
Py_DECREF(m);
Py_DECREF(Tkinter_TclError);
return NULL;
Expand Down Expand Up @@ -3471,25 +3471,25 @@ PyInit__tkinter(void)
}

Tkapp_Type = PyType_FromSpec(&Tkapp_Type_spec);
if (PyModule_AddObject(m, "TkappType", Tkapp_Type)) {
if (PyModule_AddObjectRef(m, "TkappType", Tkapp_Type)) {
Py_DECREF(m);
Py_DECREF(Tkapp_Type);
return NULL;
}
Py_DECREF(Tkapp_Type);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same for all other global references (otherwise why would they be global references?).

Yes, if you want to release these references, you need a module clearing function. This is not a big deal, because usually when you unload the module, you quit the program, so who cares about few dangling references?


Tktt_Type = PyType_FromSpec(&Tktt_Type_spec);
if (PyModule_AddObject(m, "TkttType", Tktt_Type)) {
if (PyModule_AddObjectRef(m, "TkttType", Tktt_Type)) {
Py_DECREF(m);
Py_DECREF(Tktt_Type);
return NULL;
}
Py_DECREF(Tktt_Type);

PyTclObject_Type = PyType_FromSpec(&PyTclObject_Type_spec);
if (PyModule_AddObject(m, "Tcl_Obj", PyTclObject_Type)) {
if (PyModule_AddObjectRef(m, "Tcl_Obj", PyTclObject_Type)) {
Py_DECREF(m);
Py_DECREF(PyTclObject_Type);
return NULL;
}
Py_DECREF(PyTclObject_Type);


/* This helps the dynamic loader; in Unicode aware Tcl versions
Expand Down