@@ -80,6 +80,12 @@ pymain_init(const _PyArgv *args)
8080
8181/* --- pymain_run_python() ---------------------------------------- */
8282
83+ static int
84+ pymain_check_signals (void )
85+ {
86+ return Py_MakePendingCalls ();
87+ }
88+
8389/* Non-zero if filename, command (-c) or module (-m) is set
8490 on the command line */
8591static inline int config_run_code (const PyConfig * config )
@@ -212,17 +218,21 @@ pymain_header(const PyConfig *config)
212218}
213219
214220
215- static void
221+ static int
216222pymain_import_readline (const PyConfig * config )
217223{
224+ if (pymain_check_signals () < 0 ) {
225+ return -1 ;
226+ }
227+
218228 if (config -> isolated ) {
219- return ;
229+ return 0 ;
220230 }
221231 if (!config -> inspect && config_run_code (config )) {
222- return ;
232+ return 0 ;
223233 }
224234 if (!isatty (fileno (stdin ))) {
225- return ;
235+ return 0 ;
226236 }
227237
228238 PyObject * mod = PyImport_ImportModule ("readline" );
@@ -232,13 +242,15 @@ pymain_import_readline(const PyConfig *config)
232242 else {
233243 Py_DECREF (mod );
234244 }
245+
235246 mod = PyImport_ImportModule ("rlcompleter" );
236247 if (mod == NULL ) {
237248 PyErr_Clear ();
238249 }
239250 else {
240251 Py_DECREF (mod );
241252 }
253+ return 0 ;
242254}
243255
244256
@@ -439,8 +451,7 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
439451 return 1 ;
440452 }
441453
442- // Call pending calls like signal handlers (SIGINT)
443- if (Py_MakePendingCalls () == -1 ) {
454+ if (pymain_check_signals () < 0 ) {
444455 fclose (fp );
445456 return pymain_exit_err_print ();
446457 }
@@ -596,8 +607,7 @@ pymain_set_inspect(PyConfig *config, int inspect, int *exitcode)
596607static int
597608_pymain_run_repl (PyConfig * config , int startup )
598609{
599- /* call pending calls like signal handlers (SIGINT) */
600- if (Py_MakePendingCalls () == -1 ) {
610+ if (pymain_check_signals () < 0 ) {
601611 goto error ;
602612 }
603613
@@ -763,7 +773,9 @@ pymain_run_python(int *exitcode)
763773 }
764774
765775 // import readline and rlcompleter before script dir is added to sys.path
766- pymain_import_readline (config );
776+ if (pymain_import_readline (config ) < 0 ) {
777+ goto error ;
778+ }
767779
768780 if (pymain_set_path0 (main_importer_path ) < 0 ) {
769781 goto error ;
@@ -775,6 +787,10 @@ pymain_run_python(int *exitcode)
775787 set_running_main = 1 ;
776788 assert (!PyErr_Occurred ());
777789
790+ if (pymain_check_signals () < 0 ) {
791+ goto error ;
792+ }
793+
778794 if (config -> run_command ) {
779795 * exitcode = pymain_run_command (config -> run_command );
780796 }
@@ -791,6 +807,10 @@ pymain_run_python(int *exitcode)
791807 * exitcode = pymain_run_stdin (config );
792808 }
793809
810+ if (pymain_check_signals () < 0 ) {
811+ goto error ;
812+ }
813+
794814 pymain_repl (config , exitcode );
795815 goto done ;
796816
0 commit comments