blob: 3b93a80860040bb6ec3212907fdde1e507a0887a [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);
94PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
95 const char *,
96 int, int);
Martin v. Löwis95292d62002-12-11 14:04:59 +000097PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Eli Bendersky08131682012-06-03 08:07:47 +030098 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000099
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000100#ifndef Py_LIMITED_API
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000101PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
102 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +0000103
Victor Stinner00676d12010-12-27 01:49:31 +0000104PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
105 FILE *fp,
106 const char *filename, /* decoded from the filesystem encoding */
107 int start,
108 PyObject *globals,
109 PyObject *locals,
110 int closeit,
111 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000112#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000113
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000114#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +0000115PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000116#else
Georg Brandl8334fd92010-12-04 10:26:46 +0000117#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
118#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +0000119PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
120 const char *str,
121 const char *filename, /* decoded from the filesystem encoding */
122 int start,
123 PyCompilerFlags *flags,
124 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +0200125PyAPI_FUNC(PyObject *) Py_CompileStringObject(
126 const char *str,
127 PyObject *filename, int start,
128 PyCompilerFlags *flags,
129 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000130#endif
Victor Stinner00676d12010-12-27 01:49:31 +0000131PyAPI_FUNC(struct symtable *) Py_SymtableString(
132 const char *str,
133 const char *filename, /* decoded from the filesystem encoding */
134 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100135#ifndef Py_LIMITED_API
Victor Stinner14e461d2013-08-26 22:28:21 +0200136PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
137 const char *str,
138 PyObject *filename,
139 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100140#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +0000141
Mark Hammond91a681d2002-08-12 07:21:58 +0000142PyAPI_FUNC(void) PyErr_Print(void);
143PyAPI_FUNC(void) PyErr_PrintEx(int);
144PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +0000145
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000146#ifndef Py_LIMITED_API
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000147/* Use macros for a bunch of old variants */
148#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
149#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
150#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000151 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000152#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000153 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000154#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000155#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
156#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
157#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
158#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
159#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000160 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000161#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000162 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000163#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000164 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000165#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000166
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000167/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000168#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300169PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000170#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000171PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300172PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000173#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000174PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000175#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000176
177/* Stack size, in "pointers" (so we get extra safety margins
178 on 64-bit platforms). On a 32-bit platform, this translates
179 to a 8k margin. */
180#define PYOS_STACK_MARGIN 2048
181
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000182#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000183/* Enable stack checking under Microsoft C */
184#define USE_STACKCHECK
185#endif
186
Jack Jansen275abb32000-08-07 21:00:42 +0000187#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000188/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000189PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000190#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000191
Guido van Rossuma3309961993-07-28 09:05:47 +0000192#ifdef __cplusplus
193}
194#endif
195#endif /* !Py_PYTHONRUN_H */