blob: 490613eb770d005a33d6e48061155dbd88eb2816 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum3f5da241990-12-20 15:06:42 +00002/* Interfaces to parse and execute pieces of python code */
3
Fred Drake3cf4d2b2000-07-09 00:55:06 +00004#ifndef Py_PYTHONRUN_H
5#define Py_PYTHONRUN_H
6#ifdef __cplusplus
7extern "C" {
8#endif
Guido van Rossum57d8e3f1997-07-19 19:50:52 +00009
Tim Peters2bbdba32002-04-12 01:20:10 +000010#define PyCF_MASK (CO_FUTURE_DIVISION)
11#define PyCF_MASK_OBSOLETE (CO_GENERATOR_ALLOWED | CO_NESTED)
Just van Rossum3aaf42c2003-02-10 08:21:10 +000012#define PyCF_SOURCE_IS_UTF8 0x0100
Guido van Rossum4b499dd32003-02-13 22:07:59 +000013#define PyCF_DONT_IMPLY_DEDENT 0x0200
Tim Peterse2c18e92001-08-17 20:47:47 +000014
Jeremy Hylton9f324e92001-03-01 22:59:14 +000015typedef struct {
Jeremy Hyltonfdd12f62001-08-10 21:38:04 +000016 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Jeremy Hylton9f324e92001-03-01 22:59:14 +000017} PyCompilerFlags;
18
Mark Hammond91a681d2002-08-12 07:21:58 +000019PyAPI_FUNC(void) Py_SetProgramName(char *);
20PyAPI_FUNC(char *) Py_GetProgramName(void);
Guido van Rossum66d4b901998-02-06 22:28:05 +000021
Mark Hammond91a681d2002-08-12 07:21:58 +000022PyAPI_FUNC(void) Py_SetPythonHome(char *);
23PyAPI_FUNC(char *) Py_GetPythonHome(void);
Guido van Rossum3f5da241990-12-20 15:06:42 +000024
Mark Hammond91a681d2002-08-12 07:21:58 +000025PyAPI_FUNC(void) Py_Initialize(void);
Martin v. Löwis336e85f2004-08-19 11:31:58 +000026PyAPI_FUNC(void) Py_InitializeEx(int);
Mark Hammond91a681d2002-08-12 07:21:58 +000027PyAPI_FUNC(void) Py_Finalize(void);
28PyAPI_FUNC(int) Py_IsInitialized(void);
29PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
30PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000031
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000032PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, char *, PyCompilerFlags *);
33PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, char *, int, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000034PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000035PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000036PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000037PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000038
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
40 int, PyCompilerFlags *flags);
41PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,
42 char *, char *,
43 PyCompilerFlags *, int *);
44#define PyParser_SimpleParseString(S, B) \
45 PyParser_SimpleParseStringFlags(S, B, 0)
46#define PyParser_SimpleParseFile(FP, S, B) \
47 PyParser_SimpleParseFileFlags(FP, S, B, 0)
48PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
49 int);
Martin v. Löwis95292d62002-12-11 14:04:59 +000050PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Tim Petersfe2127d2001-07-16 05:37:24 +000051 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000052
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000053PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
54 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +000055
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000056PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
57 PyObject *, PyObject *, int,
58 PyCompilerFlags *);
59
60#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
Martin v. Löwis95292d62002-12-11 14:04:59 +000061PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000062 PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000063PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000064
Mark Hammond91a681d2002-08-12 07:21:58 +000065PyAPI_FUNC(void) PyErr_Print(void);
66PyAPI_FUNC(void) PyErr_PrintEx(int);
67PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +000068
Mark Hammond91a681d2002-08-12 07:21:58 +000069PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
Guido van Rossuma3309961993-07-28 09:05:47 +000070
Mark Hammond91a681d2002-08-12 07:21:58 +000071PyAPI_FUNC(void) Py_Exit(int);
Fred Drake3cf4d2b2000-07-09 00:55:06 +000072
Martin v. Löwis95292d62002-12-11 14:04:59 +000073PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
Guido van Rossum5c4998b1997-02-14 19:51:34 +000074
Mark Hammondfe51c6d2002-08-02 02:27:13 +000075/* Bootstrap */
76PyAPI_FUNC(int) Py_Main(int argc, char **argv);
77
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000078/* Use macros for a bunch of old variants */
79#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
80#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
81#define PyRun_AnyFileEx(fp, name, closeit) \
82 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
83#define PyRun_AnyFileFlags(fp, name, flags) \
84 PyRun_AnyFileExFlags(fp, name, 0, flags)
85#define PyRun_SimpleString(s, f) PyRunSimpleStringFlags(s, f, NULL)
86#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
87#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
88#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
89#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
90#define PyRun_File(fp, p, s, g, l) \
91 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
92#define PyRun_FileEx(fp, p, s, g, l, c) \
93 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
94#define PyRun_FileFlags(fp, p, s, g, l, flags) \
95 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
96
Guido van Rossum57d8e3f1997-07-19 19:50:52 +000097/* In getpath.c */
Mark Hammonda2905272002-07-29 13:42:14 +000098PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
99PyAPI_FUNC(char *) Py_GetPrefix(void);
100PyAPI_FUNC(char *) Py_GetExecPrefix(void);
101PyAPI_FUNC(char *) Py_GetPath(void);
Guido van Rossum57d8e3f1997-07-19 19:50:52 +0000102
103/* In their own files */
Mark Hammonda2905272002-07-29 13:42:14 +0000104PyAPI_FUNC(const char *) Py_GetVersion(void);
105PyAPI_FUNC(const char *) Py_GetPlatform(void);
106PyAPI_FUNC(const char *) Py_GetCopyright(void);
107PyAPI_FUNC(const char *) Py_GetCompiler(void);
108PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
Guido van Rossum57d8e3f1997-07-19 19:50:52 +0000109
Guido van Rossum29e46a91997-08-02 02:56:48 +0000110/* Internal -- various one-time initializations */
Mark Hammond91a681d2002-08-12 07:21:58 +0000111PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
112PyAPI_FUNC(PyObject *) _PySys_Init(void);
113PyAPI_FUNC(void) _PyImport_Init(void);
Mark Hammonda2905272002-07-29 13:42:14 +0000114PyAPI_FUNC(void) _PyExc_Init(void);
Just van Rossum52e14d62002-12-30 22:08:05 +0000115PyAPI_FUNC(void) _PyImportHooks_Init(void);
Neal Norwitzb2501f42002-12-31 03:42:13 +0000116PyAPI_FUNC(int) _PyFrame_Init(void);
Neal Norwitzdc392e32003-01-01 15:18:32 +0000117PyAPI_FUNC(int) _PyInt_Init(void);
Michael W. Hudsonba283e22005-05-27 15:23:20 +0000118PyAPI_FUNC(void) _PyFloat_Init(void);
Guido van Rossum29e46a91997-08-02 02:56:48 +0000119
Guido van Rossum8e5e4461997-08-12 14:57:21 +0000120/* Various internal finalizers */
Mark Hammonda2905272002-07-29 13:42:14 +0000121PyAPI_FUNC(void) _PyExc_Fini(void);
122PyAPI_FUNC(void) _PyImport_Fini(void);
123PyAPI_FUNC(void) PyMethod_Fini(void);
124PyAPI_FUNC(void) PyFrame_Fini(void);
125PyAPI_FUNC(void) PyCFunction_Fini(void);
126PyAPI_FUNC(void) PyTuple_Fini(void);
Raymond Hettingerfb09f0e2004-10-07 03:58:07 +0000127PyAPI_FUNC(void) PyList_Fini(void);
Raymond Hettingerd7946662005-08-01 21:39:29 +0000128PyAPI_FUNC(void) PySet_Fini(void);
Mark Hammonda2905272002-07-29 13:42:14 +0000129PyAPI_FUNC(void) PyString_Fini(void);
130PyAPI_FUNC(void) PyInt_Fini(void);
131PyAPI_FUNC(void) PyFloat_Fini(void);
132PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
Guido van Rossum8e5e4461997-08-12 14:57:21 +0000133
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000134/* Stuff with no proper home (yet) */
Martin v. Löwis566f6af2002-10-26 14:39:10 +0000135PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
Mark Hammond5d546672002-08-12 13:06:35 +0000136PyAPI_DATA(int) (*PyOS_InputHook)(void);
Martin v. Löwis566f6af2002-10-26 14:39:10 +0000137PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000138PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000139
140/* Stack size, in "pointers" (so we get extra safety margins
141 on 64-bit platforms). On a 32-bit platform, this translates
142 to a 8k margin. */
143#define PYOS_STACK_MARGIN 2048
144
Trent Mick0a7af402000-10-11 17:18:11 +0000145#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER)
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000146/* Enable stack checking under Microsoft C */
147#define USE_STACKCHECK
148#endif
149
Jack Jansen275abb32000-08-07 21:00:42 +0000150#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000151/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000152PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000153#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000154
Guido van Rossumc7247ce2000-09-16 16:31:31 +0000155/* Signals */
156typedef void (*PyOS_sighandler_t)(int);
Mark Hammond91a681d2002-08-12 07:21:58 +0000157PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
158PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
Guido van Rossumc7247ce2000-09-16 16:31:31 +0000159
160
Guido van Rossuma3309961993-07-28 09:05:47 +0000161#ifdef __cplusplus
162}
163#endif
164#endif /* !Py_PYTHONRUN_H */