blob: d6010053372ac1cfd9cd1c8d1797c763ba662ece [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
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000010#ifndef Py_LIMITED_API
11PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Victor Stinner00676d12010-12-27 01:49:31 +000012PyAPI_FUNC(int) PyRun_AnyFileExFlags(
13 FILE *fp,
14 const char *filename, /* decoded from the filesystem encoding */
15 int closeit,
16 PyCompilerFlags *flags);
17PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
18 FILE *fp,
19 const char *filename, /* decoded from the filesystem encoding */
20 int closeit,
21 PyCompilerFlags *flags);
22PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
23 FILE *fp,
24 const char *filename, /* decoded from the filesystem encoding */
25 PyCompilerFlags *flags);
Victor Stinner95701bd2013-11-06 18:41:07 +010026PyAPI_FUNC(int) PyRun_InteractiveOneObject(
27 FILE *fp,
28 PyObject *filename,
29 PyCompilerFlags *flags);
Victor Stinner00676d12010-12-27 01:49:31 +000030PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
31 FILE *fp,
32 const char *filename, /* decoded from the filesystem encoding */
33 PyCompilerFlags *flags);
Guido van Rossum3f5da241990-12-20 15:06:42 +000034
Victor Stinner00676d12010-12-27 01:49:31 +000035PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
36 const char *s,
37 const char *filename, /* decoded from the filesystem encoding */
38 int start,
39 PyCompilerFlags *flags,
40 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020041PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
42 const char *s,
43 PyObject *filename,
44 int start,
45 PyCompilerFlags *flags,
46 PyArena *arena);
Victor Stinner00676d12010-12-27 01:49:31 +000047PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
48 FILE *fp,
49 const char *filename, /* decoded from the filesystem encoding */
50 const char* enc,
51 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020052 const char *ps1,
53 const char *ps2,
Victor Stinner00676d12010-12-27 01:49:31 +000054 PyCompilerFlags *flags,
55 int *errcode,
56 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020057PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
58 FILE *fp,
59 PyObject *filename,
60 const char* enc,
61 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020062 const char *ps1,
63 const char *ps2,
Victor Stinner14e461d2013-08-26 22:28:21 +020064 PyCompilerFlags *flags,
65 int *errcode,
66 PyArena *arena);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000067#endif
68
69#ifndef PyParser_SimpleParseString
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000070#define PyParser_SimpleParseString(S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000071 PyParser_SimpleParseStringFlags(S, B, 0)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000072#define PyParser_SimpleParseFile(FP, S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000073 PyParser_SimpleParseFileFlags(FP, S, B, 0)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000074#endif
Lysandros Nikolaoud301d942020-06-21 04:15:45 +030075Py_DEPRECATED(3.9) PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *,
76 int, int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020077#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
Lysandros Nikolaoud301d942020-06-21 04:15:45 +030078Py_DEPRECATED(3.9) PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
79 const char *,
80 int, int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020081#endif
Lysandros Nikolaoud301d942020-06-21 04:15:45 +030082Py_DEPRECATED(3.9) PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
83 int, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000084#ifndef Py_LIMITED_API
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000085PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
86 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +000087
Victor Stinner00676d12010-12-27 01:49:31 +000088PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
89 FILE *fp,
90 const char *filename, /* decoded from the filesystem encoding */
91 int start,
92 PyObject *globals,
93 PyObject *locals,
94 int closeit,
95 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000096#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000097
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000098#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +000099PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000100#else
Georg Brandl8334fd92010-12-04 10:26:46 +0000101#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
102#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +0000103PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
104 const char *str,
105 const char *filename, /* decoded from the filesystem encoding */
106 int start,
107 PyCompilerFlags *flags,
108 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +0200109PyAPI_FUNC(PyObject *) Py_CompileStringObject(
110 const char *str,
111 PyObject *filename, int start,
112 PyCompilerFlags *flags,
113 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000114#endif
Victor Stinner00676d12010-12-27 01:49:31 +0000115PyAPI_FUNC(struct symtable *) Py_SymtableString(
116 const char *str,
117 const char *filename, /* decoded from the filesystem encoding */
118 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100119#ifndef Py_LIMITED_API
Dino Viehland41540692019-05-28 16:21:17 -0700120PyAPI_FUNC(const char *) _Py_SourceAsString(
121 PyObject *cmd,
122 const char *funcname,
Victor Stinner343ed0f2019-06-18 00:15:13 +0200123 const char *what,
Dino Viehland41540692019-05-28 16:21:17 -0700124 PyCompilerFlags *cf,
125 PyObject **cmd_copy);
126
Victor Stinner14e461d2013-08-26 22:28:21 +0200127PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
128 const char *str,
129 PyObject *filename,
130 int start);
Dino Viehland41540692019-05-28 16:21:17 -0700131
132PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags(
133 const char *str,
134 PyObject *filename,
135 int start,
136 PyCompilerFlags *flags);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100137#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +0000138
Mark Hammond91a681d2002-08-12 07:21:58 +0000139PyAPI_FUNC(void) PyErr_Print(void);
140PyAPI_FUNC(void) PyErr_PrintEx(int);
141PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +0000142
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000143#ifndef Py_LIMITED_API
Victor Stinner343ed0f2019-06-18 00:15:13 +0200144/* A function flavor is also exported by libpython. It is required when
145 libpython is accessed directly rather than using header files which defines
146 macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to
147 export functions in pythonXX.dll. */
148PyAPI_FUNC(PyObject *) PyRun_String(const char *str, int s, PyObject *g, PyObject *l);
149PyAPI_FUNC(int) PyRun_AnyFile(FILE *fp, const char *name);
150PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *fp, const char *name, int closeit);
151PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
152PyAPI_FUNC(int) PyRun_SimpleString(const char *s);
153PyAPI_FUNC(int) PyRun_SimpleFile(FILE *f, const char *p);
154PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *f, const char *p, int c);
155PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *f, const char *p);
156PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *f, const char *p);
157PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l);
158PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c);
159PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags);
160
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000161/* Use macros for a bunch of old variants */
162#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
163#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
164#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000165 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000166#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000167 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000168#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000169#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
170#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
171#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
172#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
173#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000174 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000175#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000176 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000177#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000178 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000179#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000180
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000181/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000182#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300183PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000184#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000185PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300186PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000187#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000188PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000189#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000190
191/* Stack size, in "pointers" (so we get extra safety margins
192 on 64-bit platforms). On a 32-bit platform, this translates
Martin Panter4c359642016-05-08 13:53:41 +0000193 to an 8k margin. */
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000194#define PYOS_STACK_MARGIN 2048
195
Paul Monson11efd792019-04-17 18:09:16 -0700196#if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000197/* Enable stack checking under Microsoft C */
198#define USE_STACKCHECK
199#endif
200
Jack Jansen275abb32000-08-07 21:00:42 +0000201#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000202/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000203PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000204#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000205
Guido van Rossuma3309961993-07-28 09:05:47 +0000206#ifdef __cplusplus
207}
208#endif
209#endif /* !Py_PYTHONRUN_H */