comparison Python/pythonrun.c @ 7206:3f255aedf621 legacy-trunk

Ehm, three unrelated changes. - Add Py_FrozenFlag, intended to suppress error messages fron getpath.c in frozen binaries. - Add Py_GetPythonHome() and Py_SetPythonHome(), intended to allow embedders to force a different PYTHONHOME. - Add new interface PyErr_PrintEx(flag); same as PyErr_Print() but flag determines whether sys.last_* are set or not. PyErr_Print() now simply calls PyErr_PrintEx(1).
author Guido van Rossum <guido@python.org>
date Fri, 06 Feb 1998 22:27:24 +0000
parents f5f305d7a617
children b5d52c415b15
comparison
equal deleted inserted replaced
7205:09ffab273eeb 7206:3f255aedf621
75 int Py_DebugFlag; /* Needed by parser.c */ 75 int Py_DebugFlag; /* Needed by parser.c */
76 int Py_VerboseFlag; /* Needed by import.c */ 76 int Py_VerboseFlag; /* Needed by import.c */
77 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ 77 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
78 int Py_NoSiteFlag; /* Suppress 'import site' */ 78 int Py_NoSiteFlag; /* Suppress 'import site' */
79 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */ 79 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */
80 int Py_FrozenFlag; /* Needed by getpath.c */
80 81
81 static int initialized = 0; 82 static int initialized = 0;
82 83
83 /* API to access the initialized flag -- useful for eroteric use */ 84 /* API to access the initialized flag -- useful for eroteric use */
84 85
363 364
364 char * 365 char *
365 Py_GetProgramName() 366 Py_GetProgramName()
366 { 367 {
367 return progname; 368 return progname;
369 }
370
371 static char *default_home = NULL;
372
373 void
374 Py_SetPythonHome(home)
375 char *home;
376 {
377 default_home = home;
378 }
379
380 char *
381 Py_GetPythonHome()
382 {
383 char *home = default_home;
384 if (home == NULL)
385 home = getenv("PYTHONHOME");
386 return home;
368 } 387 }
369 388
370 /* Create __main__ module */ 389 /* Create __main__ module */
371 390
372 static void 391 static void
638 return 0; 657 return 0;
639 } 658 }
640 659
641 void 660 void
642 PyErr_Print() 661 PyErr_Print()
662 {
663 PyErr_PrintEx(1);
664 }
665
666 void
667 PyErr_PrintEx(set_sys_last_vars)
668 int set_sys_last_vars;
643 { 669 {
644 int err = 0; 670 int err = 0;
645 PyObject *exception, *v, *tb, *f; 671 PyObject *exception, *v, *tb, *f;
646 PyErr_Fetch(&exception, &v, &tb); 672 PyErr_Fetch(&exception, &v, &tb);
647 PyErr_NormalizeException(&exception, &v, &tb); 673 PyErr_NormalizeException(&exception, &v, &tb);
677 PyObject_Print(v, stderr, Py_PRINT_RAW); 703 PyObject_Print(v, stderr, Py_PRINT_RAW);
678 fprintf(stderr, "\n"); 704 fprintf(stderr, "\n");
679 Py_Exit(1); 705 Py_Exit(1);
680 } 706 }
681 } 707 }
682 PySys_SetObject("last_type", exception); 708 if (set_sys_last_vars) {
683 PySys_SetObject("last_value", v); 709 PySys_SetObject("last_type", exception);
684 PySys_SetObject("last_traceback", tb); 710 PySys_SetObject("last_value", v);
711 PySys_SetObject("last_traceback", tb);
712 }
685 f = PySys_GetObject("stderr"); 713 f = PySys_GetObject("stderr");
686 if (f == NULL) 714 if (f == NULL)
687 fprintf(stderr, "lost sys.stderr\n"); 715 fprintf(stderr, "lost sys.stderr\n");
688 else { 716 else {
689 err = Py_FlushLine(); 717 err = Py_FlushLine();