]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41675: Modernize siginterrupt calls (GH-22028)
authorPablo Galindo <Pablogsal@gmail.com>
Wed, 2 Sep 2020 14:29:12 +0000 (15:29 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Sep 2020 14:29:12 +0000 (15:29 +0100)
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) {

Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst [new file with mode: 0644]
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 (file)
index 0000000..aa102f8
--- /dev/null
@@ -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.
index 7bc1b535e6e2caae8f382e30e84f55f5d610c552..c49a3ea52e71de58899c0094e9cf695ad0c57cdf 100644 (file)
@@ -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;
     }