blob: 6f0c6fc6554379ceaabcd303dae913198c33b2d8 [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 *);
Martin v. Löwis056a69c2006-03-01 16:55:42 +000012PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
Victor Stinner00676d12010-12-27 01:49:31 +000013PyAPI_FUNC(int) PyRun_AnyFileExFlags(
14 FILE *fp,
15 const char *filename, /* decoded from the filesystem encoding */
16 int closeit,
17 PyCompilerFlags *flags);
18PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
19 FILE *fp,
20 const char *filename, /* decoded from the filesystem encoding */
21 int closeit,
22 PyCompilerFlags *flags);
23PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
24 FILE *fp,
25 const char *filename, /* decoded from the filesystem encoding */
26 PyCompilerFlags *flags);
Victor Stinner95701bd2013-11-06 18:41:07 +010027PyAPI_FUNC(int) PyRun_InteractiveOneObject(
28 FILE *fp,
29 PyObject *filename,
30 PyCompilerFlags *flags);
Victor Stinner00676d12010-12-27 01:49:31 +000031PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
32 FILE *fp,
33 const char *filename, /* decoded from the filesystem encoding */
34 PyCompilerFlags *flags);
Guido van Rossum3f5da241990-12-20 15:06:42 +000035
Victor Stinner00676d12010-12-27 01:49:31 +000036PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
37 const char *s,
38 const char *filename, /* decoded from the filesystem encoding */
39 int start,
40 PyCompilerFlags *flags,
41 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020042PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
43 const char *s,
44 PyObject *filename,
45 int start,
46 PyCompilerFlags *flags,
47 PyArena *arena);
Victor Stinner00676d12010-12-27 01:49:31 +000048PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
49 FILE *fp,
50 const char *filename, /* decoded from the filesystem encoding */
51 const char* enc,
52 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020053 const char *ps1,
54 const char *ps2,
Victor Stinner00676d12010-12-27 01:49:31 +000055 PyCompilerFlags *flags,
56 int *errcode,
57 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020058PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
59 FILE *fp,
60 PyObject *filename,
61 const char* enc,
62 int start,
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020063 const char *ps1,
64 const char *ps2,
Victor Stinner14e461d2013-08-26 22:28:21 +020065 PyCompilerFlags *flags,
66 int *errcode,
67 PyArena *arena);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000068#endif
69
70#ifndef PyParser_SimpleParseString
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000071#define PyParser_SimpleParseString(S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000072 PyParser_SimpleParseStringFlags(S, B, 0)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000073#define PyParser_SimpleParseFile(FP, S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000074 PyParser_SimpleParseFileFlags(FP, S, B, 0)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000075#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000076PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
Eli Bendersky08131682012-06-03 08:07:47 +030077 int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020078#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
Eli Bendersky08131682012-06-03 08:07:47 +030079PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
80 const char *,
81 int, int);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020082#endif
Martin v. Löwis95292d62002-12-11 14:04:59 +000083PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Eli Bendersky08131682012-06-03 08:07:47 +030084 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000085
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000086#ifndef Py_LIMITED_API
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000087PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
88 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +000089
Victor Stinner00676d12010-12-27 01:49:31 +000090PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
91 FILE *fp,
92 const char *filename, /* decoded from the filesystem encoding */
93 int start,
94 PyObject *globals,
95 PyObject *locals,
96 int closeit,
97 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000098#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000099
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000100#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +0000101PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000102#else
Georg Brandl8334fd92010-12-04 10:26:46 +0000103#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
104#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +0000105PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
106 const char *str,
107 const char *filename, /* decoded from the filesystem encoding */
108 int start,
109 PyCompilerFlags *flags,
110 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +0200111PyAPI_FUNC(PyObject *) Py_CompileStringObject(
112 const char *str,
113 PyObject *filename, int start,
114 PyCompilerFlags *flags,
115 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000116#endif
Victor Stinner00676d12010-12-27 01:49:31 +0000117PyAPI_FUNC(struct symtable *) Py_SymtableString(
118 const char *str,
119 const char *filename, /* decoded from the filesystem encoding */
120 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100121#ifndef Py_LIMITED_API
Victor Stinner14e461d2013-08-26 22:28:21 +0200122PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
123 const char *str,
124 PyObject *filename,
125 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100126#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +0000127
Mark Hammond91a681d2002-08-12 07:21:58 +0000128PyAPI_FUNC(void) PyErr_Print(void);
129PyAPI_FUNC(void) PyErr_PrintEx(int);
130PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +0000131
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000132#ifndef Py_LIMITED_API
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000133/* Use macros for a bunch of old variants */
134#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
135#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
136#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000137 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000138#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000139 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000140#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000141#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
142#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
143#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
144#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
145#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000146 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000147#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000148 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000149#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000150 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000151#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000152
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000153/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000154#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300155PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000156#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000157PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300158PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000159#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000160PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000161#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000162
163/* Stack size, in "pointers" (so we get extra safety margins
164 on 64-bit platforms). On a 32-bit platform, this translates
Martin Panter4c359642016-05-08 13:53:41 +0000165 to an 8k margin. */
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000166#define PYOS_STACK_MARGIN 2048
167
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000168#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000169/* Enable stack checking under Microsoft C */
170#define USE_STACKCHECK
171#endif
172
Jack Jansen275abb32000-08-07 21:00:42 +0000173#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000174/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000175PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000176#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000177
Guido van Rossuma3309961993-07-28 09:05:47 +0000178#ifdef __cplusplus
179}
180#endif
181#endif /* !Py_PYTHONRUN_H */