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 SystemExit */
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 */
92 int Py_HashRandomizationFlag
= 0; /* for -R and PYTHONHASHSEED */
95 /* Hack to force loading of object files */
96 int (*_PyOS_mystrnicmp_hack
)(const char *, const char *, Py_ssize_t
) = \
97 PyOS_mystrnicmp
; /* Python/pystrcmp.o */
99 /* PyModule_GetWarningsModule is no longer necessary as of 2.6
100 since _warnings is builtin. This API should not be used. */
102 PyModule_GetWarningsModule(void)
104 return PyImport_ImportModule("warnings");
107 static int initialized
= 0;
109 /* API to access the initialized flag -- useful for esoteric use */
112 Py_IsInitialized(void)
117 /* Global initializations. Can be undone by Py_Finalize(). Don't
118 call this twice without an intervening Py_Finalize() call. When
119 initializations fail, a fatal error is issued and the function does
120 not return. On return, the first thread and interpreter state have
123 Locking: you must hold the interpreter lock while calling this.
124 (If the lock has not yet been initialized, that's equivalent to
125 having the lock, but you cannot use multiple threads.)
130 add_flag(int flag
, const char *envs
)
132 int env
= atoi(envs
);
141 Py_InitializeEx(int install_sigs
)
143 PyInterpreterState
*interp
;
144 PyThreadState
*tstate
;
145 PyObject
*bimod
, *sysmod
;
147 char *icodeset
= NULL
; /* On Windows, input codeset may theoretically
148 differ from output codeset. */
149 char *codeset
= NULL
;
151 int free_codeset
= 0;
153 PyObject
*sys_stream
, *sys_isatty
;
154 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
155 char *saved_locale
, *loc_codeset
;
161 extern void _Py_ReadyTypes(void);
167 if ((p
= Py_GETENV("PYTHONDEBUG")) && *p
!= '\0')
168 Py_DebugFlag
= add_flag(Py_DebugFlag
, p
);
169 if ((p
= Py_GETENV("PYTHONVERBOSE")) && *p
!= '\0')
170 Py_VerboseFlag
= add_flag(Py_VerboseFlag
, p
);
171 if ((p
= Py_GETENV("PYTHONOPTIMIZE")) && *p
!= '\0')
172 Py_OptimizeFlag
= add_flag(Py_OptimizeFlag
, p
);
173 if ((p
= Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p
!= '\0')
174 Py_DontWriteBytecodeFlag
= add_flag(Py_DontWriteBytecodeFlag
, p
);
175 /* The variable is only tested for existence here; _PyRandom_Init will
176 check its value further. */
177 if ((p
= Py_GETENV("PYTHONHASHSEED")) && *p
!= '\0')
178 Py_HashRandomizationFlag
= add_flag(Py_HashRandomizationFlag
, p
);
182 interp
= PyInterpreterState_New();
184 Py_FatalError("Py_Initialize: can't make first interpreter");
186 tstate
= PyThreadState_New(interp
);
188 Py_FatalError("Py_Initialize: can't make first thread");
189 (void) PyThreadState_Swap(tstate
);
193 if (!_PyFrame_Init())
194 Py_FatalError("Py_Initialize: can't init frames");
197 Py_FatalError("Py_Initialize: can't init ints");
200 Py_FatalError("Py_Initialize: can't init longs");
202 if (!PyByteArray_Init())
203 Py_FatalError("Py_Initialize: can't init bytearray");
207 interp
->modules
= PyDict_New();
208 if (interp
->modules
== NULL
)
209 Py_FatalError("Py_Initialize: can't make modules dictionary");
210 interp
->modules_reloading
= PyDict_New();
211 if (interp
->modules_reloading
== NULL
)
212 Py_FatalError("Py_Initialize: can't make modules_reloading dictionary");
214 #ifdef Py_USING_UNICODE
215 /* Init Unicode implementation; relies on the codec registry */
219 bimod
= _PyBuiltin_Init();
221 Py_FatalError("Py_Initialize: can't initialize __builtin__");
222 interp
->builtins
= PyModule_GetDict(bimod
);
223 if (interp
->builtins
== NULL
)
224 Py_FatalError("Py_Initialize: can't initialize builtins dict");
225 Py_INCREF(interp
->builtins
);
227 sysmod
= _PySys_Init();
229 Py_FatalError("Py_Initialize: can't initialize sys");
230 interp
->sysdict
= PyModule_GetDict(sysmod
);
231 if (interp
->sysdict
== NULL
)
232 Py_FatalError("Py_Initialize: can't initialize sys dict");
233 Py_INCREF(interp
->sysdict
);
234 _PyImport_FixupExtension("sys", "sys");
235 PySys_SetPath(Py_GetPath());
236 PyDict_SetItemString(interp
->sysdict
, "modules",
241 /* initialize builtin exceptions */
243 _PyImport_FixupExtension("exceptions", "exceptions");
245 /* phase 2 of builtins */
246 _PyImport_FixupExtension("__builtin__", "__builtin__");
248 _PyImportHooks_Init();
251 initsigs(); /* Signal handling stuff, including initintr() */
253 /* Initialize warnings. */
255 if (PySys_HasWarnOptions()) {
256 PyObject
*warnings_module
= PyImport_ImportModule("warnings");
257 if (!warnings_module
)
259 Py_XDECREF(warnings_module
);
262 initmain(); /* Module __main__ */
264 /* auto-thread-state API, if available */
266 _PyGILState_Init(interp
, tstate
);
267 #endif /* WITH_THREAD */
270 initsite(); /* Module site */
272 if ((p
= Py_GETENV("PYTHONIOENCODING")) && *p
!= '\0') {
273 p
= icodeset
= codeset
= strdup(p
);
275 errors
= strchr(p
, ':');
283 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
284 /* On Unix, set the file system encoding according to the
285 user's preference, if the CODESET names a well-known
286 Python codec, and Py_FileSystemDefaultEncoding isn't
287 initialized by other means. Also set the encoding of
288 stdin and stdout if these are terminals, unless overridden. */
290 if (!overridden
|| !Py_FileSystemDefaultEncoding
) {
291 saved_locale
= strdup(setlocale(LC_CTYPE
, NULL
));
292 setlocale(LC_CTYPE
, "");
293 loc_codeset
= nl_langinfo(CODESET
);
294 if (loc_codeset
&& *loc_codeset
) {
295 PyObject
*enc
= PyCodec_Encoder(loc_codeset
);
297 loc_codeset
= strdup(loc_codeset
);
300 if (PyErr_ExceptionMatches(PyExc_LookupError
)) {
310 setlocale(LC_CTYPE
, saved_locale
);
314 codeset
= icodeset
= loc_codeset
;
318 /* Initialize Py_FileSystemDefaultEncoding from
319 locale even if PYTHONIOENCODING is set. */
320 if (!Py_FileSystemDefaultEncoding
) {
321 Py_FileSystemDefaultEncoding
= loc_codeset
;
332 sprintf(ibuf
, "cp%d", GetConsoleCP());
333 sprintf(buf
, "cp%d", GetConsoleOutputCP());
338 sys_stream
= PySys_GetObject("stdin");
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
, icodeset
, errors
))
346 Py_FatalError("Cannot set codeset of stdin");
348 Py_XDECREF(sys_isatty
);
350 sys_stream
= PySys_GetObject("stdout");
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 stdout");
360 Py_XDECREF(sys_isatty
);
362 sys_stream
= PySys_GetObject("stderr");
363 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
367 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
368 PyFile_Check(sys_stream
)) {
369 if (!PyFile_SetEncodingAndErrors(sys_stream
, codeset
, errors
))
370 Py_FatalError("Cannot set codeset of stderr");
372 Py_XDECREF(sys_isatty
);
387 extern void dump_counts(FILE*);
390 /* Undo the effect of Py_Initialize().
392 Beware: if multiple interpreter and/or thread states exist, these
393 are not wiped out; only the current thread and interpreter state
394 are deleted. But since everything else is deleted, those other
395 interpreter and thread states should no longer be used.
397 (XXX We should do better, e.g. wipe out all interpreters and
407 PyInterpreterState
*interp
;
408 PyThreadState
*tstate
;
413 wait_for_thread_shutdown();
415 /* The interpreter is still entirely intact at this point, and the
416 * exit funcs may be relying on that. In particular, if some thread
417 * or exit func is still waiting to do an import, the import machinery
418 * expects Py_IsInitialized() to return true. So don't say the
419 * interpreter is uninitialized until after the exit funcs have run.
420 * Note that Threading.py uses an exit func to do a join on all the
421 * threads created thru it, so this also protects pending imports in
422 * the threads created via Threading.
427 /* Get current thread state and interpreter pointer */
428 tstate
= PyThreadState_GET();
429 interp
= tstate
->interp
;
431 /* Disable signal handling */
432 PyOS_FiniInterrupts();
434 /* Clear type lookup cache */
437 /* Collect garbage. This may call finalizers; it's nice to call these
438 * before all modules are destroyed.
439 * XXX If a __del__ or weakref callback is triggered here, and tries to
440 * XXX import a module, bad things can happen, because Python no
441 * XXX longer believes it's initialized.
442 * XXX Fatal Python error: Interpreter not initialized (version mismatch?)
443 * XXX is easy to provoke that way. I've also seen, e.g.,
444 * XXX Exception exceptions.ImportError: 'No module named sha'
445 * XXX in <function callback at 0x008F5718> ignored
446 * XXX but I'm unclear on exactly how that one happens. In any case,
447 * XXX I haven't seen a real-life report of either of these.
451 /* With COUNT_ALLOCS, it helps to run GC multiple times:
452 each collection might release some types from the type
453 list, so they become garbage. */
454 while (PyGC_Collect() > 0)
458 /* Destroy all modules */
461 /* Collect final garbage. This disposes of cycles created by
462 * new-style class definitions, for example.
463 * XXX This is disabled because it caused too many problems. If
464 * XXX a __del__ or weakref callback triggers here, Python code has
465 * XXX a hard time running, because even the sys module has been
466 * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
467 * XXX One symptom is a sequence of information-free messages
468 * XXX coming from threads (if a __del__ or callback is invoked,
469 * XXX other threads can execute too, and any exception they encounter
470 * XXX triggers a comedy of errors as subsystem after subsystem
471 * XXX fails to find what it *expects* to find in sys to help report
472 * XXX the exception and consequent unexpected failures). I've also
473 * XXX seen segfaults then, after adding print statements to the
474 * XXX Python code getting called.
480 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
483 /* Debugging stuff */
491 /* Display all objects still alive -- this can invoke arbitrary
492 * __repr__ overrides, so requires a mostly-intact interpreter.
493 * Alas, a lot of stuff may still be alive now that will be cleaned
496 if (Py_GETENV("PYTHONDUMPREFS"))
497 _Py_PrintReferences(stderr
);
498 #endif /* Py_TRACE_REFS */
500 /* Clear interpreter state */
501 PyInterpreterState_Clear(interp
);
503 /* Now we decref the exception classes. After this point nothing
504 can raise an exception. That's okay, because each Fini() method
505 below has been checked to make sure no exceptions are ever
511 /* Cleanup auto-thread-state */
514 #endif /* WITH_THREAD */
516 /* Delete current thread */
517 PyThreadState_Swap(NULL
);
518 PyInterpreterState_Delete(interp
);
520 /* Sundry finalizers */
534 #ifdef Py_USING_UNICODE
535 /* Cleanup Unicode implementation */
539 /* XXX Still allocated:
540 - various static ad-hoc pointers to interned strings
541 - int and float free list blocks
542 - whatever various modules and libraries allocate
545 PyGrammar_RemoveAccelerators(&_PyParser_Grammar
);
548 /* Display addresses (& refcnts) of all objects still alive.
549 * An address can be used to find the repr of the object, printed
550 * above by _Py_PrintReferences.
552 if (Py_GETENV("PYTHONDUMPREFS"))
553 _Py_PrintReferenceAddresses(stderr
);
554 #endif /* Py_TRACE_REFS */
555 #ifdef PYMALLOC_DEBUG
556 if (Py_GETENV("PYTHONMALLOCSTATS"))
557 _PyObject_DebugMallocStats();
563 /* Create and initialize a new interpreter and thread, and return the
564 new thread. This requires that Py_Initialize() has been called
567 Unsuccessful initialization yields a NULL pointer. Note that *no*
568 exception information is available even in this case -- the
569 exception information is held in the thread, and there is no
577 Py_NewInterpreter(void)
579 PyInterpreterState
*interp
;
580 PyThreadState
*tstate
, *save_tstate
;
581 PyObject
*bimod
, *sysmod
;
584 Py_FatalError("Py_NewInterpreter: call Py_Initialize first");
586 interp
= PyInterpreterState_New();
590 tstate
= PyThreadState_New(interp
);
591 if (tstate
== NULL
) {
592 PyInterpreterState_Delete(interp
);
596 save_tstate
= PyThreadState_Swap(tstate
);
598 /* XXX The following is lax in error checking */
600 interp
->modules
= PyDict_New();
601 interp
->modules_reloading
= PyDict_New();
603 bimod
= _PyImport_FindExtension("__builtin__", "__builtin__");
605 interp
->builtins
= PyModule_GetDict(bimod
);
606 if (interp
->builtins
== NULL
)
608 Py_INCREF(interp
->builtins
);
610 sysmod
= _PyImport_FindExtension("sys", "sys");
611 if (bimod
!= NULL
&& sysmod
!= NULL
) {
612 interp
->sysdict
= PyModule_GetDict(sysmod
);
613 if (interp
->sysdict
== NULL
)
615 Py_INCREF(interp
->sysdict
);
616 PySys_SetPath(Py_GetPath());
617 PyDict_SetItemString(interp
->sysdict
, "modules",
619 _PyImportHooks_Init();
625 if (!PyErr_Occurred())
629 /* Oops, it didn't work. Undo it all. */
632 PyThreadState_Clear(tstate
);
633 PyThreadState_Swap(save_tstate
);
634 PyThreadState_Delete(tstate
);
635 PyInterpreterState_Delete(interp
);
640 /* Delete an interpreter and its last thread. This requires that the
641 given thread state is current, that the thread has no remaining
642 frames, and that it is its interpreter's only remaining thread.
643 It is a fatal error to violate these constraints.
645 (Py_Finalize() doesn't have these constraints -- it zaps
646 everything, regardless.)
653 Py_EndInterpreter(PyThreadState
*tstate
)
655 PyInterpreterState
*interp
= tstate
->interp
;
657 if (tstate
!= PyThreadState_GET())
658 Py_FatalError("Py_EndInterpreter: thread is not current");
659 if (tstate
->frame
!= NULL
)
660 Py_FatalError("Py_EndInterpreter: thread still has a frame");
661 if (tstate
!= interp
->tstate_head
|| tstate
->next
!= NULL
)
662 Py_FatalError("Py_EndInterpreter: not the last thread");
665 PyInterpreterState_Clear(interp
);
666 PyThreadState_Swap(NULL
);
667 PyInterpreterState_Delete(interp
);
670 static char *progname
= "python";
673 Py_SetProgramName(char *pn
)
680 Py_GetProgramName(void)
685 static char *default_home
= NULL
;
688 Py_SetPythonHome(char *home
)
694 Py_GetPythonHome(void)
696 char *home
= default_home
;
697 if (home
== NULL
&& !Py_IgnoreEnvironmentFlag
)
698 home
= Py_GETENV("PYTHONHOME");
702 /* Create __main__ module */
708 m
= PyImport_AddModule("__main__");
710 Py_FatalError("can't create __main__ module");
711 d
= PyModule_GetDict(m
);
712 if (PyDict_GetItemString(d
, "__builtins__") == NULL
) {
713 PyObject
*bimod
= PyImport_ImportModule("__builtin__");
715 PyDict_SetItemString(d
, "__builtins__", bimod
) != 0)
716 Py_FatalError("can't add __builtins__ to __main__");
721 /* Import the site module (not into __main__ though) */
727 m
= PyImport_ImportModule("site");
738 /* Parse input from a file and execute it */
741 PyRun_AnyFileExFlags(FILE *fp
, const char *filename
, int closeit
,
742 PyCompilerFlags
*flags
)
744 if (filename
== NULL
)
746 if (Py_FdIsInteractive(fp
, filename
)) {
747 int err
= PyRun_InteractiveLoopFlags(fp
, filename
, flags
);
753 return PyRun_SimpleFileExFlags(fp
, filename
, closeit
, flags
);
757 PyRun_InteractiveLoopFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
761 PyCompilerFlags local_flags
;
764 flags
= &local_flags
;
765 local_flags
.cf_flags
= 0;
767 v
= PySys_GetObject("ps1");
769 PySys_SetObject("ps1", v
= PyString_FromString(">>> "));
772 v
= PySys_GetObject("ps2");
774 PySys_SetObject("ps2", v
= PyString_FromString("... "));
778 ret
= PyRun_InteractiveOneFlags(fp
, filename
, flags
);
790 /* compute parser flags based on compiler flags */
791 #define PARSER_FLAGS(flags) \
792 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
793 PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0)
796 /* Keep an example of flags with future keyword support. */
797 #define PARSER_FLAGS(flags) \
798 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
799 PyPARSE_DONT_IMPLY_DEDENT : 0) \
800 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \
801 PyPARSE_PRINT_IS_FUNCTION : 0) \
802 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \
803 PyPARSE_UNICODE_LITERALS : 0) \
808 PyRun_InteractiveOneFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
810 PyObject
*m
, *d
, *v
, *w
;
813 char *ps1
= "", *ps2
= "";
816 v
= PySys_GetObject("ps1");
821 else if (PyString_Check(v
))
822 ps1
= PyString_AsString(v
);
824 w
= PySys_GetObject("ps2");
829 else if (PyString_Check(w
))
830 ps2
= PyString_AsString(w
);
832 arena
= PyArena_New();
838 mod
= PyParser_ASTFromFile(fp
, filename
,
839 Py_single_input
, ps1
, ps2
,
840 flags
, &errcode
, arena
);
845 if (errcode
== E_EOF
) {
852 m
= PyImport_AddModule("__main__");
857 d
= PyModule_GetDict(m
);
858 v
= run_mod(mod
, filename
, d
, d
, flags
, arena
);
870 /* Check whether a file maybe a pyc file: Look at the extension,
871 the file type, and, if we may close it, at the first few bytes. */
874 maybe_pyc_file(FILE *fp
, const char* filename
, const char* ext
, int closeit
)
876 if (strcmp(ext
, ".pyc") == 0 || strcmp(ext
, ".pyo") == 0)
879 /* Only look into the file if we are allowed to close it, since
880 it then should also be seekable. */
882 /* Read only two bytes of the magic. If the file was opened in
883 text mode, the bytes 3 and 4 of the magic (\r\n) might not
884 be read as they are on disk. */
885 unsigned int halfmagic
= PyImport_GetMagicNumber() & 0xFFFF;
886 unsigned char buf
[2];
887 /* Mess: In case of -x, the stream is NOT at its start now,
888 and ungetc() was used to push back the first newline,
889 which makes the current stream position formally undefined,
890 and a x-platform nightmare.
891 Unfortunately, we have no direct way to know whether -x
892 was specified. So we use a terrible hack: if the current
893 stream position is not 0, we assume -x was specified, and
894 give up. Bug 132850 on SourceForge spells out the
895 hopelessness of trying anything else (fseek and ftell
896 don't work predictably x-platform for text-mode files).
899 if (ftell(fp
) == 0) {
900 if (fread(buf
, 1, 2, fp
) == 2 &&
901 ((unsigned int)buf
[1]<<8 | buf
[0]) == halfmagic
)
911 PyRun_SimpleFileExFlags(FILE *fp
, const char *filename
, int closeit
,
912 PyCompilerFlags
*flags
)
916 int set_file_name
= 0, len
, ret
= -1;
918 m
= PyImport_AddModule("__main__");
922 d
= PyModule_GetDict(m
);
923 if (PyDict_GetItemString(d
, "__file__") == NULL
) {
924 PyObject
*f
= PyString_FromString(filename
);
927 if (PyDict_SetItemString(d
, "__file__", f
) < 0) {
934 len
= strlen(filename
);
935 ext
= filename
+ len
- (len
> 4 ? 4 : 0);
936 if (maybe_pyc_file(fp
, filename
, ext
, closeit
)) {
937 /* Try to run a pyc file. First, re-open in binary */
940 if ((fp
= fopen(filename
, "rb")) == NULL
) {
941 fprintf(stderr
, "python: Can't reopen .pyc file\n");
944 /* Turn on optimization if a .pyo file is given */
945 if (strcmp(ext
, ".pyo") == 0)
947 v
= run_pyc_file(fp
, filename
, d
, d
, flags
);
949 v
= PyRun_FileExFlags(fp
, filename
, Py_file_input
, d
, d
,
961 if (set_file_name
&& PyDict_DelItemString(d
, "__file__"))
968 PyRun_SimpleStringFlags(const char *command
, PyCompilerFlags
*flags
)
971 m
= PyImport_AddModule("__main__");
974 d
= PyModule_GetDict(m
);
975 v
= PyRun_StringFlags(command
, Py_file_input
, d
, d
, flags
);
987 parse_syntax_error(PyObject
*err
, PyObject
**message
, const char **filename
,
988 int *lineno
, int *offset
, const char **text
)
993 /* old style errors */
994 if (PyTuple_Check(err
))
995 return PyArg_ParseTuple(err
, "O(ziiz)", message
, filename
,
996 lineno
, offset
, text
);
1000 /* new style errors. `err' is an instance */
1001 *message
= PyObject_GetAttrString(err
, "msg");
1005 v
= PyObject_GetAttrString(err
, "filename");
1013 *filename
= PyString_AsString(v
);
1019 v
= PyObject_GetAttrString(err
, "lineno");
1022 hold
= PyInt_AsLong(v
);
1024 if (hold
< 0 && PyErr_Occurred())
1026 *lineno
= (int)hold
;
1028 v
= PyObject_GetAttrString(err
, "offset");
1035 hold
= PyInt_AsLong(v
);
1037 if (hold
< 0 && PyErr_Occurred())
1039 *offset
= (int)hold
;
1042 v
= PyObject_GetAttrString(err
, "text");
1050 *text
= PyString_AsString(v
);
1058 Py_XDECREF(*message
);
1069 print_error_text(PyObject
*f
, int offset
, const char *text
)
1073 if (offset
> 0 && offset
== strlen(text
) && text
[offset
- 1] == '\n')
1076 nl
= strchr(text
, '\n');
1077 if (nl
== NULL
|| nl
-text
>= offset
)
1079 offset
-= (int)(nl
+1-text
);
1082 while (*text
== ' ' || *text
== '\t') {
1087 PyFile_WriteString(" ", f
);
1088 PyFile_WriteString(text
, f
);
1089 if (*text
== '\0' || text
[strlen(text
)-1] != '\n')
1090 PyFile_WriteString("\n", f
);
1093 PyFile_WriteString(" ", f
);
1095 while (offset
> 0) {
1096 PyFile_WriteString(" ", f
);
1099 PyFile_WriteString("^\n", f
);
1103 handle_system_exit(void)
1105 PyObject
*exception
, *value
, *tb
;
1109 /* Don't exit if -i flag was given. This flag is set to 0
1110 * when entering interactive mode for inspecting. */
1113 PyErr_Fetch(&exception
, &value
, &tb
);
1117 if (value
== NULL
|| value
== Py_None
)
1119 if (PyExceptionInstance_Check(value
)) {
1120 /* The error code should be in the `code' attribute. */
1121 PyObject
*code
= PyObject_GetAttrString(value
, "code");
1125 if (value
== Py_None
)
1128 /* If we failed to dig out the 'code' attribute,
1129 just let the else clause below print the error. */
1131 if (PyInt_Check(value
))
1132 exitcode
= (int)PyInt_AsLong(value
);
1134 PyObject
*sys_stderr
= PySys_GetObject("stderr");
1135 if (sys_stderr
!= NULL
&& sys_stderr
!= Py_None
) {
1136 PyFile_WriteObject(value
, sys_stderr
, Py_PRINT_RAW
);
1138 PyObject_Print(value
, stderr
, Py_PRINT_RAW
);
1141 PySys_WriteStderr("\n");
1145 /* Restore and clear the exception info, in order to properly decref
1146 * the exception, value, and traceback. If we just exit instead,
1147 * these leak, which confuses PYTHONDUMPREFS output, and may prevent
1148 * some finalizers from running.
1150 PyErr_Restore(exception
, value
, tb
);
1157 PyErr_PrintEx(int set_sys_last_vars
)
1159 PyObject
*exception
, *v
, *tb
, *hook
;
1161 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1162 handle_system_exit();
1164 PyErr_Fetch(&exception
, &v
, &tb
);
1165 if (exception
== NULL
)
1167 PyErr_NormalizeException(&exception
, &v
, &tb
);
1168 if (exception
== NULL
)
1170 /* Now we know v != NULL too */
1171 if (set_sys_last_vars
) {
1172 PySys_SetObject("last_type", exception
);
1173 PySys_SetObject("last_value", v
);
1174 PySys_SetObject("last_traceback", tb
);
1176 hook
= PySys_GetObject("excepthook");
1177 if (hook
&& hook
!= Py_None
) {
1178 PyObject
*args
= PyTuple_Pack(3,
1179 exception
, v
, tb
? tb
: Py_None
);
1180 PyObject
*result
= PyEval_CallObject(hook
, args
);
1181 if (result
== NULL
) {
1182 PyObject
*exception2
, *v2
, *tb2
;
1183 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1184 handle_system_exit();
1186 PyErr_Fetch(&exception2
, &v2
, &tb2
);
1187 PyErr_NormalizeException(&exception2
, &v2
, &tb2
);
1188 /* It should not be possible for exception2 or v2
1189 to be NULL. However PyErr_Display() can't
1190 tolerate NULLs, so just be safe. */
1191 if (exception2
== NULL
) {
1192 exception2
= Py_None
;
1193 Py_INCREF(exception2
);
1202 PySys_WriteStderr("Error in sys.excepthook:\n");
1203 PyErr_Display(exception2
, v2
, tb2
);
1204 PySys_WriteStderr("\nOriginal exception was:\n");
1205 PyErr_Display(exception
, v
, tb
);
1206 Py_DECREF(exception2
);
1213 PySys_WriteStderr("sys.excepthook is missing\n");
1214 PyErr_Display(exception
, v
, tb
);
1216 Py_XDECREF(exception
);
1222 PyErr_Display(PyObject
*exception
, PyObject
*value
, PyObject
*tb
)
1225 PyObject
*f
= PySys_GetObject("stderr");
1227 if (f
== NULL
|| f
== Py_None
)
1228 fprintf(stderr
, "lost sys.stderr\n");
1233 if (tb
&& tb
!= Py_None
)
1234 err
= PyTraceBack_Print(tb
, f
);
1236 PyObject_HasAttrString(value
, "print_file_and_line"))
1239 const char *filename
, *text
;
1241 if (!parse_syntax_error(value
, &message
, &filename
,
1242 &lineno
, &offset
, &text
))
1246 PyFile_WriteString(" File \"", f
);
1247 if (filename
== NULL
)
1248 PyFile_WriteString("<string>", f
);
1250 PyFile_WriteString(filename
, f
);
1251 PyFile_WriteString("\", line ", f
);
1252 PyOS_snprintf(buf
, sizeof(buf
), "%d", lineno
);
1253 PyFile_WriteString(buf
, f
);
1254 PyFile_WriteString("\n", f
);
1256 print_error_text(f
, offset
, text
);
1259 /* Can't be bothered to check all those
1260 PyFile_WriteString() calls */
1261 if (PyErr_Occurred())
1266 /* Don't do anything else */
1268 else if (PyExceptionClass_Check(exception
)) {
1269 PyObject
* moduleName
;
1270 char* className
= PyExceptionClass_Name(exception
);
1271 if (className
!= NULL
) {
1272 char *dot
= strrchr(className
, '.');
1277 moduleName
= PyObject_GetAttrString(exception
, "__module__");
1278 if (moduleName
== NULL
)
1279 err
= PyFile_WriteString("<unknown>", f
);
1281 char* modstr
= PyString_AsString(moduleName
);
1282 if (modstr
&& strcmp(modstr
, "exceptions"))
1284 err
= PyFile_WriteString(modstr
, f
);
1285 err
+= PyFile_WriteString(".", f
);
1287 Py_DECREF(moduleName
);
1290 if (className
== NULL
)
1291 err
= PyFile_WriteString("<unknown>", f
);
1293 err
= PyFile_WriteString(className
, f
);
1297 err
= PyFile_WriteObject(exception
, f
, Py_PRINT_RAW
);
1298 if (err
== 0 && (value
!= Py_None
)) {
1299 PyObject
*s
= PyObject_Str(value
);
1300 /* only print colon if the str() of the
1301 object is not the empty string
1305 else if (!PyString_Check(s
) ||
1306 PyString_GET_SIZE(s
) != 0)
1307 err
= PyFile_WriteString(": ", f
);
1309 err
= PyFile_WriteObject(s
, f
, Py_PRINT_RAW
);
1312 /* try to write a newline in any case */
1313 err
+= PyFile_WriteString("\n", f
);
1316 /* If an error happened here, don't show it.
1317 XXX This is wrong, but too many callers rely on this behavior. */
1323 PyRun_StringFlags(const char *str
, int start
, PyObject
*globals
,
1324 PyObject
*locals
, PyCompilerFlags
*flags
)
1326 PyObject
*ret
= NULL
;
1328 PyArena
*arena
= PyArena_New();
1332 mod
= PyParser_ASTFromString(str
, "<string>", start
, flags
, arena
);
1334 ret
= run_mod(mod
, "<string>", globals
, locals
, flags
, arena
);
1335 PyArena_Free(arena
);
1340 PyRun_FileExFlags(FILE *fp
, const char *filename
, int start
, PyObject
*globals
,
1341 PyObject
*locals
, int closeit
, PyCompilerFlags
*flags
)
1345 PyArena
*arena
= PyArena_New();
1349 mod
= PyParser_ASTFromFile(fp
, filename
, start
, 0, 0,
1350 flags
, NULL
, arena
);
1354 PyArena_Free(arena
);
1357 ret
= run_mod(mod
, filename
, globals
, locals
, flags
, arena
);
1358 PyArena_Free(arena
);
1363 run_mod(mod_ty mod
, const char *filename
, PyObject
*globals
, PyObject
*locals
,
1364 PyCompilerFlags
*flags
, PyArena
*arena
)
1368 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1371 v
= PyEval_EvalCode(co
, globals
, locals
);
1377 run_pyc_file(FILE *fp
, const char *filename
, PyObject
*globals
,
1378 PyObject
*locals
, PyCompilerFlags
*flags
)
1383 long PyImport_GetMagicNumber(void);
1385 magic
= PyMarshal_ReadLongFromFile(fp
);
1386 if (magic
!= PyImport_GetMagicNumber()) {
1387 PyErr_SetString(PyExc_RuntimeError
,
1388 "Bad magic number in .pyc file");
1391 (void) PyMarshal_ReadLongFromFile(fp
);
1392 v
= PyMarshal_ReadLastObjectFromFile(fp
);
1394 if (v
== NULL
|| !PyCode_Check(v
)) {
1396 PyErr_SetString(PyExc_RuntimeError
,
1397 "Bad code object in .pyc file");
1400 co
= (PyCodeObject
*)v
;
1401 v
= PyEval_EvalCode(co
, globals
, locals
);
1403 flags
->cf_flags
|= (co
->co_flags
& PyCF_MASK
);
1409 Py_CompileStringFlags(const char *str
, const char *filename
, int start
,
1410 PyCompilerFlags
*flags
)
1414 PyArena
*arena
= PyArena_New();
1418 mod
= PyParser_ASTFromString(str
, filename
, start
, flags
, arena
);
1420 PyArena_Free(arena
);
1423 if (flags
&& (flags
->cf_flags
& PyCF_ONLY_AST
)) {
1424 PyObject
*result
= PyAST_mod2obj(mod
);
1425 PyArena_Free(arena
);
1428 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1429 PyArena_Free(arena
);
1430 return (PyObject
*)co
;
1434 Py_SymtableString(const char *str
, const char *filename
, int start
)
1436 struct symtable
*st
;
1438 PyCompilerFlags flags
;
1439 PyArena
*arena
= PyArena_New();
1445 mod
= PyParser_ASTFromString(str
, filename
, start
, &flags
, arena
);
1447 PyArena_Free(arena
);
1450 st
= PySymtable_Build(mod
, filename
, 0);
1451 PyArena_Free(arena
);
1455 /* Preferred access to parser is through AST. */
1457 PyParser_ASTFromString(const char *s
, const char *filename
, int start
,
1458 PyCompilerFlags
*flags
, PyArena
*arena
)
1461 PyCompilerFlags localflags
;
1463 int iflags
= PARSER_FLAGS(flags
);
1465 node
*n
= PyParser_ParseStringFlagsFilenameEx(s
, filename
,
1466 &_PyParser_Grammar
, start
, &err
,
1468 if (flags
== NULL
) {
1469 localflags
.cf_flags
= 0;
1470 flags
= &localflags
;
1473 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1474 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1485 PyParser_ASTFromFile(FILE *fp
, const char *filename
, int start
, char *ps1
,
1486 char *ps2
, PyCompilerFlags
*flags
, int *errcode
,
1490 PyCompilerFlags localflags
;
1492 int iflags
= PARSER_FLAGS(flags
);
1494 node
*n
= PyParser_ParseFileFlagsEx(fp
, filename
, &_PyParser_Grammar
,
1495 start
, ps1
, ps2
, &err
, &iflags
);
1496 if (flags
== NULL
) {
1497 localflags
.cf_flags
= 0;
1498 flags
= &localflags
;
1501 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1502 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1509 *errcode
= err
.error
;
1514 /* Simplified interface to parsefile -- return node or set exception */
1517 PyParser_SimpleParseFileFlags(FILE *fp
, const char *filename
, int start
, int flags
)
1520 node
*n
= PyParser_ParseFileFlags(fp
, filename
, &_PyParser_Grammar
,
1521 start
, NULL
, NULL
, &err
, flags
);
1528 /* Simplified interface to parsestring -- return node or set exception */
1531 PyParser_SimpleParseStringFlags(const char *str
, int start
, int flags
)
1534 node
*n
= PyParser_ParseStringFlags(str
, &_PyParser_Grammar
,
1535 start
, &err
, flags
);
1542 PyParser_SimpleParseStringFlagsFilename(const char *str
, const char *filename
,
1543 int start
, int flags
)
1546 node
*n
= PyParser_ParseStringFlagsFilename(str
, filename
,
1547 &_PyParser_Grammar
, start
, &err
, flags
);
1554 PyParser_SimpleParseStringFilename(const char *str
, const char *filename
, int start
)
1556 return PyParser_SimpleParseStringFlagsFilename(str
, filename
, start
, 0);
1559 /* May want to move a more generalized form of this to parsetok.c or
1560 even parser modules. */
1563 PyParser_SetError(perrdetail
*err
)
1568 /* Set the error appropriate to the given input error code (see errcode.h) */
1571 err_input(perrdetail
*err
)
1573 PyObject
*v
, *w
, *errtype
;
1576 errtype
= PyExc_SyntaxError
;
1577 switch (err
->error
) {
1581 errtype
= PyExc_IndentationError
;
1582 if (err
->expected
== INDENT
)
1583 msg
= "expected an indented block";
1584 else if (err
->token
== INDENT
)
1585 msg
= "unexpected indent";
1586 else if (err
->token
== DEDENT
)
1587 msg
= "unexpected unindent";
1589 errtype
= PyExc_SyntaxError
;
1590 msg
= "invalid syntax";
1594 msg
= "invalid token";
1597 msg
= "EOF while scanning triple-quoted string literal";
1600 msg
= "EOL while scanning string literal";
1603 if (!PyErr_Occurred())
1604 PyErr_SetNone(PyExc_KeyboardInterrupt
);
1610 msg
= "unexpected EOF while parsing";
1613 errtype
= PyExc_TabError
;
1614 msg
= "inconsistent use of tabs and spaces in indentation";
1617 msg
= "expression too long";
1620 errtype
= PyExc_IndentationError
;
1621 msg
= "unindent does not match any outer indentation level";
1624 errtype
= PyExc_IndentationError
;
1625 msg
= "too many levels of indentation";
1628 PyObject
*type
, *value
, *tb
;
1629 PyErr_Fetch(&type
, &value
, &tb
);
1630 if (value
!= NULL
) {
1631 u
= PyObject_Str(value
);
1633 msg
= PyString_AsString(u
);
1637 msg
= "unknown decode error";
1644 msg
= "unexpected character after line continuation character";
1647 fprintf(stderr
, "error=%d\n", err
->error
);
1648 msg
= "unknown parsing error";
1651 v
= Py_BuildValue("(ziiz)", err
->filename
,
1652 err
->lineno
, err
->offset
, err
->text
);
1655 w
= Py_BuildValue("(sO)", msg
, v
);
1658 PyErr_SetObject(errtype
, w
);
1661 if (err
->text
!= NULL
) {
1662 PyObject_FREE(err
->text
);
1667 /* Print fatal error message and abort */
1670 Py_FatalError(const char *msg
)
1672 fprintf(stderr
, "Fatal Python error: %s\n", msg
);
1673 fflush(stderr
); /* it helps in Windows debug build */
1677 size_t len
= strlen(msg
);
1681 /* Convert the message to wchar_t. This uses a simple one-to-one
1682 conversion, assuming that the this error message actually uses ASCII
1683 only. If this ceases to be true, we will have to convert. */
1684 buffer
= alloca( (len
+1) * (sizeof *buffer
));
1685 for( i
=0; i
<=len
; ++i
)
1687 OutputDebugStringW(L
"Fatal Python error: ");
1688 OutputDebugStringW(buffer
);
1689 OutputDebugStringW(L
"\n");
1694 #endif /* MS_WINDOWS */
1698 /* Clean up and exit */
1701 #include "pythread.h"
1704 /* Wait until threading._shutdown completes, provided
1705 the threading module was imported in the first place.
1706 The shutdown routine will wait until all non-daemon
1707 "threading" threads have completed. */
1709 wait_for_thread_shutdown(void)
1713 PyThreadState
*tstate
= PyThreadState_GET();
1714 PyObject
*threading
= PyMapping_GetItemString(tstate
->interp
->modules
,
1716 if (threading
== NULL
) {
1717 /* threading not imported */
1721 result
= PyObject_CallMethod(threading
, "_shutdown", "");
1723 PyErr_WriteUnraisable(threading
);
1726 Py_DECREF(threading
);
1730 #define NEXITFUNCS 32
1731 static void (*exitfuncs
[NEXITFUNCS
])(void);
1732 static int nexitfuncs
= 0;
1734 int Py_AtExit(void (*func
)(void))
1736 if (nexitfuncs
>= NEXITFUNCS
)
1738 exitfuncs
[nexitfuncs
++] = func
;
1743 call_sys_exitfunc(void)
1745 PyObject
*exitfunc
= PySys_GetObject("exitfunc");
1749 Py_INCREF(exitfunc
);
1750 PySys_SetObject("exitfunc", (PyObject
*)NULL
);
1751 res
= PyEval_CallObject(exitfunc
, (PyObject
*)NULL
);
1753 if (!PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1754 PySys_WriteStderr("Error in sys.exitfunc:\n");
1758 Py_DECREF(exitfunc
);
1766 call_ll_exitfuncs(void)
1768 while (nexitfuncs
> 0)
1769 (*exitfuncs
[--nexitfuncs
])();
1787 PyOS_setsig(SIGPIPE
, SIG_IGN
);
1790 PyOS_setsig(SIGXFZ
, SIG_IGN
);
1793 PyOS_setsig(SIGXFSZ
, SIG_IGN
);
1795 PyOS_InitInterrupts(); /* May imply initsignal() */
1800 * The file descriptor fd is considered ``interactive'' if either
1801 * a) isatty(fd) is TRUE, or
1802 * b) the -i flag was given, and the filename associated with
1803 * the descriptor is NULL or "<stdin>" or "???".
1806 Py_FdIsInteractive(FILE *fp
, const char *filename
)
1808 if (isatty((int)fileno(fp
)))
1810 if (!Py_InteractiveFlag
)
1812 return (filename
== NULL
) ||
1813 (strcmp(filename
, "<stdin>") == 0) ||
1814 (strcmp(filename
, "???") == 0);
1818 #if defined(USE_STACKCHECK)
1819 #if defined(WIN32) && defined(_MSC_VER)
1821 /* Stack checking for Microsoft C */
1827 * Return non-zero when we run out of memory on the stack; zero otherwise.
1830 PyOS_CheckStack(void)
1833 /* alloca throws a stack overflow exception if there's
1834 not enough space left on the stack */
1835 alloca(PYOS_STACK_MARGIN
* sizeof(void*));
1837 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW
?
1838 EXCEPTION_EXECUTE_HANDLER
:
1839 EXCEPTION_CONTINUE_SEARCH
) {
1840 int errcode
= _resetstkoflw();
1843 Py_FatalError("Could not reset the stack!");
1849 #endif /* WIN32 && _MSC_VER */
1851 /* Alternate implementations can be added here... */
1853 #endif /* USE_STACKCHECK */
1856 /* Wrappers around sigaction() or signal(). */
1859 PyOS_getsig(int sig
)
1861 #ifdef HAVE_SIGACTION
1862 struct sigaction context
;
1863 if (sigaction(sig
, NULL
, &context
) == -1)
1865 return context
.sa_handler
;
1867 PyOS_sighandler_t handler
;
1868 /* Special signal handling for the secure CRT in Visual Studio 2005 */
1869 #if defined(_MSC_VER) && _MSC_VER >= 1400
1871 /* Only these signals are valid */
1880 /* Don't call signal() with other values or it will assert */
1884 #endif /* _MSC_VER && _MSC_VER >= 1400 */
1885 handler
= signal(sig
, SIG_IGN
);
1886 if (handler
!= SIG_ERR
)
1887 signal(sig
, handler
);
1893 PyOS_setsig(int sig
, PyOS_sighandler_t handler
)
1895 #ifdef HAVE_SIGACTION
1896 /* Some code in Modules/signalmodule.c depends on sigaction() being
1897 * used here if HAVE_SIGACTION is defined. Fix that if this code
1898 * changes to invalidate that assumption.
1900 struct sigaction context
, ocontext
;
1901 context
.sa_handler
= handler
;
1902 sigemptyset(&context
.sa_mask
);
1903 context
.sa_flags
= 0;
1904 if (sigaction(sig
, &context
, &ocontext
) == -1)
1906 return ocontext
.sa_handler
;
1908 PyOS_sighandler_t oldhandler
;
1909 oldhandler
= signal(sig
, handler
);
1910 #ifdef HAVE_SIGINTERRUPT
1911 siginterrupt(sig
, 1);
1917 /* Deprecated C API functions still provided for binary compatiblity */
1919 #undef PyParser_SimpleParseFile
1921 PyParser_SimpleParseFile(FILE *fp
, const char *filename
, int start
)
1923 return PyParser_SimpleParseFileFlags(fp
, filename
, start
, 0);
1926 #undef PyParser_SimpleParseString
1928 PyParser_SimpleParseString(const char *str
, int start
)
1930 return PyParser_SimpleParseStringFlags(str
, start
, 0);
1933 #undef PyRun_AnyFile
1935 PyRun_AnyFile(FILE *fp
, const char *name
)
1937 return PyRun_AnyFileExFlags(fp
, name
, 0, NULL
);
1940 #undef PyRun_AnyFileEx
1942 PyRun_AnyFileEx(FILE *fp
, const char *name
, int closeit
)
1944 return PyRun_AnyFileExFlags(fp
, name
, closeit
, NULL
);
1947 #undef PyRun_AnyFileFlags
1949 PyRun_AnyFileFlags(FILE *fp
, const char *name
, PyCompilerFlags
*flags
)
1951 return PyRun_AnyFileExFlags(fp
, name
, 0, flags
);
1955 PyAPI_FUNC(PyObject
*)
1956 PyRun_File(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
)
1958 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, NULL
);
1962 PyAPI_FUNC(PyObject
*)
1963 PyRun_FileEx(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
, int c
)
1965 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, c
, NULL
);
1968 #undef PyRun_FileFlags
1969 PyAPI_FUNC(PyObject
*)
1970 PyRun_FileFlags(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
,
1971 PyCompilerFlags
*flags
)
1973 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, flags
);
1976 #undef PyRun_SimpleFile
1978 PyRun_SimpleFile(FILE *f
, const char *p
)
1980 return PyRun_SimpleFileExFlags(f
, p
, 0, NULL
);
1983 #undef PyRun_SimpleFileEx
1985 PyRun_SimpleFileEx(FILE *f
, const char *p
, int c
)
1987 return PyRun_SimpleFileExFlags(f
, p
, c
, NULL
);
1992 PyAPI_FUNC(PyObject
*)
1993 PyRun_String(const char *str
, int s
, PyObject
*g
, PyObject
*l
)
1995 return PyRun_StringFlags(str
, s
, g
, l
, NULL
);
1998 #undef PyRun_SimpleString
2000 PyRun_SimpleString(const char *s
)
2002 return PyRun_SimpleStringFlags(s
, NULL
);
2005 #undef Py_CompileString
2006 PyAPI_FUNC(PyObject
*)
2007 Py_CompileString(const char *str
, const char *p
, int s
)
2009 return Py_CompileStringFlags(str
, p
, s
, NULL
);
2012 #undef PyRun_InteractiveOne
2014 PyRun_InteractiveOne(FILE *f
, const char *p
)
2016 return PyRun_InteractiveOneFlags(f
, p
, NULL
);
2019 #undef PyRun_InteractiveLoop
2021 PyRun_InteractiveLoop(FILE *f
, const char *p
)
2023 return PyRun_InteractiveLoopFlags(f
, p
, NULL
);