tech-pkg: patches to python to fix PR 24797

Subject: patches to python to fix PR 24797
To: None <tech-pkg@NetBSD.org, recht@NetBSD.org>
From: Luke Mewburn <lukem@NetBSD.org>
List: tech-pkg
Date: 06/10/2004 23:02:31
--4AmJdx/+JAF2YHMk
Content-Type: multipart/mixed; boundary="3WLtXmtPTeS+BWmV"
Content-Disposition: inline
--3WLtXmtPTeS+BWmV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi Marc (& the rest of tech-pkg)
I have discovered the problem behind the bug that I reported
in PR 24797.
The following patches work for python23-pth, but I'm not
sure the correct method to apply them given the way that
python23 is built (across multiple makefiles), so I offer
them here.
Note that these patches should also fix the bug for python 2.2
and python 2.1, but they'll probably need massaging to apply.
I've also attached a simple script that can reproduce the problem;
if you need to press ^C twice to raise KeyboardInterrupt the bug
is present; you should only need to press ^C once.
Cheers,
Luke.
--3WLtXmtPTeS+BWmV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pytest.py"
#!/usr/bin/env python
import sys
print "press ^C to exit. if buggy, you may need more than one"
l=sys.stdin.read()
--3WLtXmtPTeS+BWmV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="python.fix"
Content-Transfer-Encoding: quoted-printable
--- Python/pythonrun.c.orig	2004年03月23日 07:41:47.000000000 +1100
+++ Python/pythonrun.c
@@ -1581,13 +1581,13 @@ initsigs(void)
 {
 #ifdef HAVE_SIGNAL_H
 #ifdef SIGPIPE
-	signal(SIGPIPE, SIG_IGN);
+	PyOS_setsig(SIGPIPE, SIG_IGN);
 #endif
 #ifdef SIGXFZ
-	signal(SIGXFZ, SIG_IGN);
+	PyOS_setsig(SIGXFZ, SIG_IGN);
 #endif
 #ifdef SIGXFSZ
-	signal(SIGXFSZ, SIG_IGN);
+	PyOS_setsig(SIGXFSZ, SIG_IGN);
 #endif
 #endif /* HAVE_SIGNAL_H */
 	PyOS_InitInterrupts(); /* May imply initsignal() */
@@ -1684,20 +1684,19 @@ PyOS_sighandler_t
 PyOS_setsig(int sig, PyOS_sighandler_t handler)
 {
 #ifdef HAVE_SIGACTION
-	struct sigaction context;
-	PyOS_sighandler_t oldhandler;
-	/* Initialize context.sa_handler to SIG_ERR which makes about as
-	 * much sense as anything else. It should get overwritten if
-	 * sigaction actually succeeds and otherwise we avoid an
-	 * uninitialized memory read.
-	 */
-	context.sa_handler =3D SIG_ERR;
-	sigaction(sig, NULL, &context);
-	oldhandler =3D context.sa_handler;
+	struct sigaction context, ocontext;
 	context.sa_handler =3D handler;
-	sigaction(sig, &context, NULL);
-	return oldhandler;
+	sigemptyset(&context.sa_mask);
+	context.sa_flags =3D 0;
+	if (sigaction(sig, &context, &ocontext) =3D=3D -1)
+		return SIG_ERR;
+	return ocontext.sa_handler;
 #else
-	return signal(sig, handler);
+	PyOS_sighandler_t oldhandler;
+	oldhandler =3D signal(sig, handler);
+#ifdef HAVE_SIGINTERRUPT
+	siginterrupt(sig, 1);
+#endif
+	return oldhandler;
 #endif
 }
--- Modules/signalmodule.c.orig	2003年03月14日 00:56:53.000000000 +1100
+++ Modules/signalmodule.c
@@ -137,9 +137,6 @@ signal_handler(int sig_num)
 		return;
 	}
 #endif
-#ifdef HAVE_SIGINTERRUPT
-	siginterrupt(sig_num, 1);
-#endif
 	PyOS_setsig(sig_num, signal_handler);
 }
=20
@@ -217,9 +214,6 @@ signal_signal(PyObject *self, PyObject *
 	}
 	else
 		func =3D signal_handler;
-#ifdef HAVE_SIGINTERRUPT
-	siginterrupt(sig_num, 1);
-#endif
 	if (PyOS_setsig(sig_num, func) =3D=3D SIG_ERR) {
 		PyErr_SetFromErrno(PyExc_RuntimeError);
 		return NULL;
--3WLtXmtPTeS+BWmV--
--4AmJdx/+JAF2YHMk
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (NetBSD)
iD8DBQFAyFvnpBhtmn8zJHIRAqYqAJsEAzVKwgAQA/f5GFJELtvzYSvgbQCgkRb9
OjlI4cQEbgEZVxWUtq5AVIg=
=1+oI
-----END PGP SIGNATURE-----
--4AmJdx/+JAF2YHMk--

AltStyle によって変換されたページ (->オリジナル) /