blob: efc613f65dfe88f11c902f55bdef1834f2e94278 [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
Benjamin Peterson466a7822009-07-02 21:44:01 +000010#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
11 CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
Yury Selivanov8170e8c2015-05-09 11:44:30 -040012 CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
13 CO_FUTURE_GENERATOR_STOP)
Benjamin Petersonffeaa882009-07-02 21:54:36 +000014#define PyCF_MASK_OBSOLETE (CO_NESTED)
Just van Rossum3aaf42c2003-02-10 08:21:10 +000015#define PyCF_SOURCE_IS_UTF8 0x0100
Guido van Rossum4b499dd32003-02-13 22:07:59 +000016#define PyCF_DONT_IMPLY_DEDENT 0x0200
Martin v. Löwisbd260da2006-02-26 19:42:26 +000017#define PyCF_ONLY_AST 0x0400
Benjamin Petersonf5b52242009-03-02 23:31:26 +000018#define PyCF_IGNORE_COOKIE 0x0800
Tim Peterse2c18e92001-08-17 20:47:47 +000019
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000020#ifndef Py_LIMITED_API
Jeremy Hylton9f324e92001-03-01 22:59:14 +000021typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000022 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Jeremy Hylton9f324e92001-03-01 22:59:14 +000023} PyCompilerFlags;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000024#endif
Jeremy Hylton9f324e92001-03-01 22:59:14 +000025
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000026#ifndef Py_LIMITED_API
27PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Martin v. Löwis056a69c2006-03-01 16:55:42 +000028PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
Victor Stinner00676d12010-12-27 01:49:31 +000029PyAPI_FUNC(int) PyRun_AnyFileExFlags(
30 FILE *fp,
31 const char *filename, /* decoded from the filesystem encoding */
32 int closeit,
33 PyCompilerFlags *flags);
34PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
35 FILE *fp,
36 const char *filename, /* decoded from the filesystem encoding */
37 int closeit,
38 PyCompilerFlags *flags);
39PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
40 FILE *fp,
41 const char *filename, /* decoded from the filesystem encoding */
42 PyCompilerFlags *flags);
Victor Stinner95701bd2013-11-06 18:41:07 +010043PyAPI_FUNC(int) PyRun_InteractiveOneObject(
44 FILE *fp,
45 PyObject *filename,
46 PyCompilerFlags *flags);
Victor Stinner00676d12010-12-27 01:49:31 +000047PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
48 FILE *fp,
49 const char *filename, /* decoded from the filesystem encoding */
50 PyCompilerFlags *flags);
Guido van Rossum3f5da241990-12-20 15:06:42 +000051
Victor Stinner00676d12010-12-27 01:49:31 +000052PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
53 const char *s,
54 const char *filename, /* decoded from the filesystem encoding */
55 int start,
56 PyCompilerFlags *flags,
57 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020058PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
59 const char *s,
60 PyObject *filename,
61 int start,
62 PyCompilerFlags *flags,
63 PyArena *arena);
Victor Stinner00676d12010-12-27 01:49:31 +000064PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
65 FILE *fp,
66 const char *filename, /* decoded from the filesystem encoding */
67 const char* enc,
68 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020069 const char *ps1,
70 const char *ps2,
Victor Stinner00676d12010-12-27 01:49:31 +000071 PyCompilerFlags *flags,
72 int *errcode,
73 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020074PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
75 FILE *fp,
76 PyObject *filename,
77 const char* enc,
78 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020079 const char *ps1,
80 const char *ps2,
Victor Stinner14e461d2013-08-26 22:28:21 +020081 PyCompilerFlags *flags,
82 int *errcode,
83 PyArena *arena);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000084#endif
85
86#ifndef PyParser_SimpleParseString
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000087#define PyParser_SimpleParseString(S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000088 PyParser_SimpleParseStringFlags(S, B, 0)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000089#define PyParser_SimpleParseFile(FP, S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000090 PyParser_SimpleParseFileFlags(FP, S, B, 0)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000091#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000092PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
Eli Bendersky08131682012-06-03 08:07:47 +030093 int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020094#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
Eli Bendersky08131682012-06-03 08:07:47 +030095PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
96 const char *,
97 int, int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020098#endif
Martin v. Löwis95292d62002-12-11 14:04:59 +000099PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Eli Bendersky08131682012-06-03 08:07:47 +0300100 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +0000101
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000102#ifndef Py_LIMITED_API
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000103PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
104 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +0000105
Victor Stinner00676d12010-12-27 01:49:31 +0000106PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
107 FILE *fp,
108 const char *filename, /* decoded from the filesystem encoding */
109 int start,
110 PyObject *globals,
111 PyObject *locals,
112 int closeit,
113 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000114#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000115
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000116#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +0000117PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000118#else
Georg Brandl8334fd92010-12-04 10:26:46 +0000119#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
120#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +0000121PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
122 const char *str,
123 const char *filename, /* decoded from the filesystem encoding */
124 int start,
125 PyCompilerFlags *flags,
126 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +0200127PyAPI_FUNC(PyObject *) Py_CompileStringObject(
128 const char *str,
129 PyObject *filename, int start,
130 PyCompilerFlags *flags,
131 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000132#endif
Victor Stinner00676d12010-12-27 01:49:31 +0000133PyAPI_FUNC(struct symtable *) Py_SymtableString(
134 const char *str,
135 const char *filename, /* decoded from the filesystem encoding */
136 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100137#ifndef Py_LIMITED_API
Victor Stinner14e461d2013-08-26 22:28:21 +0200138PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
139 const char *str,
140 PyObject *filename,
141 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100142#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +0000143
Mark Hammond91a681d2002-08-12 07:21:58 +0000144PyAPI_FUNC(void) PyErr_Print(void);
145PyAPI_FUNC(void) PyErr_PrintEx(int);
146PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +0000147
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000148#ifndef Py_LIMITED_API
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000149/* Use macros for a bunch of old variants */
150#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
151#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
152#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000153 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000154#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000155 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000156#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000157#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
158#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
159#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
160#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
161#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000162 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000163#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000164 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000165#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000166 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000167#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000168
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000169/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000170#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300171PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000172#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000173PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300174PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000175#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000176PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000177#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000178
179/* Stack size, in "pointers" (so we get extra safety margins
180 on 64-bit platforms). On a 32-bit platform, this translates
Martin Panter4c359642016-05-08 13:53:41 +0000181 to an 8k margin. */
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000182#define PYOS_STACK_MARGIN 2048
183
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000184#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000185/* Enable stack checking under Microsoft C */
186#define USE_STACKCHECK
187#endif
188
Jack Jansen275abb32000-08-07 21:00:42 +0000189#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000190/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000191PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000192#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000193
Guido van Rossuma3309961993-07-28 09:05:47 +0000194#ifdef __cplusplus
195}
196#endif
197#endif /* !Py_PYTHONRUN_H */