[Python-checkins] bpo-38037: Fix reference counters in signal module (GH-15753)
Miss Islington (bot)
webhook-mailer at python.org
Mon Sep 9 10:42:39 EDT 2019
https://github.com/python/cpython/commit/b150d0bf1bb4c3203bb3293625e32aed01b25887
commit: b150d0bf1bb4c3203bb3293625e32aed01b25887
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-09-09T07:42:35-07:00
summary:
bpo-38037: Fix reference counters in signal module (GH-15753)
(cherry picked from commit 77643c486fd22d8030e0d82c13012684b4ab6df1)
Co-authored-by: animalize <animalize at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2019-09-09-18-39-23.bpo-38037.B0UgFU.rst
M Modules/signalmodule.c
diff --git a/Misc/NEWS.d/next/Library/2019-09-09-18-39-23.bpo-38037.B0UgFU.rst b/Misc/NEWS.d/next/Library/2019-09-09-18-39-23.bpo-38037.B0UgFU.rst
new file mode 100644
index 000000000000..607673bd9994
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-09-09-18-39-23.bpo-38037.B0UgFU.rst
@@ -0,0 +1 @@
+Fix reference counters in the :mod:`signal` module.
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 7698984ff3af..9aca70599689 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -1329,7 +1329,7 @@ static struct PyModuleDef signalmodule = {
PyMODINIT_FUNC
PyInit__signal(void)
{
- PyObject *m, *d, *x;
+ PyObject *m, *d;
int i;
/* Create the module and add the functions */
@@ -1350,13 +1350,17 @@ PyInit__signal(void)
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
- x = DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
- if (PyModule_AddObject(m, "SIG_DFL", x))
+ DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
+ if (!DefaultHandler ||
+ PyDict_SetItemString(d, "SIG_DFL", DefaultHandler) < 0) {
goto finally;
+ }
- x = IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
- if (PyModule_AddObject(m, "SIG_IGN", x))
+ IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
+ if (!IgnoreHandler ||
+ PyDict_SetItemString(d, "SIG_IGN", IgnoreHandler) < 0) {
goto finally;
+ }
if (PyModule_AddIntMacro(m, NSIG))
goto finally;
@@ -1374,8 +1378,8 @@ PyInit__signal(void)
goto finally;
#endif
- x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
- if (!x)
+ IntHandler = PyDict_GetItemString(d, "default_int_handler");
+ if (!IntHandler)
goto finally;
Py_INCREF(IntHandler);
@@ -1568,8 +1572,10 @@ PyInit__signal(void)
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
ItimerError = PyErr_NewException("signal.ItimerError",
PyExc_OSError, NULL);
- if (PyModule_AddObject(m, "ItimerError", ItimerError))
+ if (!ItimerError ||
+ PyDict_SetItemString(d, "ItimerError", ItimerError) < 0) {
goto finally;
+ }
#endif
#ifdef CTRL_C_EVENT
@@ -1615,6 +1621,9 @@ finisignal(void)
Py_CLEAR(IntHandler);
Py_CLEAR(DefaultHandler);
Py_CLEAR(IgnoreHandler);
+#ifdef HAVE_GETITIMER
+ Py_CLEAR(ItimerError);
+#endif
}
More information about the Python-checkins
mailing list