mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
bpo-38631: Avoid Py_FatalError() in readline (GH-16998)
readline now calls PyErr_NoMemory() rather than Py_FatalError() on memory allocation failure, when importing the module.
This commit is contained in:
parent
a4ed6ed9f3
commit
1d8da61f5a
1 changed files with 11 additions and 6 deletions
|
|
@ -1066,15 +1066,16 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Helper to initialize GNU readline properly. */
|
/* Helper to initialize GNU readline properly.
|
||||||
|
Return -1 on memory allocation failure, return 0 on success. */
|
||||||
static void
|
static int
|
||||||
setup_readline(readlinestate *mod_state)
|
setup_readline(readlinestate *mod_state)
|
||||||
{
|
{
|
||||||
#ifdef SAVE_LOCALE
|
#ifdef SAVE_LOCALE
|
||||||
char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
|
char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
|
||||||
if (!saved_locale)
|
if (!saved_locale) {
|
||||||
Py_FatalError("not enough memory to save locale");
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The name must be defined before initialization */
|
/* The name must be defined before initialization */
|
||||||
|
|
@ -1156,6 +1157,7 @@ setup_readline(readlinestate *mod_state)
|
||||||
rl_initialize();
|
rl_initialize();
|
||||||
|
|
||||||
RESTORE_LOCALE(saved_locale)
|
RESTORE_LOCALE(saved_locale)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrapper around GNU readline that handles signals differently. */
|
/* Wrapper around GNU readline that handles signals differently. */
|
||||||
|
|
@ -1369,7 +1371,10 @@ PyInit_readline(void)
|
||||||
|
|
||||||
mod_state = (readlinestate *) PyModule_GetState(m);
|
mod_state = (readlinestate *) PyModule_GetState(m);
|
||||||
PyOS_ReadlineFunctionPointer = call_readline;
|
PyOS_ReadlineFunctionPointer = call_readline;
|
||||||
setup_readline(mod_state);
|
if (setup_readline(mod_state) < 0) {
|
||||||
|
PyErr_NoMemory();
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue