@@ -269,13 +269,14 @@ pymain_run_command(wchar_t *command)
269
269
270
270
271
271
static int
272
- pymain_start_pyrepl_no_main (void )
272
+ pymain_start_pyrepl (void )
273
273
{
274
274
int res = 0 ;
275
275
PyObject * console = NULL ;
276
276
PyObject * empty_tuple = NULL ;
277
277
PyObject * kwargs = NULL ;
278
278
PyObject * console_result = NULL ;
279
+ PyObject * main_module = NULL ;
279
280
280
281
PyObject * pyrepl = PyImport_ImportModule ("_pyrepl.main" );
281
282
if (pyrepl == NULL ) {
@@ -299,7 +300,16 @@ pymain_start_pyrepl_no_main(void)
299
300
res = pymain_exit_err_print ();
300
301
goto done ;
301
302
}
303
+ main_module = PyImport_AddModuleRef ("__main__" );
304
+ if (main_module == NULL ) {
305
+ res = pymain_exit_err_print ();
306
+ goto done ;
307
+ }
302
308
if (!PyDict_SetItemString (kwargs , "pythonstartup" , _PyLong_GetOne ())) {
309
+ if (PyDict_SetItemString (kwargs , "mainmodule" , main_module ) < 0 ) {
310
+ res = pymain_exit_err_print ();
311
+ goto done ;
312
+ }
303
313
console_result = PyObject_Call (console , empty_tuple , kwargs );
304
314
if (console_result == NULL ) {
305
315
res = pymain_exit_err_print ();
@@ -311,6 +321,7 @@ pymain_start_pyrepl_no_main(void)
311
321
Py_XDECREF (empty_tuple );
312
322
Py_XDECREF (console );
313
323
Py_XDECREF (pyrepl );
324
+ Py_XDECREF (main_module );
314
325
return res ;
315
326
}
316
327
@@ -595,7 +606,7 @@ pymain_repl(PyConfig *config, int *exitcode)
595
606
* exitcode = (run != 0 );
596
607
return ;
597
608
}
598
- int run = pymain_start_pyrepl_no_main ();
609
+ int run = pymain_start_pyrepl ();
599
610
* exitcode = (run != 0 );
600
611
return ;
601
612
}
0 commit comments