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 initsite(); /* Module site */
254 /* auto-thread-state API, if available */
256 _PyGILState_Init(interp
, tstate
);
257 #endif /* WITH_THREAD */
259 if ((p
= Py_GETENV("PYTHONIOENCODING")) && *p
!= '\0') {
260 p
= icodeset
= codeset
= strdup(p
);
262 errors
= strchr(p
, ':');
270 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
271 /* On Unix, set the file system encoding according to the
272 user's preference, if the CODESET names a well-known
273 Python codec, and Py_FileSystemDefaultEncoding isn't
274 initialized by other means. Also set the encoding of
275 stdin and stdout if these are terminals, unless overridden. */
277 if (!overridden
|| !Py_FileSystemDefaultEncoding
) {
278 saved_locale
= strdup(setlocale(LC_CTYPE
, NULL
));
279 setlocale(LC_CTYPE
, "");
280 loc_codeset
= nl_langinfo(CODESET
);
281 if (loc_codeset
&& *loc_codeset
) {
282 PyObject
*enc
= PyCodec_Encoder(loc_codeset
);
284 loc_codeset
= strdup(loc_codeset
);
292 setlocale(LC_CTYPE
, saved_locale
);
296 codeset
= icodeset
= loc_codeset
;
300 /* Initialize Py_FileSystemDefaultEncoding from
301 locale even if PYTHONIOENCODING is set. */
302 if (!Py_FileSystemDefaultEncoding
) {
303 Py_FileSystemDefaultEncoding
= loc_codeset
;
314 sprintf(ibuf
, "cp%d", GetConsoleCP());
315 sprintf(buf
, "cp%d", GetConsoleOutputCP());
320 sys_stream
= PySys_GetObject("stdin");
321 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
325 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
326 PyFile_Check(sys_stream
)) {
327 if (!PyFile_SetEncodingAndErrors(sys_stream
, icodeset
, errors
))
328 Py_FatalError("Cannot set codeset of stdin");
330 Py_XDECREF(sys_isatty
);
332 sys_stream
= PySys_GetObject("stdout");
333 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
337 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
338 PyFile_Check(sys_stream
)) {
339 if (!PyFile_SetEncodingAndErrors(sys_stream
, codeset
, errors
))
340 Py_FatalError("Cannot set codeset of stdout");
342 Py_XDECREF(sys_isatty
);
344 sys_stream
= PySys_GetObject("stderr");
345 sys_isatty
= PyObject_CallMethod(sys_stream
, "isatty", "");
349 (sys_isatty
&& PyObject_IsTrue(sys_isatty
))) &&
350 PyFile_Check(sys_stream
)) {
351 if (!PyFile_SetEncodingAndErrors(sys_stream
, codeset
, errors
))
352 Py_FatalError("Cannot set codeset of stderr");
354 Py_XDECREF(sys_isatty
);
369 extern void dump_counts(FILE*);
372 /* Undo the effect of Py_Initialize().
374 Beware: if multiple interpreter and/or thread states exist, these
375 are not wiped out; only the current thread and interpreter state
376 are deleted. But since everything else is deleted, those other
377 interpreter and thread states should no longer be used.
379 (XXX We should do better, e.g. wipe out all interpreters and
389 PyInterpreterState
*interp
;
390 PyThreadState
*tstate
;
395 wait_for_thread_shutdown();
397 /* The interpreter is still entirely intact at this point, and the
398 * exit funcs may be relying on that. In particular, if some thread
399 * or exit func is still waiting to do an import, the import machinery
400 * expects Py_IsInitialized() to return true. So don't say the
401 * interpreter is uninitialized until after the exit funcs have run.
402 * Note that Threading.py uses an exit func to do a join on all the
403 * threads created thru it, so this also protects pending imports in
404 * the threads created via Threading.
409 /* Get current thread state and interpreter pointer */
410 tstate
= PyThreadState_GET();
411 interp
= tstate
->interp
;
413 /* Disable signal handling */
414 PyOS_FiniInterrupts();
416 /* Clear type lookup cache */
419 /* Collect garbage. This may call finalizers; it's nice to call these
420 * before all modules are destroyed.
421 * XXX If a __del__ or weakref callback is triggered here, and tries to
422 * XXX import a module, bad things can happen, because Python no
423 * XXX longer believes it's initialized.
424 * XXX Fatal Python error: Interpreter not initialized (version mismatch?)
425 * XXX is easy to provoke that way. I've also seen, e.g.,
426 * XXX Exception exceptions.ImportError: 'No module named sha'
427 * XXX in <function callback at 0x008F5718> ignored
428 * XXX but I'm unclear on exactly how that one happens. In any case,
429 * XXX I haven't seen a real-life report of either of these.
433 /* With COUNT_ALLOCS, it helps to run GC multiple times:
434 each collection might release some types from the type
435 list, so they become garbage. */
436 while (PyGC_Collect() > 0)
440 /* Destroy all modules */
443 /* Collect final garbage. This disposes of cycles created by
444 * new-style class definitions, for example.
445 * XXX This is disabled because it caused too many problems. If
446 * XXX a __del__ or weakref callback triggers here, Python code has
447 * XXX a hard time running, because even the sys module has been
448 * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
449 * XXX One symptom is a sequence of information-free messages
450 * XXX coming from threads (if a __del__ or callback is invoked,
451 * XXX other threads can execute too, and any exception they encounter
452 * XXX triggers a comedy of errors as subsystem after subsystem
453 * XXX fails to find what it *expects* to find in sys to help report
454 * XXX the exception and consequent unexpected failures). I've also
455 * XXX seen segfaults then, after adding print statements to the
456 * XXX Python code getting called.
462 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
465 /* Debugging stuff */
473 /* Display all objects still alive -- this can invoke arbitrary
474 * __repr__ overrides, so requires a mostly-intact interpreter.
475 * Alas, a lot of stuff may still be alive now that will be cleaned
478 if (Py_GETENV("PYTHONDUMPREFS"))
479 _Py_PrintReferences(stderr
);
480 #endif /* Py_TRACE_REFS */
482 /* Clear interpreter state */
483 PyInterpreterState_Clear(interp
);
485 /* Now we decref the exception classes. After this point nothing
486 can raise an exception. That's okay, because each Fini() method
487 below has been checked to make sure no exceptions are ever
493 /* Cleanup auto-thread-state */
496 #endif /* WITH_THREAD */
498 /* Delete current thread */
499 PyThreadState_Swap(NULL
);
500 PyInterpreterState_Delete(interp
);
502 /* Sundry finalizers */
515 #ifdef Py_USING_UNICODE
516 /* Cleanup Unicode implementation */
520 /* XXX Still allocated:
521 - various static ad-hoc pointers to interned strings
522 - int and float free list blocks
523 - whatever various modules and libraries allocate
526 PyGrammar_RemoveAccelerators(&_PyParser_Grammar
);
529 /* Display addresses (& refcnts) of all objects still alive.
530 * An address can be used to find the repr of the object, printed
531 * above by _Py_PrintReferences.
533 if (Py_GETENV("PYTHONDUMPREFS"))
534 _Py_PrintReferenceAddresses(stderr
);
535 #endif /* Py_TRACE_REFS */
536 #ifdef PYMALLOC_DEBUG
537 if (Py_GETENV("PYTHONMALLOCSTATS"))
538 _PyObject_DebugMallocStats();
544 /* Create and initialize a new interpreter and thread, and return the
545 new thread. This requires that Py_Initialize() has been called
548 Unsuccessful initialization yields a NULL pointer. Note that *no*
549 exception information is available even in this case -- the
550 exception information is held in the thread, and there is no
558 Py_NewInterpreter(void)
560 PyInterpreterState
*interp
;
561 PyThreadState
*tstate
, *save_tstate
;
562 PyObject
*bimod
, *sysmod
;
565 Py_FatalError("Py_NewInterpreter: call Py_Initialize first");
567 interp
= PyInterpreterState_New();
571 tstate
= PyThreadState_New(interp
);
572 if (tstate
== NULL
) {
573 PyInterpreterState_Delete(interp
);
577 save_tstate
= PyThreadState_Swap(tstate
);
579 /* XXX The following is lax in error checking */
581 interp
->modules
= PyDict_New();
582 interp
->modules_reloading
= PyDict_New();
584 bimod
= _PyImport_FindExtension("__builtin__", "__builtin__");
586 interp
->builtins
= PyModule_GetDict(bimod
);
587 if (interp
->builtins
== NULL
)
589 Py_INCREF(interp
->builtins
);
591 sysmod
= _PyImport_FindExtension("sys", "sys");
592 if (bimod
!= NULL
&& sysmod
!= NULL
) {
593 interp
->sysdict
= PyModule_GetDict(sysmod
);
594 if (interp
->sysdict
== NULL
)
596 Py_INCREF(interp
->sysdict
);
597 PySys_SetPath(Py_GetPath());
598 PyDict_SetItemString(interp
->sysdict
, "modules",
600 _PyImportHooks_Init();
606 if (!PyErr_Occurred())
610 /* Oops, it didn't work. Undo it all. */
613 PyThreadState_Clear(tstate
);
614 PyThreadState_Swap(save_tstate
);
615 PyThreadState_Delete(tstate
);
616 PyInterpreterState_Delete(interp
);
621 /* Delete an interpreter and its last thread. This requires that the
622 given thread state is current, that the thread has no remaining
623 frames, and that it is its interpreter's only remaining thread.
624 It is a fatal error to violate these constraints.
626 (Py_Finalize() doesn't have these constraints -- it zaps
627 everything, regardless.)
634 Py_EndInterpreter(PyThreadState
*tstate
)
636 PyInterpreterState
*interp
= tstate
->interp
;
638 if (tstate
!= PyThreadState_GET())
639 Py_FatalError("Py_EndInterpreter: thread is not current");
640 if (tstate
->frame
!= NULL
)
641 Py_FatalError("Py_EndInterpreter: thread still has a frame");
642 if (tstate
!= interp
->tstate_head
|| tstate
->next
!= NULL
)
643 Py_FatalError("Py_EndInterpreter: not the last thread");
646 PyInterpreterState_Clear(interp
);
647 PyThreadState_Swap(NULL
);
648 PyInterpreterState_Delete(interp
);
651 static char *progname
= "python";
654 Py_SetProgramName(char *pn
)
661 Py_GetProgramName(void)
666 static char *default_home
= NULL
;
669 Py_SetPythonHome(char *home
)
675 Py_GetPythonHome(void)
677 char *home
= default_home
;
678 if (home
== NULL
&& !Py_IgnoreEnvironmentFlag
)
679 home
= Py_GETENV("PYTHONHOME");
683 /* Create __main__ module */
689 m
= PyImport_AddModule("__main__");
691 Py_FatalError("can't create __main__ module");
692 d
= PyModule_GetDict(m
);
693 if (PyDict_GetItemString(d
, "__builtins__") == NULL
) {
694 PyObject
*bimod
= PyImport_ImportModule("__builtin__");
696 PyDict_SetItemString(d
, "__builtins__", bimod
) != 0)
697 Py_FatalError("can't add __builtins__ to __main__");
702 /* Import the site module (not into __main__ though) */
708 m
= PyImport_ImportModule("site");
710 f
= PySys_GetObject("stderr");
711 if (Py_VerboseFlag
) {
713 "'import site' failed; traceback:\n", f
);
718 "'import site' failed; use -v for traceback\n", f
);
727 /* Parse input from a file and execute it */
730 PyRun_AnyFileExFlags(FILE *fp
, const char *filename
, int closeit
,
731 PyCompilerFlags
*flags
)
733 if (filename
== NULL
)
735 if (Py_FdIsInteractive(fp
, filename
)) {
736 int err
= PyRun_InteractiveLoopFlags(fp
, filename
, flags
);
742 return PyRun_SimpleFileExFlags(fp
, filename
, closeit
, flags
);
746 PyRun_InteractiveLoopFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
750 PyCompilerFlags local_flags
;
753 flags
= &local_flags
;
754 local_flags
.cf_flags
= 0;
756 v
= PySys_GetObject("ps1");
758 PySys_SetObject("ps1", v
= PyString_FromString(">>> "));
761 v
= PySys_GetObject("ps2");
763 PySys_SetObject("ps2", v
= PyString_FromString("... "));
767 ret
= PyRun_InteractiveOneFlags(fp
, filename
, flags
);
779 /* compute parser flags based on compiler flags */
780 #define PARSER_FLAGS(flags) \
781 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
782 PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0)
785 /* Keep an example of flags with future keyword support. */
786 #define PARSER_FLAGS(flags) \
787 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
788 PyPARSE_DONT_IMPLY_DEDENT : 0) \
789 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \
790 PyPARSE_PRINT_IS_FUNCTION : 0) \
791 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \
792 PyPARSE_UNICODE_LITERALS : 0) \
797 PyRun_InteractiveOneFlags(FILE *fp
, const char *filename
, PyCompilerFlags
*flags
)
799 PyObject
*m
, *d
, *v
, *w
;
802 char *ps1
= "", *ps2
= "";
805 v
= PySys_GetObject("ps1");
810 else if (PyString_Check(v
))
811 ps1
= PyString_AsString(v
);
813 w
= PySys_GetObject("ps2");
818 else if (PyString_Check(w
))
819 ps2
= PyString_AsString(w
);
821 arena
= PyArena_New();
827 mod
= PyParser_ASTFromFile(fp
, filename
,
828 Py_single_input
, ps1
, ps2
,
829 flags
, &errcode
, arena
);
834 if (errcode
== E_EOF
) {
841 m
= PyImport_AddModule("__main__");
846 d
= PyModule_GetDict(m
);
847 v
= run_mod(mod
, filename
, d
, d
, flags
, arena
);
859 /* Check whether a file maybe a pyc file: Look at the extension,
860 the file type, and, if we may close it, at the first few bytes. */
863 maybe_pyc_file(FILE *fp
, const char* filename
, const char* ext
, int closeit
)
865 if (strcmp(ext
, ".pyc") == 0 || strcmp(ext
, ".pyo") == 0)
868 /* Only look into the file if we are allowed to close it, since
869 it then should also be seekable. */
871 /* Read only two bytes of the magic. If the file was opened in
872 text mode, the bytes 3 and 4 of the magic (\r\n) might not
873 be read as they are on disk. */
874 unsigned int halfmagic
= PyImport_GetMagicNumber() & 0xFFFF;
875 unsigned char buf
[2];
876 /* Mess: In case of -x, the stream is NOT at its start now,
877 and ungetc() was used to push back the first newline,
878 which makes the current stream position formally undefined,
879 and a x-platform nightmare.
880 Unfortunately, we have no direct way to know whether -x
881 was specified. So we use a terrible hack: if the current
882 stream position is not 0, we assume -x was specified, and
883 give up. Bug 132850 on SourceForge spells out the
884 hopelessness of trying anything else (fseek and ftell
885 don't work predictably x-platform for text-mode files).
888 if (ftell(fp
) == 0) {
889 if (fread(buf
, 1, 2, fp
) == 2 &&
890 ((unsigned int)buf
[1]<<8 | buf
[0]) == halfmagic
)
900 PyRun_SimpleFileExFlags(FILE *fp
, const char *filename
, int closeit
,
901 PyCompilerFlags
*flags
)
905 int set_file_name
= 0, ret
, len
;
907 m
= PyImport_AddModule("__main__");
910 d
= PyModule_GetDict(m
);
911 if (PyDict_GetItemString(d
, "__file__") == NULL
) {
912 PyObject
*f
= PyString_FromString(filename
);
915 if (PyDict_SetItemString(d
, "__file__", f
) < 0) {
922 len
= strlen(filename
);
923 ext
= filename
+ len
- (len
> 4 ? 4 : 0);
924 if (maybe_pyc_file(fp
, filename
, ext
, closeit
)) {
925 /* Try to run a pyc file. First, re-open in binary */
928 if ((fp
= fopen(filename
, "rb")) == NULL
) {
929 fprintf(stderr
, "python: Can't reopen .pyc file\n");
933 /* Turn on optimization if a .pyo file is given */
934 if (strcmp(ext
, ".pyo") == 0)
936 v
= run_pyc_file(fp
, filename
, d
, d
, flags
);
938 v
= PyRun_FileExFlags(fp
, filename
, Py_file_input
, d
, d
,
951 if (set_file_name
&& PyDict_DelItemString(d
, "__file__"))
957 PyRun_SimpleStringFlags(const char *command
, PyCompilerFlags
*flags
)
960 m
= PyImport_AddModule("__main__");
963 d
= PyModule_GetDict(m
);
964 v
= PyRun_StringFlags(command
, Py_file_input
, d
, d
, flags
);
976 parse_syntax_error(PyObject
*err
, PyObject
**message
, const char **filename
,
977 int *lineno
, int *offset
, const char **text
)
982 /* old style errors */
983 if (PyTuple_Check(err
))
984 return PyArg_ParseTuple(err
, "O(ziiz)", message
, filename
,
985 lineno
, offset
, text
);
987 /* new style errors. `err' is an instance */
989 if (! (v
= PyObject_GetAttrString(err
, "msg")))
993 if (!(v
= PyObject_GetAttrString(err
, "filename")))
997 else if (! (*filename
= PyString_AsString(v
)))
1001 if (!(v
= PyObject_GetAttrString(err
, "lineno")))
1003 hold
= PyInt_AsLong(v
);
1006 if (hold
< 0 && PyErr_Occurred())
1008 *lineno
= (int)hold
;
1010 if (!(v
= PyObject_GetAttrString(err
, "offset")))
1017 hold
= PyInt_AsLong(v
);
1020 if (hold
< 0 && PyErr_Occurred())
1022 *offset
= (int)hold
;
1025 if (!(v
= PyObject_GetAttrString(err
, "text")))
1029 else if (! (*text
= PyString_AsString(v
)))
1046 print_error_text(PyObject
*f
, int offset
, const char *text
)
1050 if (offset
> 0 && offset
== (int)strlen(text
))
1053 nl
= strchr(text
, '\n');
1054 if (nl
== NULL
|| nl
-text
>= offset
)
1056 offset
-= (int)(nl
+1-text
);
1059 while (*text
== ' ' || *text
== '\t') {
1064 PyFile_WriteString(" ", f
);
1065 PyFile_WriteString(text
, f
);
1066 if (*text
== '\0' || text
[strlen(text
)-1] != '\n')
1067 PyFile_WriteString("\n", f
);
1070 PyFile_WriteString(" ", f
);
1072 while (offset
> 0) {
1073 PyFile_WriteString(" ", f
);
1076 PyFile_WriteString("^\n", f
);
1080 handle_system_exit(void)
1082 PyObject
*exception
, *value
, *tb
;
1086 /* Don't exit if -i flag was given. This flag is set to 0
1087 * when entering interactive mode for inspecting. */
1090 PyErr_Fetch(&exception
, &value
, &tb
);
1094 if (value
== NULL
|| value
== Py_None
)
1096 if (PyExceptionInstance_Check(value
)) {
1097 /* The error code should be in the `code' attribute. */
1098 PyObject
*code
= PyObject_GetAttrString(value
, "code");
1102 if (value
== Py_None
)
1105 /* If we failed to dig out the 'code' attribute,
1106 just let the else clause below print the error. */
1108 if (PyInt_Check(value
))
1109 exitcode
= (int)PyInt_AsLong(value
);
1111 PyObject_Print(value
, stderr
, Py_PRINT_RAW
);
1112 PySys_WriteStderr("\n");
1116 /* Restore and clear the exception info, in order to properly decref
1117 * the exception, value, and traceback. If we just exit instead,
1118 * these leak, which confuses PYTHONDUMPREFS output, and may prevent
1119 * some finalizers from running.
1121 PyErr_Restore(exception
, value
, tb
);
1128 PyErr_PrintEx(int set_sys_last_vars
)
1130 PyObject
*exception
, *v
, *tb
, *hook
;
1132 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1133 handle_system_exit();
1135 PyErr_Fetch(&exception
, &v
, &tb
);
1136 if (exception
== NULL
)
1138 PyErr_NormalizeException(&exception
, &v
, &tb
);
1139 if (exception
== NULL
)
1141 /* Now we know v != NULL too */
1142 if (set_sys_last_vars
) {
1143 PySys_SetObject("last_type", exception
);
1144 PySys_SetObject("last_value", v
);
1145 PySys_SetObject("last_traceback", tb
);
1147 hook
= PySys_GetObject("excepthook");
1149 PyObject
*args
= PyTuple_Pack(3,
1150 exception
, v
, tb
? tb
: Py_None
);
1151 PyObject
*result
= PyEval_CallObject(hook
, args
);
1152 if (result
== NULL
) {
1153 PyObject
*exception2
, *v2
, *tb2
;
1154 if (PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1155 handle_system_exit();
1157 PyErr_Fetch(&exception2
, &v2
, &tb2
);
1158 PyErr_NormalizeException(&exception2
, &v2
, &tb2
);
1159 /* It should not be possible for exception2 or v2
1160 to be NULL. However PyErr_Display() can't
1161 tolerate NULLs, so just be safe. */
1162 if (exception2
== NULL
) {
1163 exception2
= Py_None
;
1164 Py_INCREF(exception2
);
1173 PySys_WriteStderr("Error in sys.excepthook:\n");
1174 PyErr_Display(exception2
, v2
, tb2
);
1175 PySys_WriteStderr("\nOriginal exception was:\n");
1176 PyErr_Display(exception
, v
, tb
);
1177 Py_DECREF(exception2
);
1184 PySys_WriteStderr("sys.excepthook is missing\n");
1185 PyErr_Display(exception
, v
, tb
);
1187 Py_XDECREF(exception
);
1193 PyErr_Display(PyObject
*exception
, PyObject
*value
, PyObject
*tb
)
1196 PyObject
*f
= PySys_GetObject("stderr");
1199 fprintf(stderr
, "lost sys.stderr\n");
1204 if (tb
&& tb
!= Py_None
)
1205 err
= PyTraceBack_Print(tb
, f
);
1207 PyObject_HasAttrString(value
, "print_file_and_line"))
1210 const char *filename
, *text
;
1212 if (!parse_syntax_error(value
, &message
, &filename
,
1213 &lineno
, &offset
, &text
))
1217 PyFile_WriteString(" File \"", f
);
1218 if (filename
== NULL
)
1219 PyFile_WriteString("<string>", f
);
1221 PyFile_WriteString(filename
, f
);
1222 PyFile_WriteString("\", line ", f
);
1223 PyOS_snprintf(buf
, sizeof(buf
), "%d", lineno
);
1224 PyFile_WriteString(buf
, f
);
1225 PyFile_WriteString("\n", f
);
1227 print_error_text(f
, offset
, text
);
1230 /* Can't be bothered to check all those
1231 PyFile_WriteString() calls */
1232 if (PyErr_Occurred())
1237 /* Don't do anything else */
1239 else if (PyExceptionClass_Check(exception
)) {
1240 PyObject
* moduleName
;
1241 char* className
= PyExceptionClass_Name(exception
);
1242 if (className
!= NULL
) {
1243 char *dot
= strrchr(className
, '.');
1248 moduleName
= PyObject_GetAttrString(exception
, "__module__");
1249 if (moduleName
== NULL
)
1250 err
= PyFile_WriteString("<unknown>", f
);
1252 char* modstr
= PyString_AsString(moduleName
);
1253 if (modstr
&& strcmp(modstr
, "exceptions"))
1255 err
= PyFile_WriteString(modstr
, f
);
1256 err
+= PyFile_WriteString(".", f
);
1258 Py_DECREF(moduleName
);
1261 if (className
== NULL
)
1262 err
= PyFile_WriteString("<unknown>", f
);
1264 err
= PyFile_WriteString(className
, f
);
1268 err
= PyFile_WriteObject(exception
, f
, Py_PRINT_RAW
);
1269 if (err
== 0 && (value
!= Py_None
)) {
1270 PyObject
*s
= PyObject_Str(value
);
1271 /* only print colon if the str() of the
1272 object is not the empty string
1276 else if (!PyString_Check(s
) ||
1277 PyString_GET_SIZE(s
) != 0)
1278 err
= PyFile_WriteString(": ", f
);
1280 err
= PyFile_WriteObject(s
, f
, Py_PRINT_RAW
);
1283 /* try to write a newline in any case */
1284 err
+= PyFile_WriteString("\n", f
);
1287 /* If an error happened here, don't show it.
1288 XXX This is wrong, but too many callers rely on this behavior. */
1294 PyRun_StringFlags(const char *str
, int start
, PyObject
*globals
,
1295 PyObject
*locals
, PyCompilerFlags
*flags
)
1297 PyObject
*ret
= NULL
;
1299 PyArena
*arena
= PyArena_New();
1303 mod
= PyParser_ASTFromString(str
, "<string>", start
, flags
, arena
);
1305 ret
= run_mod(mod
, "<string>", globals
, locals
, flags
, arena
);
1306 PyArena_Free(arena
);
1311 PyRun_FileExFlags(FILE *fp
, const char *filename
, int start
, PyObject
*globals
,
1312 PyObject
*locals
, int closeit
, PyCompilerFlags
*flags
)
1316 PyArena
*arena
= PyArena_New();
1320 mod
= PyParser_ASTFromFile(fp
, filename
, start
, 0, 0,
1321 flags
, NULL
, arena
);
1325 PyArena_Free(arena
);
1328 ret
= run_mod(mod
, filename
, globals
, locals
, flags
, arena
);
1329 PyArena_Free(arena
);
1334 run_mod(mod_ty mod
, const char *filename
, PyObject
*globals
, PyObject
*locals
,
1335 PyCompilerFlags
*flags
, PyArena
*arena
)
1339 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1342 v
= PyEval_EvalCode(co
, globals
, locals
);
1348 run_pyc_file(FILE *fp
, const char *filename
, PyObject
*globals
,
1349 PyObject
*locals
, PyCompilerFlags
*flags
)
1354 long PyImport_GetMagicNumber(void);
1356 magic
= PyMarshal_ReadLongFromFile(fp
);
1357 if (magic
!= PyImport_GetMagicNumber()) {
1358 PyErr_SetString(PyExc_RuntimeError
,
1359 "Bad magic number in .pyc file");
1362 (void) PyMarshal_ReadLongFromFile(fp
);
1363 v
= PyMarshal_ReadLastObjectFromFile(fp
);
1365 if (v
== NULL
|| !PyCode_Check(v
)) {
1367 PyErr_SetString(PyExc_RuntimeError
,
1368 "Bad code object in .pyc file");
1371 co
= (PyCodeObject
*)v
;
1372 v
= PyEval_EvalCode(co
, globals
, locals
);
1374 flags
->cf_flags
|= (co
->co_flags
& PyCF_MASK
);
1380 Py_CompileStringFlags(const char *str
, const char *filename
, int start
,
1381 PyCompilerFlags
*flags
)
1385 PyArena
*arena
= PyArena_New();
1389 mod
= PyParser_ASTFromString(str
, filename
, start
, flags
, arena
);
1391 PyArena_Free(arena
);
1394 if (flags
&& (flags
->cf_flags
& PyCF_ONLY_AST
)) {
1395 PyObject
*result
= PyAST_mod2obj(mod
);
1396 PyArena_Free(arena
);
1399 co
= PyAST_Compile(mod
, filename
, flags
, arena
);
1400 PyArena_Free(arena
);
1401 return (PyObject
*)co
;
1405 Py_SymtableString(const char *str
, const char *filename
, int start
)
1407 struct symtable
*st
;
1409 PyCompilerFlags flags
;
1410 PyArena
*arena
= PyArena_New();
1416 mod
= PyParser_ASTFromString(str
, filename
, start
, &flags
, arena
);
1418 PyArena_Free(arena
);
1421 st
= PySymtable_Build(mod
, filename
, 0);
1422 PyArena_Free(arena
);
1426 /* Preferred access to parser is through AST. */
1428 PyParser_ASTFromString(const char *s
, const char *filename
, int start
,
1429 PyCompilerFlags
*flags
, PyArena
*arena
)
1432 PyCompilerFlags localflags
;
1434 int iflags
= PARSER_FLAGS(flags
);
1436 node
*n
= PyParser_ParseStringFlagsFilenameEx(s
, filename
,
1437 &_PyParser_Grammar
, start
, &err
,
1439 if (flags
== NULL
) {
1440 localflags
.cf_flags
= 0;
1441 flags
= &localflags
;
1444 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1445 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1456 PyParser_ASTFromFile(FILE *fp
, const char *filename
, int start
, char *ps1
,
1457 char *ps2
, PyCompilerFlags
*flags
, int *errcode
,
1461 PyCompilerFlags localflags
;
1463 int iflags
= PARSER_FLAGS(flags
);
1465 node
*n
= PyParser_ParseFileFlagsEx(fp
, filename
, &_PyParser_Grammar
,
1466 start
, ps1
, ps2
, &err
, &iflags
);
1467 if (flags
== NULL
) {
1468 localflags
.cf_flags
= 0;
1469 flags
= &localflags
;
1472 flags
->cf_flags
|= iflags
& PyCF_MASK
;
1473 mod
= PyAST_FromNode(n
, flags
, filename
, arena
);
1480 *errcode
= err
.error
;
1485 /* Simplified interface to parsefile -- return node or set exception */
1488 PyParser_SimpleParseFileFlags(FILE *fp
, const char *filename
, int start
, int flags
)
1491 node
*n
= PyParser_ParseFileFlags(fp
, filename
, &_PyParser_Grammar
,
1492 start
, NULL
, NULL
, &err
, flags
);
1499 /* Simplified interface to parsestring -- return node or set exception */
1502 PyParser_SimpleParseStringFlags(const char *str
, int start
, int flags
)
1505 node
*n
= PyParser_ParseStringFlags(str
, &_PyParser_Grammar
,
1506 start
, &err
, flags
);
1513 PyParser_SimpleParseStringFlagsFilename(const char *str
, const char *filename
,
1514 int start
, int flags
)
1517 node
*n
= PyParser_ParseStringFlagsFilename(str
, filename
,
1518 &_PyParser_Grammar
, start
, &err
, flags
);
1525 PyParser_SimpleParseStringFilename(const char *str
, const char *filename
, int start
)
1527 return PyParser_SimpleParseStringFlagsFilename(str
, filename
, start
, 0);
1530 /* May want to move a more generalized form of this to parsetok.c or
1531 even parser modules. */
1534 PyParser_SetError(perrdetail
*err
)
1539 /* Set the error appropriate to the given input error code (see errcode.h) */
1542 err_input(perrdetail
*err
)
1544 PyObject
*v
, *w
, *errtype
;
1547 errtype
= PyExc_SyntaxError
;
1548 switch (err
->error
) {
1550 errtype
= PyExc_IndentationError
;
1551 if (err
->expected
== INDENT
)
1552 msg
= "expected an indented block";
1553 else if (err
->token
== INDENT
)
1554 msg
= "unexpected indent";
1555 else if (err
->token
== DEDENT
)
1556 msg
= "unexpected unindent";
1558 errtype
= PyExc_SyntaxError
;
1559 msg
= "invalid syntax";
1563 msg
= "invalid token";
1566 msg
= "EOF while scanning triple-quoted string literal";
1569 msg
= "EOL while scanning string literal";
1572 if (!PyErr_Occurred())
1573 PyErr_SetNone(PyExc_KeyboardInterrupt
);
1579 msg
= "unexpected EOF while parsing";
1582 errtype
= PyExc_TabError
;
1583 msg
= "inconsistent use of tabs and spaces in indentation";
1586 msg
= "expression too long";
1589 errtype
= PyExc_IndentationError
;
1590 msg
= "unindent does not match any outer indentation level";
1593 errtype
= PyExc_IndentationError
;
1594 msg
= "too many levels of indentation";
1597 PyObject
*type
, *value
, *tb
;
1598 PyErr_Fetch(&type
, &value
, &tb
);
1599 if (value
!= NULL
) {
1600 u
= PyObject_Str(value
);
1602 msg
= PyString_AsString(u
);
1606 msg
= "unknown decode error";
1613 msg
= "unexpected character after line continuation character";
1616 fprintf(stderr
, "error=%d\n", err
->error
);
1617 msg
= "unknown parsing error";
1620 v
= Py_BuildValue("(ziiz)", err
->filename
,
1621 err
->lineno
, err
->offset
, err
->text
);
1624 w
= Py_BuildValue("(sO)", msg
, v
);
1627 PyErr_SetObject(errtype
, w
);
1630 if (err
->text
!= NULL
) {
1631 PyObject_FREE(err
->text
);
1636 /* Print fatal error message and abort */
1639 Py_FatalError(const char *msg
)
1641 fprintf(stderr
, "Fatal Python error: %s\n", msg
);
1642 fflush(stderr
); /* it helps in Windows debug build */
1646 size_t len
= strlen(msg
);
1650 /* Convert the message to wchar_t. This uses a simple one-to-one
1651 conversion, assuming that the this error message actually uses ASCII
1652 only. If this ceases to be true, we will have to convert. */
1653 buffer
= alloca( (len
+1) * (sizeof *buffer
));
1654 for( i
=0; i
<=len
; ++i
)
1656 OutputDebugStringW(L
"Fatal Python error: ");
1657 OutputDebugStringW(buffer
);
1658 OutputDebugStringW(L
"\n");
1663 #endif /* MS_WINDOWS */
1667 /* Clean up and exit */
1670 #include "pythread.h"
1673 /* Wait until threading._shutdown completes, provided
1674 the threading module was imported in the first place.
1675 The shutdown routine will wait until all non-daemon
1676 "threading" threads have completed. */
1678 wait_for_thread_shutdown(void)
1682 PyThreadState
*tstate
= PyThreadState_GET();
1683 PyObject
*threading
= PyMapping_GetItemString(tstate
->interp
->modules
,
1685 if (threading
== NULL
) {
1686 /* threading not imported */
1690 result
= PyObject_CallMethod(threading
, "_shutdown", "");
1692 PyErr_WriteUnraisable(threading
);
1695 Py_DECREF(threading
);
1699 #define NEXITFUNCS 32
1700 static void (*exitfuncs
[NEXITFUNCS
])(void);
1701 static int nexitfuncs
= 0;
1703 int Py_AtExit(void (*func
)(void))
1705 if (nexitfuncs
>= NEXITFUNCS
)
1707 exitfuncs
[nexitfuncs
++] = func
;
1712 call_sys_exitfunc(void)
1714 PyObject
*exitfunc
= PySys_GetObject("exitfunc");
1718 Py_INCREF(exitfunc
);
1719 PySys_SetObject("exitfunc", (PyObject
*)NULL
);
1720 res
= PyEval_CallObject(exitfunc
, (PyObject
*)NULL
);
1722 if (!PyErr_ExceptionMatches(PyExc_SystemExit
)) {
1723 PySys_WriteStderr("Error in sys.exitfunc:\n");
1727 Py_DECREF(exitfunc
);
1735 call_ll_exitfuncs(void)
1737 while (nexitfuncs
> 0)
1738 (*exitfuncs
[--nexitfuncs
])();
1756 PyOS_setsig(SIGPIPE
, SIG_IGN
);
1759 PyOS_setsig(SIGXFZ
, SIG_IGN
);
1762 PyOS_setsig(SIGXFSZ
, SIG_IGN
);
1764 PyOS_InitInterrupts(); /* May imply initsignal() */
1769 * The file descriptor fd is considered ``interactive'' if either
1770 * a) isatty(fd) is TRUE, or
1771 * b) the -i flag was given, and the filename associated with
1772 * the descriptor is NULL or "<stdin>" or "???".
1775 Py_FdIsInteractive(FILE *fp
, const char *filename
)
1777 if (isatty((int)fileno(fp
)))
1779 if (!Py_InteractiveFlag
)
1781 return (filename
== NULL
) ||
1782 (strcmp(filename
, "<stdin>") == 0) ||
1783 (strcmp(filename
, "???") == 0);
1787 #if defined(USE_STACKCHECK)
1788 #if defined(WIN32) && defined(_MSC_VER)
1790 /* Stack checking for Microsoft C */
1796 * Return non-zero when we run out of memory on the stack; zero otherwise.
1799 PyOS_CheckStack(void)
1802 /* alloca throws a stack overflow exception if there's
1803 not enough space left on the stack */
1804 alloca(PYOS_STACK_MARGIN
* sizeof(void*));
1806 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW
?
1807 EXCEPTION_EXECUTE_HANDLER
:
1808 EXCEPTION_CONTINUE_SEARCH
) {
1809 int errcode
= _resetstkoflw();
1812 Py_FatalError("Could not reset the stack!");
1818 #endif /* WIN32 && _MSC_VER */
1820 /* Alternate implementations can be added here... */
1822 #endif /* USE_STACKCHECK */
1825 /* Wrappers around sigaction() or signal(). */
1828 PyOS_getsig(int sig
)
1830 #ifdef HAVE_SIGACTION
1831 struct sigaction context
;
1832 if (sigaction(sig
, NULL
, &context
) == -1)
1834 return context
.sa_handler
;
1836 PyOS_sighandler_t handler
;
1837 /* Special signal handling for the secure CRT in Visual Studio 2005 */
1838 #if defined(_MSC_VER) && _MSC_VER >= 1400
1840 /* Only these signals are valid */
1849 /* Don't call signal() with other values or it will assert */
1853 #endif /* _MSC_VER && _MSC_VER >= 1400 */
1854 handler
= signal(sig
, SIG_IGN
);
1855 if (handler
!= SIG_ERR
)
1856 signal(sig
, handler
);
1862 PyOS_setsig(int sig
, PyOS_sighandler_t handler
)
1864 #ifdef HAVE_SIGACTION
1865 struct sigaction context
, ocontext
;
1866 context
.sa_handler
= handler
;
1867 sigemptyset(&context
.sa_mask
);
1868 context
.sa_flags
= 0;
1869 if (sigaction(sig
, &context
, &ocontext
) == -1)
1871 return ocontext
.sa_handler
;
1873 PyOS_sighandler_t oldhandler
;
1874 oldhandler
= signal(sig
, handler
);
1875 #ifdef HAVE_SIGINTERRUPT
1876 siginterrupt(sig
, 1);
1882 /* Deprecated C API functions still provided for binary compatiblity */
1884 #undef PyParser_SimpleParseFile
1886 PyParser_SimpleParseFile(FILE *fp
, const char *filename
, int start
)
1888 return PyParser_SimpleParseFileFlags(fp
, filename
, start
, 0);
1891 #undef PyParser_SimpleParseString
1893 PyParser_SimpleParseString(const char *str
, int start
)
1895 return PyParser_SimpleParseStringFlags(str
, start
, 0);
1898 #undef PyRun_AnyFile
1900 PyRun_AnyFile(FILE *fp
, const char *name
)
1902 return PyRun_AnyFileExFlags(fp
, name
, 0, NULL
);
1905 #undef PyRun_AnyFileEx
1907 PyRun_AnyFileEx(FILE *fp
, const char *name
, int closeit
)
1909 return PyRun_AnyFileExFlags(fp
, name
, closeit
, NULL
);
1912 #undef PyRun_AnyFileFlags
1914 PyRun_AnyFileFlags(FILE *fp
, const char *name
, PyCompilerFlags
*flags
)
1916 return PyRun_AnyFileExFlags(fp
, name
, 0, flags
);
1920 PyAPI_FUNC(PyObject
*)
1921 PyRun_File(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
)
1923 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, NULL
);
1927 PyAPI_FUNC(PyObject
*)
1928 PyRun_FileEx(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
, int c
)
1930 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, c
, NULL
);
1933 #undef PyRun_FileFlags
1934 PyAPI_FUNC(PyObject
*)
1935 PyRun_FileFlags(FILE *fp
, const char *p
, int s
, PyObject
*g
, PyObject
*l
,
1936 PyCompilerFlags
*flags
)
1938 return PyRun_FileExFlags(fp
, p
, s
, g
, l
, 0, flags
);
1941 #undef PyRun_SimpleFile
1943 PyRun_SimpleFile(FILE *f
, const char *p
)
1945 return PyRun_SimpleFileExFlags(f
, p
, 0, NULL
);
1948 #undef PyRun_SimpleFileEx
1950 PyRun_SimpleFileEx(FILE *f
, const char *p
, int c
)
1952 return PyRun_SimpleFileExFlags(f
, p
, c
, NULL
);
1957 PyAPI_FUNC(PyObject
*)
1958 PyRun_String(const char *str
, int s
, PyObject
*g
, PyObject
*l
)
1960 return PyRun_StringFlags(str
, s
, g
, l
, NULL
);
1963 #undef PyRun_SimpleString
1965 PyRun_SimpleString(const char *s
)
1967 return PyRun_SimpleStringFlags(s
, NULL
);
1970 #undef Py_CompileString
1971 PyAPI_FUNC(PyObject
*)
1972 Py_CompileString(const char *str
, const char *p
, int s
)
1974 return Py_CompileStringFlags(str
, p
, s
, NULL
);
1977 #undef PyRun_InteractiveOne
1979 PyRun_InteractiveOne(FILE *f
, const char *p
)
1981 return PyRun_InteractiveOneFlags(f
, p
, NULL
);
1984 #undef PyRun_InteractiveLoop
1986 PyRun_InteractiveLoop(FILE *f
, const char *p
)
1988 return PyRun_InteractiveLoopFlags(f
, p
, NULL
);