diff options
author | Victor Stinner <vstinner@python.org> | 2019-10-30 16:39:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-30 16:39:27 +0100 |
commit | 1d8da61f5ad26274556e0bbce260ce292d0402a1 (patch) | |
tree | 4cb8d81b4474ea507f852e9d4c87645285bdc602 /Modules/readline.c | |
parent | a4ed6ed9f3779b6eda41bb65f5c09004a2b937ef (diff) | |
download | cpython-git-1d8da61f5ad26274556e0bbce260ce292d0402a1.tar.gz |
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.
Diffstat (limited to 'Modules/readline.c')
-rw-r--r-- | Modules/readline.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/readline.c b/Modules/readline.c index 930e63975c..b76861f7b0 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1066,15 +1066,16 @@ done: } -/* Helper to initialize GNU readline properly. */ - -static void +/* Helper to initialize GNU readline properly. + Return -1 on memory allocation failure, return 0 on success. */ +static int setup_readline(readlinestate *mod_state) { #ifdef SAVE_LOCALE char *saved_locale = strdup(setlocale(LC_CTYPE, NULL)); - if (!saved_locale) - Py_FatalError("not enough memory to save locale"); + if (!saved_locale) { + return -1; + } #endif /* The name must be defined before initialization */ @@ -1156,6 +1157,7 @@ setup_readline(readlinestate *mod_state) rl_initialize(); RESTORE_LOCALE(saved_locale) + return 0; } /* Wrapper around GNU readline that handles signals differently. */ @@ -1369,7 +1371,10 @@ PyInit_readline(void) mod_state = (readlinestate *) PyModule_GetState(m); PyOS_ReadlineFunctionPointer = call_readline; - setup_readline(mod_state); + if (setup_readline(mod_state) < 0) { + PyErr_NoMemory(); + goto error; + } return m; |