2 /* Python interpreter top-level routines, including init/exit */
6 #include "Python-ast.h"
7 #undef Yield /* undefine macro conflicting with winbase.h */
27 #include "malloc.h" /* for alloca */
30 #ifdef HAVE_LANGINFO_H
41 #define PRINT_TOTAL_REFS()
42 #else /* Py_REF_DEBUG */
43 #define PRINT_TOTAL_REFS() fprintf(stderr, \
44 "[%" PY_FORMAT_SIZE_T "d refs]\n", \
52 extern char *Py_GetPath(void);
54 extern grammar _PyParser_Grammar
; /* From graminit.c */
57 static void initmain(void);
58 static void initsite(void);
59 static PyObject
*run_mod(mod_ty
, const char *, PyObject
*, PyObject
*,
60 PyCompilerFlags
*, PyArena
*);
61 static PyObject
*run_pyc_file(FILE *, const char *, PyObject
*, PyObject
*,
63 static void err_input(perrdetail
*);
64 static void initsigs(void);
65 static void wait_for_thread_shutdown(void);
66 static void call_sys_exitfunc(void);
67 static void call_ll_exitfuncs(void);
68 extern void _PyUnicode_Init(void);
69 extern void _PyUnicode_Fini(void);
72 extern void _PyGILState_Init(PyInterpreterState
*, PyThreadState
*);
73 extern void _PyGILState_Fini(void);
74 #endif /* WITH_THREAD */
76 int Py_DebugFlag
; /* Needed by parser.c */
77 int Py_VerboseFlag
; /* Needed by import.c */
78 int Py_InteractiveFlag
; /* Needed by Py_FdIsInteractive() below */
79 int Py_InspectFlag
; /* Needed to determine whether to exit at SystemError */
80 int Py_NoSiteFlag
; /* Suppress 'import site' */
81 int Py_BytesWarningFlag
; /* Warn on str(bytes) and str(buffer) */
82 int Py_DontWriteBytecodeFlag
; /* Suppress writing bytecode files (*.py[co]) */
83 int Py_UseClassExceptionsFlag
= 1; /* Needed by bltinmodule.c: deprecated */
84 int Py_FrozenFlag
; /* Needed by getpath.c */
85 int Py_UnicodeFlag
= 0; /* Needed by compile.c */
86 int Py_IgnoreEnvironmentFlag
; /* e.g. PYTHONPATH, PYTHONHOME */
87 /* _XXX Py_QnewFlag should go away in 2.3. It's true iff -Qnew is passed,
88 on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
89 true divisions (which they will be in 2.3). */
91 int Py_NoUserSiteDirectory
= 0; /* for -s and site.py */
93 /* PyModule_GetWarningsModule is no longer necessary as of 2.6
94 since _warnings is builtin. This API should not be used. */
96 PyModule_GetWarningsModule(void)
98 return PyImport_ImportModule("warnings");
101 static int initialized
= 0;
103 /* API to access the initialized flag -- useful for esoteric use */
106 Py_IsInitialized(void)
111 /* Global initializations. Can be undone by Py_Finalize(). Don't
112 call this twice without an intervening Py_Finalize() call. When
113 initializations fail, a fatal error is issued and the function does
114 not return. On return, the first thread and interpreter state have
117 Locking: you must hold the interpreter lock while calling this.
118 (If the lock has not yet been initialized, that's equivalent to
119 having the lock, but you cannot use multiple threads.)
124 add_flag(int flag
, const char *envs
)
126 int env
= atoi(envs
);
135 Py_InitializeEx(int install_sigs
)
137 PyInterpreterState
*interp
;
138 PyThreadState
*tstate
;
139 PyObject
*bimod
, *sysmod
;
141 char *icodeset
= NULL
; /* On Windows, input codeset may theoretically
142 differ from output codeset. */
143 char *codeset
= NULL
;
145 int free_codeset
= 0;
147 PyObject
*sys_stream
, *sys_isatty
;
148 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
149 char *saved_locale
, *loc_codeset
;
155 extern void _Py_ReadyTypes(void);
161 if ((p
= Py_GETENV("PYTHONDEBUG")) && *p
!= '\0')
162 Py_DebugFlag
= add_flag(Py_DebugFlag
, p
);
163 if ((p
= Py_GETENV("PYTHONVERBOSE")) && *p
!= '\0')
164 Py_VerboseFlag
= add_flag(Py_VerboseFlag
, p
);
165 if ((p
= Py_GETENV("PYTHONOPTIMIZE")) && *p
!= '\0')
166 Py_OptimizeFlag
= add_flag(Py_OptimizeFlag
, p
);
167 if ((p
= Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p
!= '\0')
168 Py_DontWriteBytecodeFlag
= add_flag(Py_DontWriteBytecodeFlag
, p
);
170 interp
= PyInterpreterState_New();
172 Py_FatalError("Py_Initialize: can't make first interpreter");
174 tstate
= PyThreadState_New(interp
);
176 Py_FatalError("Py_Initialize: can't make first thread");
177 (void) PyThreadState_Swap(tstate
);
181 if (!_PyFrame_Init())
182 Py_FatalError("Py_Initialize: can't init frames");
185 Py_FatalError("Py_Initialize: can't init ints");
188 Py_FatalError("Py_Initialize: can't init longs");
190 if (!PyByteArray_Init())
191 Py_FatalError("Py_Initialize: can't init bytearray");
195 interp
->modules
= PyDict_New();
196 if (interp
->modules
== NULL
)
197 Py_FatalError("Py_Initialize: can't make modules dictionary");
198 interp
->modules_reloading
= PyDict_New();
199 if (interp
->modules_reloading
== NULL
)
200 Py_FatalError("Py_Initialize: can't make modules_reloading dictionary");
202 #ifdef Py_USING_UNICODE
203 /* Init Unicode implementation; relies on the codec registry */
207 bimod
= _PyBuiltin_Init();
209 Py_FatalError("Py_Initialize: can't initialize __builtin__");
210 interp
->builtins
= PyModule_GetDict(bimod
);
211 if (interp
->builtins
== NULL
)
212 Py_FatalError("Py_Initialize: can't initialize builtins dict");
213 Py_INCREF(interp
->builtins
);
215 sysmod
= _PySys_Init();
217 Py_FatalError("Py_Initialize: can't initialize sys");
218 interp
->sysdict
= PyModule_GetDict(sysmod
);
219 if (interp
->sysdict
== NULL
)
220 Py_FatalError("Py_Initialize: can't initialize sys dict");
221 Py_INCREF(interp
->sysdict
);
222 _PyImport_FixupExtension("sys", "sys");
223 PySys_SetPath(Py_GetPath());
224 PyDict_SetItemString(interp
->sysdict
, "modules",
229 /* initialize builtin exceptions */
231 _PyImport_FixupExtension("exceptions", "exceptions");
233 /* phase 2 of builtins */
234 _PyImport_FixupExtension("__builtin__", "__builtin__");
236 _PyImportHooks_Init();
239 initsigs(); /* Signal handling stuff, including initintr() */
241 /* Initialize warnings. */
243 if (PySys_HasWarnOptions()) {
244 PyObject
*warnings_module
= PyImport_ImportModule("warnings");
245 if (!warnings_module
)
247 Py_XDECREF(warnings_module
);
250 initmain(); /* Module __main__ */
252 /* auto-thread-state API, if available */
254 _PyGILState_Init(interp
, tstate
);
255 #endif /* WITH_THREAD */
258 initsite(); /* Module site */
260 if ((p
= Py_GETENV("PYTHONIOENCODING")) && *p
!= '\0') {
261 p
= icodeset
= codeset
= strdup(p
);
263 errors
= strchr(p
, ':');
271 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
272 /* On Unix, set the file system encoding according to the
273 user's preference, if the CODESET names a well-known
274 Python codec, and Py_FileSystemDefaultEncoding isn't
275 initialized by other means. Also set the encoding of
276 stdin and stdout if these are terminals, unless overridden. */
278 if (!overridden
|| !Py_FileSystemDefaultEncoding
) {
279 saved_locale
= strdup(setlocale(LC_CTYPE
, NULL
));
280 setlocale(LC_CTYPE
, "");
281 loc_codeset
= nl_langinfo(CODESET
);
282 if (loc_codeset
&& *loc_codeset
) {
283 PyObject
*enc
= PyCodec_Encoder(loc_codeset
);
285 loc_codeset
= strdup(loc_codeset
);
288 if (PyErr_ExceptionMatches(PyExc_LookupError
)) {
298 setlocale(LC_CTYPE
, saved_locale
);
302 codeset
= icodeset
= loc_codeset
;
306 /* Initialize Py_FileSystemDefaultEncoding from
307 locale even if PYTHONIOENCODING is set. */
308 if (!Py_FileSystemDefaultEncoding
) {
309 Py_FileSystemDefaultEncoding
= loc_codeset
;
320 sprintf(ibuf
, "cp%d", GetConsoleCP());
321 sprintf(buf
, "cp%d", GetConsoleOutputCP());
326 sys_stream
= PySys_GetObject("stdin");
327 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
331 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
332 PyFile_Check(sys_stream
)) {
333 if (!PyFile_SetEncodingAndErrors(sys_stream
, icodeset
, errors
))
334 Py_FatalError("Cannot set codeset of stdin");
336 Py_XDECREF(sys_isatty
);
338 sys_stream
= PySys_GetObject("stdout");
339 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
343 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
344 PyFile_Check(sys_stream
)) {
345 if (!PyFile_SetEncodingAndErrors(sys_stream
, codeset
, errors
))
346 Py_FatalError("Cannot set codeset of stdout");
348 Py_XDECREF(sys_isatty
);
350 sys_stream
= PySys_GetObject("stderr");
351 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
355 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
356 PyFile_Check(sys_stream
)) {
357 if (!PyFile_SetEncodingAndErrors(sys_stream
, codeset
, errors
))
358 Py_FatalError("Cannot set codeset of stderr");
360 Py_XDECREF(sys_isatty
);
375 extern void dump_counts(FILE*);
378 /* Undo the effect of Py_Initialize().
380 Beware: if multiple interpreter and/or thread states exist, these
381 are not wiped out; only the current thread and interpreter state
382 are deleted. But since everything else is deleted, those other
383 interpreter and thread states should no longer be used.
385 (XXX We should do better, e.g. wipe out all interpreters and
395 PyInterpreterState
*interp
;
396 PyThreadState
*tstate
;
401 wait_for_thread_shutdown();
403 /* The interpreter is still entirely intact at this point, and the
404 * exit funcs may be relying on that. In particular, if some thread
405 * or exit func is still waiting to do an import, the import machinery
406 * expects Py_IsInitialized() to return true. So don't say the
407 * interpreter is uninitialized until after the exit funcs have run.
408 * Note that Threading.py uses an exit func to do a join on all the
409 * threads created thru it, so this also protects pending imports in
410 * the threads created via Threading.
415 /* Get current thread state and interpreter pointer */
416 tstate
= PyThreadState_GET();
417 interp
= tstate
->interp
;
419 /* Disable signal handling */
420 PyOS_FiniInterrupts();
422 /* Clear type lookup cache */
425 /* Collect garbage. This may call finalizers; it's nice to call these
426 * before all modules are destroyed.
427 * XXX If a __del__ or weakref callback is triggered here, and tries to
428 * XXX import a module, bad things can happen, because Python no
429 * XXX longer believes it's initialized.
430 * XXX Fatal Python error: Interpreter not initialized (version mismatch?)
431 * XXX is easy to provoke that way. I've also seen, e.g.,
432 * XXX Exception exceptions.ImportError: 'No module named sha'
433 * XXX in <function callback at 0x008F5718> ignored
434 * XXX but I'm unclear on exactly how that one happens. In any case,
435 * XXX I haven't seen a real-life report of either of these.
439 /* With COUNT_ALLOCS, it helps to run GC multiple times:
440 each collection might release some types from the type
441 list, so they become garbage. */
442 while (PyGC_Collect() > 0)
446 /* Destroy all modules */
449 /* Collect final garbage. This disposes of cycles created by
450 * new-style class definitions, for example.
451 * XXX This is disabled because it caused too many problems. If
452 * XXX a __del__ or weakref callback triggers here, Python code has
453 * XXX a hard time running, because even the sys module has been
454 * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
455 * XXX One symptom is a sequence of information-free messages
456 * XXX coming from threads (if a __del__ or callback is invoked,
457 * XXX other threads can execute too, and any exception they encounter
458 * XXX triggers a comedy of errors as subsystem after subsystem
459 * XXX fails to find what it *expects* to find in sys to help report
460 * XXX the exception and consequent unexpected failures). I've also
461 * XXX seen segfaults then, after adding print statements to the
462 * XXX Python code getting called.
468 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
471 /* Debugging stuff */
479 /* Display all objects still alive -- this can invoke arbitrary
480 * __repr__ overrides, so requires a mostly-intact interpreter.
481 * Alas, a lot of stuff may still be alive now that will be cleaned
484 if (Py_GETENV("PYTHONDUMPREFS"))
485 _Py_PrintReferences(stderr
);
486 #endif /* Py_TRACE_REFS */
488 /* Clear interpreter state */
489 PyInterpreterState_Clear(interp
);
491 /* Now we decref the exception classes. After this point nothing
492 can raise an exception. That's okay, because each Fini() method
493 below has been checked to make sure no exceptions are ever
499 /* Cleanup auto-thread-state */
502 #endif /* WITH_THREAD */
504 /* Delete current thread */
505 PyThreadState_Swap(NULL
);
506 PyInterpreterState_Delete(interp
);
508 /* Sundry finalizers */
521 #ifdef Py_USING_UNICODE
522 /* Cleanup Unicode implementation */
526 /* XXX Still allocated:
527 - various static ad-hoc pointers to interned strings
528 - int and float free list blocks
529 - whatever various modules and libraries allocate
532 PyGrammar_RemoveAccelerators(&_PyParser_Grammar
);
535 /* Display addresses (& refcnts) of all objects still alive.
536 * An address can be used to find the repr of the object, printed
537 * above by _Py_PrintReferences.
539 if (Py_GETENV("PYTHONDUMPREFS"))
540 _Py_PrintReferenceAddresses(stderr
);
541 #endif /* Py_TRACE_REFS */
542 #ifdef PYMALLOC_DEBUG
543 if (Py_GETENV("PYTHONMALLOCSTATS"))
544 _PyObject_DebugMallocStats();
550 /* Create and initialize a new interpreter and thread, and return the
551 new thread. This requires that Py_Initialize() has been called
554 Unsuccessful initialization yields a NULL pointer. Note that *no*
555 exception information is available even in this case -- the
556 exception information is held in the thread, and there is no
564 Py_NewInterpreter(void)
566 PyInterpreterState
*interp
;
567 PyThreadState
*tstate
, *save_tstate
;
568 PyObject
*bimod
, *sysmod
;
571 Py_FatalError("Py_NewInterpreter: call Py_Initialize first");
573 interp
= PyInterpreterState_New();
577 tstate
= PyThreadState_New(interp
);
578 if (tstate
== NULL
) {
579 PyInterpreterState_Delete(interp
);
583 save_tstate
= PyThreadState_Swap(tstate
);
585 /* XXX The following is lax in error checking */
587 interp
->modules
= PyDict_New();
588 interp
->modules_reloading
= PyDict_New();
590 bimod
= _PyImport_FindExtension("__builtin__", "__builtin__");
592 interp
->builtins
= PyModule_GetDict(bimod
);
593 if (interp
->builtins
== NULL
)
595 Py_INCREF(interp
->builtins
);
597 sysmod
= _PyImport_FindExtension("sys", "sys");
598 if (bimod
!= NULL
&& sysmod
!= NULL
) {
599 interp
->sysdict
= PyModule_GetDict(sysmod
);
600 if (interp
->sysdict
== NULL
)
602 Py_INCREF(interp
->sysdict
);
603 PySys_SetPath(Py_GetPath());
604 PyDict_SetItemString(interp
->sysdict
, "modules",
606 _PyImportHooks_Init();
612 if (!PyErr_Occurred())
616 /* Oops, it didn't work. Undo it all. */
619 PyThreadState_Clear(tstate
);
620 PyThreadState_Swap(save_tstate
);
621 PyThreadState_Delete(tstate
);
622 PyInterpreterState_Delete(interp
);
627 /* Delete an interpreter and its last thread. This requires that the
628 given thread state is current, that the thread has no remaining
629 frames, and that it is its interpreter's only remaining thread.
630 It is a fatal error to violate these constraints.
632 (Py_Finalize() doesn't have these constraints -- it zaps
633 everything, regardless.)
640 Py_EndInterpreter(PyThreadState
*tstate
)
642 PyInterpreterState
*interp
= tstate
->interp
;
644 if (tstate
!= PyThreadState_GET())
645 Py_FatalError("Py_EndInterpreter: thread is not current");
646 if (tstate
->frame
!= NULL
)
647 Py_FatalError("Py_EndInterpreter: thread still has a frame");
648 if (tstate
!= interp
->tstate_head
|| tstate
->next
!= NULL
)
649 Py_FatalError("Py_EndInterpreter: not the last thread");
652 PyInterpreterState_Clear(interp
);
653 PyThreadState_Swap(NULL
);
654 PyInterpreterState_Delete(interp
);
657 static char *progname
= "python";
660 Py_SetProgramName(char *pn
)
667 Py_GetProgramName(void)
672 static char *default_home
= NULL
;
675 Py_SetPythonHome(char *home
)
681 Py_GetPythonHome(void)
683 char *home
= default_home
;
684 if (home
== NULL
&& !Py_IgnoreEnvironmentFlag
)
685 home
= Py_GETENV("PYTHONHOME");
689 /* Create __main__ module */
695 m
= PyImport_AddModule("__main__");
697 Py_FatalError("can't create __main__ module");
698 d
= PyModule_GetDict(m
);
699 if (PyDict_GetItemString(d
, "__builtins__") == NULL
) {
700 PyObject
*bimod
= PyImport_ImportModule("__builtin__");
702 PyDict_SetItemString(d
, "__builtins__", bimod
) != 0)
703 Py_FatalError("can't add __builtins__ to __main__");
708 /* Import the site module (not into __main__ though) */
714 m
= PyImport_ImportModule("site");
725 /* Parse input from a file and execute it */
728 PyRun_AnyFileExFlags(FILE *fp
, const char *filename
, int closeit
,
729 PyCompilerFlags
*flags
)
731 if (filename
== NULL
)
733 if (Py_FdIsInteractive(fp
, filename
)) {
734 int err
= PyRun_InteractiveLoopFlags(fp
, filename
, flags
);
740 return PyRun_SimpleFileExFlags(fp
, filename
, closeit
, flags
);
744 PyRun_InteractiveLoopFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
748 PyCompilerFlags local_flags
;
751 flags
= &local_flags
;
752 local_flags
.cf_flags
= 0;
754 v
= PySys_GetObject("ps1");
756 PySys_SetObject("ps1", v
= PyString_FromString(">>> "));
759 v
= PySys_GetObject("ps2");
761 PySys_SetObject("ps2", v
= PyString_FromString("... "));
765 ret
= PyRun_InteractiveOneFlags(fp
, filename
, flags
);
777 /* compute parser flags based on compiler flags */
778 #define PARSER_FLAGS(flags) \
779 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
780 PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0)
783 /* Keep an example of flags with future keyword support. */
784 #define PARSER_FLAGS(flags) \
785 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
786 PyPARSE_DONT_IMPLY_DEDENT : 0) \
787 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \
788 PyPARSE_PRINT_IS_FUNCTION : 0) \
789 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \
790 PyPARSE_UNICODE_LITERALS : 0) \
795 PyRun_InteractiveOneFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
797 PyObject
*m
, *d
, *v
, *w
;
800 char *ps1
= "", *ps2
= "";
803 v
= PySys_GetObject("ps1");
808 else if (PyString_Check(v
))
809 ps1
= PyString_AsString(v
);
811 w
= PySys_GetObject("ps2");
816 else if (PyString_Check(w
))
817 ps2
= PyString_AsString(w
);
819 arena
= PyArena_New();
825 mod
= PyParser_ASTFromFile(fp
, filename
,
826 Py_single_input
, ps1
, ps2
,
827 flags
, &errcode
, arena
);
832 if (errcode
== E_EOF
) {
839 m
= PyImport_AddModule("__main__");
844 d
= PyModule_GetDict(m
);
845 v
= run_mod(mod
, filename
, d
, d
, flags
, arena
);
857 /* Check whether a file maybe a pyc file: Look at the extension,
858 the file type, and, if we may close it, at the first few bytes. */
861 maybe_pyc_file(FILE *fp
, const char* filename
, const char* ext
, int closeit
)
863 if (strcmp(ext
, ".pyc") == 0 || strcmp(ext
, ".pyo") == 0)
866 /* Only look into the file if we are allowed to close it, since
867 it then should also be seekable. */
869 /* Read only two bytes of the magic. If the file was opened in
870 text mode, the bytes 3 and 4 of the magic (\r\n) might not
871 be read as they are on disk. */
872 unsigned int halfmagic
= PyImport_GetMagicNumber() & 0xFFFF;
873 unsigned char buf
[2];
874 /* Mess: In case of -x, the stream is NOT at its start now,
875 and ungetc() was used to push back the first newline,
876 which makes the current stream position formally undefined,
877 and a x-platform nightmare.
878 Unfortunately, we have no direct way to know whether -x
879 was specified. So we use a terrible hack: if the current
880 stream position is not 0, we assume -x was specified, and
881 give up. Bug 132850 on SourceForge spells out the
882 hopelessness of trying anything else (fseek and ftell
883 don't work predictably x-platform for text-mode files).
886 if (ftell(fp
) == 0) {
887 if (fread(buf
, 1, 2, fp
) == 2 &&
888 ((unsigned int)buf
[1]<<8 | buf
[0]) == halfmagic
)
898 PyRun_SimpleFileExFlags(FILE *fp
, const char *filename
, int closeit
,
899 PyCompilerFlags
*flags
)
903 int set_file_name
= 0, ret
, len
;
905 m
= PyImport_AddModule("__main__");
908 d
= PyModule_GetDict(m
);
909 if (PyDict_GetItemString(d
, "__file__") == NULL
) {
910 PyObject
*f
= PyString_FromString(filename
);
913 if (PyDict_SetItemString(d
, "__file__", f
) < 0) {
920 len
= strlen(filename
);
921 ext
= filename
+ len
- (len
> 4 ? 4 : 0);
922 if (maybe_pyc_file(fp
, filename
, ext
, closeit
)) {
923 /* Try to run a pyc file. First, re-open in binary */
926 if ((fp
= fopen(filename
, "rb")) == NULL
) {
927 fprintf(stderr
, "python: Can't reopen .pyc file\n");
931 /* Turn on optimization if a .pyo file is given */
932 if (strcmp(ext
, ".pyo") == 0)
934 v
= run_pyc_file(fp
, filename
, d
, d
, flags
);
936 v
= PyRun_FileExFlags(fp
, filename
, Py_file_input
, d
, d
,
949 if (set_file_name
&& PyDict_DelItemString(d
, "__file__"))
955 PyRun_SimpleStringFlags(const char *command
, PyCompilerFlags
*flags
)
958 m
= PyImport_AddModule("__main__");
961 d
= PyModule_GetDict(m
);
962 v
= PyRun_StringFlags(command
, Py_file_input
, d
, d
, flags
);
974 parse_syntax_error(PyObject
*err
, PyObject
**message
, const char **filename
,
975 int *lineno
, int *offset
, const char **text
)
980 /* old style errors */
981 if (PyTuple_Check(err
))
982 return PyArg_ParseTuple(err
, "O(ziiz)", message
, filename
,
983 lineno
, offset
, text
);
985 /* new style errors. `err' is an instance */
987 if (! (v
= PyObject_GetAttrString(err
, "msg")))
991 if (!(v
= PyObject_GetAttrString(err
, "filename")))
995 else if (! (*filename
= PyString_AsString(v
)))
999 if (!(v
= PyObject_GetAttrString(err
, "lineno")))
1001 hold
= PyInt_AsLong(v
);
1004 if (hold
< 0 && PyErr_Occurred())
1006 *lineno
= (int)hold
;
1008 if (!(v
= PyObject_GetAttrString(err
, "offset")))
1015 hold
= PyInt_AsLong(v
);
1018 if (hold
< 0 && PyErr_Occurred())
1020 *offset
= (int)hold
;
1023 if (!(v
= PyObject_GetAttrString(err
, "text")))
1027 else if (! (*text
= PyString_AsString(v
)))
1044 print_error_text(PyObject
*f
, int offset
, const char *text
)
1048 if (offset
> 0 && offset
== (int)strlen(text
))
1051 nl
= strchr(text
, '\n');
1052 if (nl
== NULL
|| nl
-text
>= offset
)
1054 offset
-= (int)(nl
+1-text
);
1057 while (*text
== ' ' || *text
== '\t') {
1062 PyFile_WriteString(" ", f
);
1063 PyFile_WriteString(text
, f
);
1064 if (*text
== '\0' || text
[strlen(text
)-1] != '\n')
1065 PyFile_WriteString("\n", f
);
1068 PyFile_WriteString(" ", f
);
1070 while (offset
> 0) {
1071 PyFile_WriteString(" ", f
);
1074 PyFile_WriteString("^\n", f
);
1078 handle_system_exit(void)
1080 PyObject
*exception
, *value
, *tb
;
1084 /* Don't exit if -i flag was given. This flag is set to 0
1085 * when entering interactive mode for inspecting. */
1088 PyErr_Fetch(&exception
, &value
, &tb
);
1092 if (value
== NULL
|| value
== Py_None
)
1094 if (PyExceptionInstance_Check(value
)) {
1095 /* The error code should be in the `code' attribute. */
1096 PyObject
*code
= PyObject_GetAttrString(value
, "code");
1100 if (value
== Py_None
)
1103 /* If we failed to dig out the 'code' attribute,
1104 just let the else clause below print the error. */
1106 if (PyInt_Check(value
))
1107 exitcode
= (int)PyInt_AsLong(value
);
1109 PyObject
*sys_stderr
= PySys_GetObject("stderr");
1110 if (sys_stderr
!= NULL
&& sys_stderr
!= Py_None
) {
1111 PyFile_WriteObject(value
, sys_stderr
, Py_PRINT_RAW
);
1113 PyObject_Print(value
, stderr
, Py_PRINT_RAW
);
1116 PySys_WriteStderr("\n");
1120 /* Restore and clear the exception info, in order to properly decref
1121 * the exception, value, and traceback. If we just exit instead,
1122 * these leak, which confuses PYTHONDUMPREFS output, and may prevent
1123 * some finalizers from running.
1125 PyErr_Restore(exception
, value
, tb
);
1132 PyErr_PrintEx(int set_sys_last_vars
)
1134 PyObject
*exception
, *v
, *tb
, *hook
;
1136 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1137 handle_system_exit();
1139 PyErr_Fetch(&exception
, &v
, &tb
);
1140 if (exception
== NULL
)
1142 PyErr_NormalizeException(&exception
, &v
, &tb
);
1143 if (exception
== NULL
)
1145 /* Now we know v != NULL too */
1146 if (set_sys_last_vars
) {
1147 PySys_SetObject("last_type", exception
);
1148 PySys_SetObject("last_value", v
);
1149 PySys_SetObject("last_traceback", tb
);
1151 hook
= PySys_GetObject("excepthook");
1153 PyObject
*args
= PyTuple_Pack(3,
1154 exception
, v
, tb
? tb
: Py_None
);
1155 PyObject
*result
= PyEval_CallObject(hook
, args
);
1156 if (result
== NULL
) {
1157 PyObject
*exception2
, *v2
, *tb2
;
1158 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1159 handle_system_exit();
1161 PyErr_Fetch(&exception2
, &v2
, &tb2
);
1162 PyErr_NormalizeException(&exception2
, &v2
, &tb2
);
1163 /* It should not be possible for exception2 or v2
1164 to be NULL. However PyErr_Display() can't
1165 tolerate NULLs, so just be safe. */
1166 if (exception2
== NULL
) {
1167 exception2
= Py_None
;
1168 Py_INCREF(exception2
);
1177 PySys_WriteStderr("Error in sys.excepthook:\n");
1178 PyErr_Display(exception2
, v2
, tb2
);
1179 PySys_WriteStderr("\nOriginal exception was:\n");
1180 PyErr_Display(exception
, v
, tb
);
1181 Py_DECREF(exception2
);
1188 PySys_WriteStderr("sys.excepthook is missing\n");
1189 PyErr_Display(exception
, v
, tb
);
1191 Py_XDECREF(exception
);
1197 PyErr_Display(PyObject
*exception
, PyObject
*value
, PyObject
*tb
)
1200 PyObject
*f
= PySys_GetObject("stderr");
1203 fprintf(stderr
, "lost sys.stderr\n");
1208 if (tb
&& tb
!= Py_None
)
1209 err
= PyTraceBack_Print(tb
, f
);
1211 PyObject_HasAttrString(value
, "print_file_and_line"))
1214 const char *filename
, *text
;
1216 if (!parse_syntax_error(value
, &message
, &filename
,
1217 &lineno
, &offset
, &text
))
1221 PyFile_WriteString(" File \"", f
);
1222 if (filename
== NULL
)
1223 PyFile_WriteString("<string>", f
);
1225 PyFile_WriteString(filename
, f
);
1226 PyFile_WriteString("\", line ", f
);
1227 PyOS_snprintf(buf
, sizeof(buf
), "%d", lineno
);
1228 PyFile_WriteString(buf
, f
);
1229 PyFile_WriteString("\n", f
);
1231 print_error_text(f
, offset
, text
);
1234 /* Can't be bothered to check all those
1235 PyFile_WriteString() calls */
1236 if (PyErr_Occurred())
1241 /* Don't do anything else */
1243 else if (PyExceptionClass_Check(exception
)) {
1244 PyObject
* moduleName
;
1245 char* className
= PyExceptionClass_Name(exception
);
1246 if (className
!= NULL
) {
1247 char *dot
= strrchr(className
, '.');
1252 moduleName
= PyObject_GetAttrString(exception
, "__module__");
1253 if (moduleName
== NULL
)
1254 err
= PyFile_WriteString("<unknown>", f
);
1256 char* modstr
= PyString_AsString(moduleName
);
1257 if (modstr
&& strcmp(modstr
, "exceptions"))
1259 err
= PyFile_WriteString(modstr
, f
);
1260 err
+= PyFile_WriteString(".", f
);
1262 Py_DECREF(moduleName
);
1265 if (className
== NULL
)
1266 err
= PyFile_WriteString("<unknown>", f
);
1268 err
= PyFile_WriteString(className
, f
);
1272 err
= PyFile_WriteObject(exception
, f
, Py_PRINT_RAW
);
1273 if (err
== 0 && (value
!= Py_None
)) {
1274 PyObject
*s
= PyObject_Str(value
);
1275 /* only print colon if the str() of the
1276 object is not the empty string
1280 else if (!PyString_Check(s
) ||
1281 PyString_GET_SIZE(s
) != 0)
1282 err
= PyFile_WriteString(": ", f
);
1284 err
= PyFile_WriteObject(s
, f
, Py_PRINT_RAW
);
1287 /* try to write a newline in any case */
1288 err
+= PyFile_WriteString("\n", f
);
1291 /* If an error happened here, don't show it.
1292 XXX This is wrong, but too many callers rely on this behavior. */
1298 PyRun_StringFlags(const char *str
, int start
, PyObject
*globals
,
1299 PyObject
*locals
, PyCompilerFlags
*flags
)
1301 PyObject
*ret
= NULL
;
1303 PyArena
*arena
= PyArena_New();
1307 mod
= PyParser_ASTFromString(str
, "<string>", start
, flags
, arena
);
1309 ret
= run_mod(mod
, "<string>", globals
, locals
, flags
, arena
);
1310 PyArena_Free(arena
);
1315 PyRun_FileExFlags(FILE *fp
, const char *filename
, int start
, PyObject
*globals
,
1316 PyObject
*locals
, int closeit
, PyCompilerFlags
*flags
)
1320 PyArena
*arena
= PyArena_New();
1324 mod
= PyParser_ASTFromFile(fp
, filename
, start
, 0, 0,
1325 flags
, NULL
, arena
);
1329 PyArena_Free(arena
);
1332 ret
= run_mod(mod
, filename
, globals
, locals
, flags
, arena
);
1333 PyArena_Free(arena
);
1338 run_mod(mod_ty mod
, const char *filename
, PyObject
*globals
, PyObject
*locals
,
1339 PyCompilerFlags
*flags
, PyArena
*arena
)
1343 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1346 v
= PyEval_EvalCode(co
, globals
, locals
);
1352 run_pyc_file(FILE *fp
, const char *filename
, PyObject
*globals
,
1353 PyObject
*locals
, PyCompilerFlags
*flags
)
1358 long PyImport_GetMagicNumber(void);
1360 magic
= PyMarshal_ReadLongFromFile(fp
);
1361 if (magic
!= PyImport_GetMagicNumber()) {
1362 PyErr_SetString(PyExc_RuntimeError
,
1363 "Bad magic number in .pyc file");
1366 (void) PyMarshal_ReadLongFromFile(fp
);
1367 v
= PyMarshal_ReadLastObjectFromFile(fp
);
1369 if (v
== NULL
|| !PyCode_Check(v
)) {
1371 PyErr_SetString(PyExc_RuntimeError
,
1372 "Bad code object in .pyc file");
1375 co
= (PyCodeObject
*)v
;
1376 v
= PyEval_EvalCode(co
, globals
, locals
);
1378 flags
->cf_flags
|= (co
->co_flags
& PyCF_MASK
);
1384 Py_CompileStringFlags(const char *str
, const char *filename
, int start
,
1385 PyCompilerFlags
*flags
)
1389 PyArena
*arena
= PyArena_New();
1393 mod
= PyParser_ASTFromString(str
, filename
, start
, flags
, arena
);
1395 PyArena_Free(arena
);
1398 if (flags
&& (flags
->cf_flags
& PyCF_ONLY_AST
)) {
1399 PyObject
*result
= PyAST_mod2obj(mod
);
1400 PyArena_Free(arena
);
1403 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1404 PyArena_Free(arena
);
1405 return (PyObject
*)co
;
1409 Py_SymtableString(const char *str
, const char *filename
, int start
)
1411 struct symtable
*st
;
1413 PyCompilerFlags flags
;
1414 PyArena
*arena
= PyArena_New();
1420 mod
= PyParser_ASTFromString(str
, filename
, start
, &flags
, arena
);
1422 PyArena_Free(arena
);
1425 st
= PySymtable_Build(mod
, filename
, 0);
1426 PyArena_Free(arena
);
1430 /* Preferred access to parser is through AST. */
1432 PyParser_ASTFromString(const char *s
, const char *filename
, int start
,
1433 PyCompilerFlags
*flags
, PyArena
*arena
)
1436 PyCompilerFlags localflags
;
1438 int iflags
= PARSER_FLAGS(flags
);
1440 node
*n
= PyParser_ParseStringFlagsFilenameEx(s
, filename
,
1441 &_PyParser_Grammar
, start
, &err
,
1443 if (flags
== NULL
) {
1444 localflags
.cf_flags
= 0;
1445 flags
= &localflags
;
1448 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1449 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1460 PyParser_ASTFromFile(FILE *fp
, const char *filename
, int start
, char *ps1
,
1461 char *ps2
, PyCompilerFlags
*flags
, int *errcode
,
1465 PyCompilerFlags localflags
;
1467 int iflags
= PARSER_FLAGS(flags
);
1469 node
*n
= PyParser_ParseFileFlagsEx(fp
, filename
, &_PyParser_Grammar
,
1470 start
, ps1
, ps2
, &err
, &iflags
);
1471 if (flags
== NULL
) {
1472 localflags
.cf_flags
= 0;
1473 flags
= &localflags
;
1476 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1477 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1484 *errcode
= err
.error
;
1489 /* Simplified interface to parsefile -- return node or set exception */
1492 PyParser_SimpleParseFileFlags(FILE *fp
, const char *filename
, int start
, int flags
)
1495 node
*n
= PyParser_ParseFileFlags(fp
, filename
, &_PyParser_Grammar
,
1496 start
, NULL
, NULL
, &err
, flags
);
1503 /* Simplified interface to parsestring -- return node or set exception */
1506 PyParser_SimpleParseStringFlags(const char *str
, int start
, int flags
)
1509 node
*n
= PyParser_ParseStringFlags(str
, &_PyParser_Grammar
,
1510 start
, &err
, flags
);
1517 PyParser_SimpleParseStringFlagsFilename(const char *str
, const char *filename
,
1518 int start
, int flags
)
1521 node
*n
= PyParser_ParseStringFlagsFilename(str
, filename
,
1522 &_PyParser_Grammar
, start
, &err
, flags
);
1529 PyParser_SimpleParseStringFilename(const char *str
, const char *filename
, int start
)
1531 return PyParser_SimpleParseStringFlagsFilename(str
, filename
, start
, 0);
1534 /* May want to move a more generalized form of this to parsetok.c or
1535 even parser modules. */
1538 PyParser_SetError(perrdetail
*err
)
1543 /* Set the error appropriate to the given input error code (see errcode.h) */
1546 err_input(perrdetail
*err
)
1548 PyObject
*v
, *w
, *errtype
;
1551 errtype
= PyExc_SyntaxError
;
1552 switch (err
->error
) {
1556 errtype
= PyExc_IndentationError
;
1557 if (err
->expected
== INDENT
)
1558 msg
= "expected an indented block";
1559 else if (err
->token
== INDENT
)
1560 msg
= "unexpected indent";
1561 else if (err
->token
== DEDENT
)
1562 msg
= "unexpected unindent";
1564 errtype
= PyExc_SyntaxError
;
1565 msg
= "invalid syntax";
1569 msg
= "invalid token";
1572 msg
= "EOF while scanning triple-quoted string literal";
1575 msg
= "EOL while scanning string literal";
1578 if (!PyErr_Occurred())
1579 PyErr_SetNone(PyExc_KeyboardInterrupt
);
1585 msg
= "unexpected EOF while parsing";
1588 errtype
= PyExc_TabError
;
1589 msg
= "inconsistent use of tabs and spaces in indentation";
1592 msg
= "expression too long";
1595 errtype
= PyExc_IndentationError
;
1596 msg
= "unindent does not match any outer indentation level";
1599 errtype
= PyExc_IndentationError
;
1600 msg
= "too many levels of indentation";
1603 PyObject
*type
, *value
, *tb
;
1604 PyErr_Fetch(&type
, &value
, &tb
);
1605 if (value
!= NULL
) {
1606 u
= PyObject_Str(value
);
1608 msg
= PyString_AsString(u
);
1612 msg
= "unknown decode error";
1619 msg
= "unexpected character after line continuation character";
1622 fprintf(stderr
, "error=%d\n", err
->error
);
1623 msg
= "unknown parsing error";
1626 v
= Py_BuildValue("(ziiz)", err
->filename
,
1627 err
->lineno
, err
->offset
, err
->text
);
1630 w
= Py_BuildValue("(sO)", msg
, v
);
1633 PyErr_SetObject(errtype
, w
);
1636 if (err
->text
!= NULL
) {
1637 PyObject_FREE(err
->text
);
1642 /* Print fatal error message and abort */
1645 Py_FatalError(const char *msg
)
1647 fprintf(stderr
, "Fatal Python error: %s\n", msg
);
1648 fflush(stderr
); /* it helps in Windows debug build */
1652 size_t len
= strlen(msg
);
1656 /* Convert the message to wchar_t. This uses a simple one-to-one
1657 conversion, assuming that the this error message actually uses ASCII
1658 only. If this ceases to be true, we will have to convert. */
1659 buffer
= alloca( (len
+1) * (sizeof *buffer
));
1660 for( i
=0; i
<=len
; ++i
)
1662 OutputDebugStringW(L
"Fatal Python error: ");
1663 OutputDebugStringW(buffer
);
1664 OutputDebugStringW(L
"\n");
1669 #endif /* MS_WINDOWS */
1673 /* Clean up and exit */
1676 #include "pythread.h"
1679 /* Wait until threading._shutdown completes, provided
1680 the threading module was imported in the first place.
1681 The shutdown routine will wait until all non-daemon
1682 "threading" threads have completed. */
1684 wait_for_thread_shutdown(void)
1688 PyThreadState
*tstate
= PyThreadState_GET();
1689 PyObject
*threading
= PyMapping_GetItemString(tstate
->interp
->modules
,
1691 if (threading
== NULL
) {
1692 /* threading not imported */
1696 result
= PyObject_CallMethod(threading
, "_shutdown", "");
1698 PyErr_WriteUnraisable(threading
);
1701 Py_DECREF(threading
);
1705 #define NEXITFUNCS 32
1706 static void (*exitfuncs
[NEXITFUNCS
])(void);
1707 static int nexitfuncs
= 0;
1709 int Py_AtExit(void (*func
)(void))
1711 if (nexitfuncs
>= NEXITFUNCS
)
1713 exitfuncs
[nexitfuncs
++] = func
;
1718 call_sys_exitfunc(void)
1720 PyObject
*exitfunc
= PySys_GetObject("exitfunc");
1724 Py_INCREF(exitfunc
);
1725 PySys_SetObject("exitfunc", (PyObject
*)NULL
);
1726 res
= PyEval_CallObject(exitfunc
, (PyObject
*)NULL
);
1728 if (!PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1729 PySys_WriteStderr("Error in sys.exitfunc:\n");
1733 Py_DECREF(exitfunc
);
1741 call_ll_exitfuncs(void)
1743 while (nexitfuncs
> 0)
1744 (*exitfuncs
[--nexitfuncs
])();
1762 PyOS_setsig(SIGPIPE
, SIG_IGN
);
1765 PyOS_setsig(SIGXFZ
, SIG_IGN
);
1768 PyOS_setsig(SIGXFSZ
, SIG_IGN
);
1770 PyOS_InitInterrupts(); /* May imply initsignal() */
1775 * The file descriptor fd is considered ``interactive'' if either
1776 * a) isatty(fd) is TRUE, or
1777 * b) the -i flag was given, and the filename associated with
1778 * the descriptor is NULL or "<stdin>" or "???".
1781 Py_FdIsInteractive(FILE *fp
, const char *filename
)
1783 if (isatty((int)fileno(fp
)))
1785 if (!Py_InteractiveFlag
)
1787 return (filename
== NULL
) ||
1788 (strcmp(filename
, "<stdin>") == 0) ||
1789 (strcmp(filename
, "???") == 0);
1793 #if defined(USE_STACKCHECK)
1794 #if defined(WIN32) && defined(_MSC_VER)
1796 /* Stack checking for Microsoft C */
1802 * Return non-zero when we run out of memory on the stack; zero otherwise.
1805 PyOS_CheckStack(void)
1808 /* alloca throws a stack overflow exception if there's
1809 not enough space left on the stack */
1810 alloca(PYOS_STACK_MARGIN
* sizeof(void*));
1812 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW
?
1813 EXCEPTION_EXECUTE_HANDLER
:
1814 EXCEPTION_CONTINUE_SEARCH
) {
1815 int errcode
= _resetstkoflw();
1818 Py_FatalError("Could not reset the stack!");
1824 #endif /* WIN32 && _MSC_VER */
1826 /* Alternate implementations can be added here... */
1828 #endif /* USE_STACKCHECK */
1831 /* Wrappers around sigaction() or signal(). */
1834 PyOS_getsig(int sig
)
1836 #ifdef HAVE_SIGACTION
1837 struct sigaction context
;
1838 if (sigaction(sig
, NULL
, &context
) == -1)
1840 return context
.sa_handler
;
1842 PyOS_sighandler_t handler
;
1843 /* Special signal handling for the secure CRT in Visual Studio 2005 */
1844 #if defined(_MSC_VER) && _MSC_VER >= 1400
1846 /* Only these signals are valid */
1855 /* Don't call signal() with other values or it will assert */
1859 #endif /* _MSC_VER && _MSC_VER >= 1400 */
1860 handler
= signal(sig
, SIG_IGN
);
1861 if (handler
!= SIG_ERR
)
1862 signal(sig
, handler
);
1868 PyOS_setsig(int sig
, PyOS_sighandler_t handler
)
1870 #ifdef HAVE_SIGACTION
1871 /* Some code in Modules/signalmodule.c depends on sigaction() being
1872 * used here if HAVE_SIGACTION is defined. Fix that if this code
1873 * changes to invalidate that assumption.
1875 struct sigaction context
, ocontext
;
1876 context
.sa_handler
= handler
;
1877 sigemptyset(&context
.sa_mask
);
1878 context
.sa_flags
= 0;
1879 if (sigaction(sig
, &context
, &ocontext
) == -1)
1881 return ocontext
.sa_handler
;
1883 PyOS_sighandler_t oldhandler
;
1884 oldhandler
= signal(sig
, handler
);
1885 #ifdef HAVE_SIGINTERRUPT
1886 siginterrupt(sig
, 1);
1892 /* Deprecated C API functions still provided for binary compatiblity */
1894 #undef PyParser_SimpleParseFile
1896 PyParser_SimpleParseFile(FILE *fp
, const char *filename
, int start
)
1898 return PyParser_SimpleParseFileFlags(fp
, filename
, start
, 0);
1901 #undef PyParser_SimpleParseString
1903 PyParser_SimpleParseString(const char *str
, int start
)
1905 return PyParser_SimpleParseStringFlags(str
, start
, 0);
1908 #undef PyRun_AnyFile
1910 PyRun_AnyFile(FILE *fp
, const char *name
)
1912 return PyRun_AnyFileExFlags(fp
, name
, 0, NULL
);
1915 #undef PyRun_AnyFileEx
1917 PyRun_AnyFileEx(FILE *fp
, const char *name
, int closeit
)
1919 return PyRun_AnyFileExFlags(fp
, name
, closeit
, NULL
);
1922 #undef PyRun_AnyFileFlags
1924 PyRun_AnyFileFlags(FILE *fp
, const char *name
, PyCompilerFlags
*flags
)
1926 return PyRun_AnyFileExFlags(fp
, name
, 0, flags
);
1930 PyAPI_FUNC(PyObject
*)
1931 PyRun_File(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
)
1933 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, NULL
);
1937 PyAPI_FUNC(PyObject
*)
1938 PyRun_FileEx(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
, int c
)
1940 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, c
, NULL
);
1943 #undef PyRun_FileFlags
1944 PyAPI_FUNC(PyObject
*)
1945 PyRun_FileFlags(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
,
1946 PyCompilerFlags
*flags
)
1948 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, flags
);
1951 #undef PyRun_SimpleFile
1953 PyRun_SimpleFile(FILE *f
, const char *p
)
1955 return PyRun_SimpleFileExFlags(f
, p
, 0, NULL
);
1958 #undef PyRun_SimpleFileEx
1960 PyRun_SimpleFileEx(FILE *f
, const char *p
, int c
)
1962 return PyRun_SimpleFileExFlags(f
, p
, c
, NULL
);
1967 PyAPI_FUNC(PyObject
*)
1968 PyRun_String(const char *str
, int s
, PyObject
*g
, PyObject
*l
)
1970 return PyRun_StringFlags(str
, s
, g
, l
, NULL
);
1973 #undef PyRun_SimpleString
1975 PyRun_SimpleString(const char *s
)
1977 return PyRun_SimpleStringFlags(s
, NULL
);
1980 #undef Py_CompileString
1981 PyAPI_FUNC(PyObject
*)
1982 Py_CompileString(const char *str
, const char *p
, int s
)
1984 return Py_CompileStringFlags(str
, p
, s
, NULL
);
1987 #undef PyRun_InteractiveOne
1989 PyRun_InteractiveOne(FILE *f
, const char *p
)
1991 return PyRun_InteractiveOneFlags(f
, p
, NULL
);
1994 #undef PyRun_InteractiveLoop
1996 PyRun_InteractiveLoop(FILE *f
, const char *p
)
1998 return PyRun_InteractiveLoopFlags(f
, p
, NULL
);