blob: 86d9fe2250c05879649a61213d1e37d64839a408 [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
Brett Cannone3944a52009-04-01 05:08:41 +000010#define PyCF_MASK CO_FUTURE_BARRY_AS_BDFL
Guido van Rossum45aecf42006-03-15 04:58:47 +000011#define PyCF_MASK_OBSOLETE 0
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
Martin v. Löwisbd260da2006-02-26 19:42:26 +000014#define PyCF_ONLY_AST 0x0400
Benjamin Petersonf5b52242009-03-02 23:31:26 +000015#define PyCF_IGNORE_COOKIE 0x0800
Tim Peterse2c18e92001-08-17 20:47:47 +000016
Jeremy Hylton9f324e92001-03-01 22:59:14 +000017typedef struct {
Jeremy Hyltonfdd12f62001-08-10 21:38:04 +000018 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Jeremy Hylton9f324e92001-03-01 22:59:14 +000019} PyCompilerFlags;
20
Martin v. Löwis790465f2008-04-05 20:41:37 +000021PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
22PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
Guido van Rossum66d4b901998-02-06 22:28:05 +000023
Martin v. Löwis790465f2008-04-05 20:41:37 +000024PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
25PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
Guido van Rossum3f5da241990-12-20 15:06:42 +000026
Mark Hammond91a681d2002-08-12 07:21:58 +000027PyAPI_FUNC(void) Py_Initialize(void);
Martin v. Löwis336e85f2004-08-19 11:31:58 +000028PyAPI_FUNC(void) Py_InitializeEx(int);
Mark Hammond91a681d2002-08-12 07:21:58 +000029PyAPI_FUNC(void) Py_Finalize(void);
30PyAPI_FUNC(int) Py_IsInitialized(void);
31PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
32PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000033
Martin v. Löwis056a69c2006-03-01 16:55:42 +000034PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
35PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000036PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000037PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000038PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000039PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000040
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000041PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
Neal Norwitzadb69fc2005-12-17 20:54:49 +000042 int, PyCompilerFlags *flags,
43 PyArena *);
Martin v. Löwis85bcc662007-09-04 09:18:06 +000044PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *,
45 const char*, int,
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000046 char *, char *,
Neal Norwitzadb69fc2005-12-17 20:54:49 +000047 PyCompilerFlags *, int *,
48 PyArena *);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000049#define PyParser_SimpleParseString(S, B) \
50 PyParser_SimpleParseStringFlags(S, B, 0)
51#define PyParser_SimpleParseFile(FP, S, B) \
52 PyParser_SimpleParseFileFlags(FP, S, B, 0)
53PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
54 int);
Martin v. Löwis95292d62002-12-11 14:04:59 +000055PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Tim Petersfe2127d2001-07-16 05:37:24 +000056 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000057
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000058PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
59 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +000060
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000061PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
62 PyObject *, PyObject *, int,
63 PyCompilerFlags *);
64
65#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
Martin v. Löwis95292d62002-12-11 14:04:59 +000066PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000067 PyCompilerFlags *);
Martin v. Löwis95292d62002-12-11 14:04:59 +000068PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000069
Mark Hammond91a681d2002-08-12 07:21:58 +000070PyAPI_FUNC(void) PyErr_Print(void);
71PyAPI_FUNC(void) PyErr_PrintEx(int);
72PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +000073
Collin Winter670e6922007-03-21 02:57:17 +000074/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
75 * exit functions.
76 */
77PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void));
Mark Hammond91a681d2002-08-12 07:21:58 +000078PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
Guido van Rossuma3309961993-07-28 09:05:47 +000079
Mark Hammond91a681d2002-08-12 07:21:58 +000080PyAPI_FUNC(void) Py_Exit(int);
Fred Drake3cf4d2b2000-07-09 00:55:06 +000081
Martin v. Löwis95292d62002-12-11 14:04:59 +000082PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
Guido van Rossum5c4998b1997-02-14 19:51:34 +000083
Mark Hammondfe51c6d2002-08-02 02:27:13 +000084/* Bootstrap */
Martin v. Löwis790465f2008-04-05 20:41:37 +000085PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
Mark Hammondfe51c6d2002-08-02 02:27:13 +000086
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000087/* Use macros for a bunch of old variants */
88#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
89#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
90#define PyRun_AnyFileEx(fp, name, closeit) \
91 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
92#define PyRun_AnyFileFlags(fp, name, flags) \
93 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +000094#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000095#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
96#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
97#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
98#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
99#define PyRun_File(fp, p, s, g, l) \
100 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
101#define PyRun_FileEx(fp, p, s, g, l, c) \
102 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
103#define PyRun_FileFlags(fp, p, s, g, l, flags) \
104 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
105
Guido van Rossum57d8e3f1997-07-19 19:50:52 +0000106/* In getpath.c */
Martin v. Löwis790465f2008-04-05 20:41:37 +0000107PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
108PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
109PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
110PyAPI_FUNC(wchar_t *) Py_GetPath(void);
Guido van Rossum57d8e3f1997-07-19 19:50:52 +0000111
112/* In their own files */
Mark Hammonda2905272002-07-29 13:42:14 +0000113PyAPI_FUNC(const char *) Py_GetVersion(void);
114PyAPI_FUNC(const char *) Py_GetPlatform(void);
115PyAPI_FUNC(const char *) Py_GetCopyright(void);
116PyAPI_FUNC(const char *) Py_GetCompiler(void);
117PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
Martin v. Löwis43b57802006-01-05 23:38:54 +0000118PyAPI_FUNC(const char *) _Py_svnversion(void);
119PyAPI_FUNC(const char *) Py_SubversionRevision(void);
120PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
Guido van Rossum57d8e3f1997-07-19 19:50:52 +0000121
Guido van Rossum29e46a91997-08-02 02:56:48 +0000122/* Internal -- various one-time initializations */
Mark Hammond91a681d2002-08-12 07:21:58 +0000123PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
124PyAPI_FUNC(PyObject *) _PySys_Init(void);
125PyAPI_FUNC(void) _PyImport_Init(void);
Mark Hammonda2905272002-07-29 13:42:14 +0000126PyAPI_FUNC(void) _PyExc_Init(void);
Just van Rossum52e14d62002-12-30 22:08:05 +0000127PyAPI_FUNC(void) _PyImportHooks_Init(void);
Neal Norwitzb2501f42002-12-31 03:42:13 +0000128PyAPI_FUNC(int) _PyFrame_Init(void);
Michael W. Hudsonba283e22005-05-27 15:23:20 +0000129PyAPI_FUNC(void) _PyFloat_Init(void);
Christian Heimes9c4756e2008-05-26 13:22:05 +0000130PyAPI_FUNC(int) PyByteArray_Init(void);
Guido van Rossum29e46a91997-08-02 02:56:48 +0000131
Guido van Rossum8e5e4461997-08-12 14:57:21 +0000132/* Various internal finalizers */
Mark Hammonda2905272002-07-29 13:42:14 +0000133PyAPI_FUNC(void) _PyExc_Fini(void);
134PyAPI_FUNC(void) _PyImport_Fini(void);
135PyAPI_FUNC(void) PyMethod_Fini(void);
136PyAPI_FUNC(void) PyFrame_Fini(void);
137PyAPI_FUNC(void) PyCFunction_Fini(void);
Christian Heimes77c02eb2008-02-09 02:18:51 +0000138PyAPI_FUNC(void) PyDict_Fini(void);
Mark Hammonda2905272002-07-29 13:42:14 +0000139PyAPI_FUNC(void) PyTuple_Fini(void);
Raymond Hettingerfb09f0e2004-10-07 03:58:07 +0000140PyAPI_FUNC(void) PyList_Fini(void);
Raymond Hettingerd7946662005-08-01 21:39:29 +0000141PyAPI_FUNC(void) PySet_Fini(void);
Christian Heimes72b710a2008-05-26 13:28:38 +0000142PyAPI_FUNC(void) PyBytes_Fini(void);
Christian Heimes9c4756e2008-05-26 13:22:05 +0000143PyAPI_FUNC(void) PyByteArray_Fini(void);
Mark Hammonda2905272002-07-29 13:42:14 +0000144PyAPI_FUNC(void) PyFloat_Fini(void);
145PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
Guido van Rossum8e5e4461997-08-12 14:57:21 +0000146
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000147/* Stuff with no proper home (yet) */
Martin v. Löwis566f6af2002-10-26 14:39:10 +0000148PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
Mark Hammond5d546672002-08-12 13:06:35 +0000149PyAPI_DATA(int) (*PyOS_InputHook)(void);
Martin v. Löwis566f6af2002-10-26 14:39:10 +0000150PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000151PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000152
153/* Stack size, in "pointers" (so we get extra safety margins
154 on 64-bit platforms). On a 32-bit platform, this translates
155 to a 8k margin. */
156#define PYOS_STACK_MARGIN 2048
157
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000158#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000159/* Enable stack checking under Microsoft C */
160#define USE_STACKCHECK
161#endif
162
Jack Jansen275abb32000-08-07 21:00:42 +0000163#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000164/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000165PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000166#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000167
Guido van Rossumc7247ce2000-09-16 16:31:31 +0000168/* Signals */
169typedef void (*PyOS_sighandler_t)(int);
Mark Hammond91a681d2002-08-12 07:21:58 +0000170PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
171PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
Guido van Rossumc7247ce2000-09-16 16:31:31 +0000172
173
Guido van Rossuma3309961993-07-28 09:05:47 +0000174#ifdef __cplusplus
175}
176#endif
177#endif /* !Py_PYTHONRUN_H */