Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1be4684

Browse files
committed
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.
1 parent 2f2370b commit 1be4684

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

Include/pyport.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1111

1212
/**************************************************************************
1313
Symbols and macros to supply platform-independent interfaces to basic
14-
C-language operations whose spellings vary across platforms.
14+
C language & library operations whose spellings vary across platforms.
1515
1616
Please try to make documentation here as clear as possible: by definition,
1717
the stuff here is trying to illuminate C's darkest corners.
@@ -22,6 +22,11 @@ SIGNED_RIGHT_SHIFT_ZERO_FILLS
2222
Meaning: To be defined iff i>>j does not extend the sign bit when i is a
2323
signed integral type and i < 0.
2424
Used in: Py_ARITHMETIC_RIGHT_SHIFT
25+
26+
RETSIGTYPE
27+
Meaning: Expands to void or int, depending on what the platform wants
28+
signal handlers to return. Note that only void is ANSI!
29+
Used in: Py_RETURN_FROM_SIGNAL_HANDLER
2530
**************************************************************************/
2631

2732

@@ -50,6 +55,25 @@ extern "C" {
5055
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
5156
#endif
5257

58+
/* Py_FORCE_EXPANSION
59+
* "Simply" returns its argument. However, macro expansions within the
60+
* argument are evaluated. This unfortunate trickery is needed to get
61+
* token-pasting to work as desired in some cases.
62+
*/
63+
#define Py_FORCE_EXPANSION(X) X
64+
65+
/* Py_RETURN_FROM_SIGNAL_HANDLER
66+
* The return from a signal handler varies depending on whether RETSIGTYPE
67+
* is int or void. The macro Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) expands
68+
* to
69+
* return VALUE
70+
* if RETSIGTYPE is int, else to nothing if RETSIGTYPE is void.
71+
*/
72+
#define int_PySIGRETURN(VALUE) return VALUE
73+
#define void_PySIGRETURN(VALUE)
74+
#define Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) \
75+
Py_FORCE_EXPANSION(RETSIGTYPE) ## _PySIGRETURN(VALUE)
76+
5377
#ifdef __cplusplus
5478
}
5579
#endif

Modules/signalmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ signal_handler(int sig_num)
143143
siginterrupt(sig_num, 1);
144144
#endif
145145
signal(sig_num, signal_handler);
146-
#if RETSIGTYPE != void
147-
return 0;
148-
#endif
146+
Py_RETURN_FROM_SIGNAL_HANDLER(0);
149147
}
150148

151149

Parser/intrcheck.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ intcatcher(int sig)
168168
}
169169
signal(SIGINT, intcatcher);
170170
Py_AddPendingCall(checksignals_witharg, NULL);
171-
#if RETSIGTYPE != void
172-
return 0;
173-
#endif
171+
Py_RETURN_FROM_SIGNAL_HANDLER(0);
174172
}
175173

176174
static RETSIGTYPE (*old_siginthandler)(int) = SIG_DFL;

0 commit comments

Comments
 (0)