diff -r 09371221e59d Lib/test/test_signal.py --- a/Lib/test/test_signal.py Thu May 22 19:45:39 2014 +0100 +++ b/Lib/test/test_signal.py Thu May 22 22:02:09 2014 +0200 @@ -56,6 +56,14 @@ class GenericTests(unittest.TestCase): self.assertIsInstance(sig, signal.Signals) self.assertEqual(sys.platform, "win32") + def test_nsig(self): + # Issue #20584: Ensure that NSIG is greater than all signal number + # exposed in Python + signals = (int(getattr(signal, name)) + for name in dir(signal) + if (name.startswith("SIG") and not name.startswith('SIG_'))) + self.assertLess(max(signals), signal.NSIG) + @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class InterProcessSignalTests(unittest.TestCase): diff -r 09371221e59d Modules/signalmodule.c --- a/Modules/signalmodule.c Thu May 22 19:45:39 2014 +0100 +++ b/Modules/signalmodule.c Thu May 22 22:02:09 2014 +0200 @@ -37,6 +37,13 @@ #define SIG_ERR ((PyOS_sighandler_t)(-1)) #endif +#if defined(_SIG_MAXSIG) + /* Issue #20584: On FreeBSD, NSIG is the number of "old signals" (ex: 32), + whereas _SIG_MAXSIG is the size of a sigset (ex: 128). */ +# undef NSIG +# define NSIG _SIG_MAXSIG +#endif + #ifndef NSIG # if defined(_NSIG) # define NSIG _NSIG /* For BSD/SysV */