diff options
author | Tim Peters <tim.peters@gmail.com> | 2000-07-23 18:10:18 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2000-07-23 18:10:18 (GMT) |
commit | 1be46844d9c858a21021e2c3ad0ef9bbee64d9e0 (patch) | |
tree | ccddb1369834ad559d8c61954a8354548fdc2c57 | |
parent | 2f2370bfc99e95a4f5edaf4d29cd47afd54fb1b7 (diff) | |
download | cpython-1be46844d9c858a21021e2c3ad0ef9bbee64d9e0.zip cpython-1be46844d9c858a21021e2c3ad0ef9bbee64d9e0.tar.gz cpython-1be46844d9c858a21021e2c3ad0ef9bbee64d9e0.tar.bz2 |
Recent ANSIfication introduced a couple instances of
#if RETSIGTYPE != void
That isn't C, and MSVC properly refuses to compile it.
Introduced new Py_RETURN_FROM_SIGNAL_HANDLER macro in pyport.h
to expand to the correct thing based on RETSIGTYPE. However,
only void is ANSI! Do we still have platforms that return int?
The Unix config mess appears to #define RETSIGTYPE by magic
without being asked to, so I assume it's "a problem" across
Unices still.
-rw-r--r-- | Include/pyport.h | 26 | ||||
-rw-r--r-- | Modules/signalmodule.c | 4 | ||||
-rw-r--r-- | Parser/intrcheck.c | 4 |
3 files changed, 27 insertions, 7 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index fbaaa38..4faba7c 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -11,7 +11,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. /************************************************************************** Symbols and macros to supply platform-independent interfaces to basic -C-language operations whose spellings vary across platforms. +C language & library operations whose spellings vary across platforms. Please try to make documentation here as clear as possible: by definition, the stuff here is trying to illuminate C's darkest corners. @@ -22,6 +22,11 @@ SIGNED_RIGHT_SHIFT_ZERO_FILLS Meaning: To be defined iff i>>j does not extend the sign bit when i is a signed integral type and i < 0. Used in: Py_ARITHMETIC_RIGHT_SHIFT + +RETSIGTYPE +Meaning: Expands to void or int, depending on what the platform wants + signal handlers to return. Note that only void is ANSI! +Used in: Py_RETURN_FROM_SIGNAL_HANDLER **************************************************************************/ @@ -50,6 +55,25 @@ extern "C" { #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) #endif +/* Py_FORCE_EXPANSION + * "Simply" returns its argument. However, macro expansions within the + * argument are evaluated. This unfortunate trickery is needed to get + * token-pasting to work as desired in some cases. + */ +#define Py_FORCE_EXPANSION(X) X + +/* Py_RETURN_FROM_SIGNAL_HANDLER + * The return from a signal handler varies depending on whether RETSIGTYPE + * is int or void. The macro Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) expands + * to + * return VALUE + * if RETSIGTYPE is int, else to nothing if RETSIGTYPE is void. + */ +#define int_PySIGRETURN(VALUE) return VALUE +#define void_PySIGRETURN(VALUE) +#define Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) \ + Py_FORCE_EXPANSION(RETSIGTYPE) ## _PySIGRETURN(VALUE) + #ifdef __cplusplus } #endif diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 3a2a6df..6fe516a 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -143,9 +143,7 @@ signal_handler(int sig_num) siginterrupt(sig_num, 1); #endif signal(sig_num, signal_handler); -#if RETSIGTYPE != void - return 0; -#endif + Py_RETURN_FROM_SIGNAL_HANDLER(0); } diff --git a/Parser/intrcheck.c b/Parser/intrcheck.c index e9927e9..2f151ee 100644 --- a/Parser/intrcheck.c +++ b/Parser/intrcheck.c @@ -168,9 +168,7 @@ intcatcher(int sig) } signal(SIGINT, intcatcher); Py_AddPendingCall(checksignals_witharg, NULL); -#if RETSIGTYPE != void - return 0; -#endif + Py_RETURN_FROM_SIGNAL_HANDLER(0); } static RETSIGTYPE (*old_siginthandler)(int) = SIG_DFL; |