mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Use PyOS_setsig() instead of directly calling signal() or sigaction().
This fixes the first half of bug #110611: the immediate exit when ^C is hit when readline and threads are configured. Also added a new module variable, readline.library_version.
This commit is contained in:
parent
d2cd7adf6f
commit
174efc9cdb
1 changed files with 12 additions and 5 deletions
|
|
@ -447,19 +447,20 @@ call_readline(char *prompt)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
void (*old_inthandler)(int);
|
PyOS_sighandler_t old_inthandler;
|
||||||
old_inthandler = signal(SIGINT, onintr);
|
|
||||||
|
old_inthandler = PyOS_setsig(SIGINT, onintr);
|
||||||
if (setjmp(jbuf)) {
|
if (setjmp(jbuf)) {
|
||||||
#ifdef HAVE_SIGRELSE
|
#ifdef HAVE_SIGRELSE
|
||||||
/* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
|
/* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
|
||||||
sigrelse(SIGINT);
|
sigrelse(SIGINT);
|
||||||
#endif
|
#endif
|
||||||
signal(SIGINT, old_inthandler);
|
PyOS_setsig(SIGINT, old_inthandler);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rl_event_hook = PyOS_InputHook;
|
rl_event_hook = PyOS_InputHook;
|
||||||
p = readline(prompt);
|
p = readline(prompt);
|
||||||
signal(SIGINT, old_inthandler);
|
PyOS_setsig(SIGINT, old_inthandler);
|
||||||
|
|
||||||
/* We must return a buffer allocated with PyMem_Malloc. */
|
/* We must return a buffer allocated with PyMem_Malloc. */
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
|
|
@ -493,10 +494,16 @@ static char doc_module[] =
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
initreadline(void)
|
initreadline(void)
|
||||||
{
|
{
|
||||||
PyObject *m;
|
PyObject *m, *d, *v;
|
||||||
|
|
||||||
m = Py_InitModule4("readline", readline_methods, doc_module,
|
m = Py_InitModule4("readline", readline_methods, doc_module,
|
||||||
(PyObject *)NULL, PYTHON_API_VERSION);
|
(PyObject *)NULL, PYTHON_API_VERSION);
|
||||||
|
|
||||||
|
d = PyModule_GetDict(m);
|
||||||
|
v = PyString_FromString(rl_library_version);
|
||||||
|
PyDict_SetItemString(d, "library_version", v);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
if (isatty(fileno(stdin))) {
|
if (isatty(fileno(stdin))) {
|
||||||
PyOS_ReadlineFunctionPointer = call_readline;
|
PyOS_ReadlineFunctionPointer = call_readline;
|
||||||
setup_readline();
|
setup_readline();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue