[Python-checkins] bpo-41675: Modernize siginterrupt calls (GH-22028)

Pablo Galindo webhook-mailer at python.org
Wed Sep 2 10:29:21 EDT 2020


https://github.com/python/cpython/commit/f9c5e3f5f61cd380f8a17c814766fc3730b7fbdf
commit: f9c5e3f5f61cd380f8a17c814766fc3730b7fbdf
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-09-02T15:29:12+01:00
summary:

bpo-41675: Modernize siginterrupt calls (GH-22028)

siginterrupt is deprecated:

./Modules/signalmodule.c:667:5: warning: ‘siginterrupt’ is deprecated: Use sigaction with SA_RESTART instead [-Wdeprecated-declarations]
  667 |     if (siginterrupt(signalnum, flag)<0) {

files:
A Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst
M Modules/signalmodule.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst
new file mode 100644
index 0000000000000..aa102f8fe4384
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst	
@@ -0,0 +1,3 @@
+The implementation of :func:`signal.siginterrupt` now uses :c:func:`sigaction`
+(if it is available in the system) instead of the deprecated :c:func:`siginterrupt`.
+Patch by Pablo Galindo.
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 7bc1b535e6e2c..c49a3ea52e71d 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -664,7 +664,19 @@ signal_siginterrupt_impl(PyObject *module, int signalnum, int flag)
                         "signal number out of range");
         return NULL;
     }
-    if (siginterrupt(signalnum, flag)<0) {
+#ifdef HAVE_SIGACTION
+    struct sigaction act;
+    (void) sigaction(signalnum, NULL, &act);
+    if (flag) {
+        act.sa_flags &= ~SA_RESTART;
+    }
+    else {
+        act.sa_flags |= SA_RESTART;
+    }
+    if (sigaction(signalnum, &act, NULL) < 0) {
+#else
+    if (siginterrupt(signalnum, flag) < 0) {
+#endif
         PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }



More information about the Python-checkins mailing list