blob: 1d9b71beaa97d5fc99f1b44b498c88e159c8798c [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 | \
12 CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL)
Benjamin Petersonffeaa882009-07-02 21:54:36 +000013#define PyCF_MASK_OBSOLETE (CO_NESTED)
Just van Rossum3aaf42c2003-02-10 08:21:10 +000014#define PyCF_SOURCE_IS_UTF8 0x0100
Guido van Rossum4b499dd32003-02-13 22:07:59 +000015#define PyCF_DONT_IMPLY_DEDENT 0x0200
Martin v. Löwisbd260da2006-02-26 19:42:26 +000016#define PyCF_ONLY_AST 0x0400
Benjamin Petersonf5b52242009-03-02 23:31:26 +000017#define PyCF_IGNORE_COOKIE 0x0800
Tim Peterse2c18e92001-08-17 20:47:47 +000018
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000019#ifndef Py_LIMITED_API
Jeremy Hylton9f324e92001-03-01 22:59:14 +000020typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000021 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Jeremy Hylton9f324e92001-03-01 22:59:14 +000022} PyCompilerFlags;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000023#endif
Jeremy Hylton9f324e92001-03-01 22:59:14 +000024
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000025#ifndef Py_LIMITED_API
26PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Martin v. Löwis056a69c2006-03-01 16:55:42 +000027PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
Victor Stinner00676d12010-12-27 01:49:31 +000028PyAPI_FUNC(int) PyRun_AnyFileExFlags(
29 FILE *fp,
30 const char *filename, /* decoded from the filesystem encoding */
31 int closeit,
32 PyCompilerFlags *flags);
33PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
34 FILE *fp,
35 const char *filename, /* decoded from the filesystem encoding */
36 int closeit,
37 PyCompilerFlags *flags);
38PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
39 FILE *fp,
40 const char *filename, /* decoded from the filesystem encoding */
41 PyCompilerFlags *flags);
Victor Stinner95701bd2013-11-06 18:41:07 +010042PyAPI_FUNC(int) PyRun_InteractiveOneObject(
43 FILE *fp,
44 PyObject *filename,
45 PyCompilerFlags *flags);
Victor Stinner00676d12010-12-27 01:49:31 +000046PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
47 FILE *fp,
48 const char *filename, /* decoded from the filesystem encoding */
49 PyCompilerFlags *flags);
Guido van Rossum3f5da241990-12-20 15:06:42 +000050
Victor Stinner00676d12010-12-27 01:49:31 +000051PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
52 const char *s,
53 const char *filename, /* decoded from the filesystem encoding */
54 int start,
55 PyCompilerFlags *flags,
56 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020057PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
58 const char *s,
59 PyObject *filename,
60 int start,
61 PyCompilerFlags *flags,
62 PyArena *arena);
Victor Stinner00676d12010-12-27 01:49:31 +000063PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
64 FILE *fp,
65 const char *filename, /* decoded from the filesystem encoding */
66 const char* enc,
67 int start,
68 char *ps1,
69 char *ps2,
70 PyCompilerFlags *flags,
71 int *errcode,
72 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020073PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
74 FILE *fp,
75 PyObject *filename,
76 const char* enc,
77 int start,
78 char *ps1,
79 char *ps2,
80 PyCompilerFlags *flags,
81 int *errcode,
82 PyArena *arena);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000083#endif
84
85#ifndef PyParser_SimpleParseString
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000086#define PyParser_SimpleParseString(S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000087 PyParser_SimpleParseStringFlags(S, B, 0)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000088#define PyParser_SimpleParseFile(FP, S, B) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000089 PyParser_SimpleParseFileFlags(FP, S, B, 0)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000090#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000091PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
Eli Bendersky08131682012-06-03 08:07:47 +030092 int);
93PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
94 const char *,
95 int, int);
Martin v. Löwis95292d62002-12-11 14:04:59 +000096PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
Eli Bendersky08131682012-06-03 08:07:47 +030097 int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000098
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000099#ifndef Py_LIMITED_API
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000100PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
101 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +0000102
Victor Stinner00676d12010-12-27 01:49:31 +0000103PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
104 FILE *fp,
105 const char *filename, /* decoded from the filesystem encoding */
106 int start,
107 PyObject *globals,
108 PyObject *locals,
109 int closeit,
110 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000111#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000112
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000113#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +0000114PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000115#else
Georg Brandl8334fd92010-12-04 10:26:46 +0000116#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
117#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +0000118PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
119 const char *str,
120 const char *filename, /* decoded from the filesystem encoding */
121 int start,
122 PyCompilerFlags *flags,
123 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +0200124PyAPI_FUNC(PyObject *) Py_CompileStringObject(
125 const char *str,
126 PyObject *filename, int start,
127 PyCompilerFlags *flags,
128 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000129#endif
Victor Stinner00676d12010-12-27 01:49:31 +0000130PyAPI_FUNC(struct symtable *) Py_SymtableString(
131 const char *str,
132 const char *filename, /* decoded from the filesystem encoding */
133 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100134#ifndef Py_LIMITED_API
Victor Stinner14e461d2013-08-26 22:28:21 +0200135PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
136 const char *str,
137 PyObject *filename,
138 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100139#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +0000140
Mark Hammond91a681d2002-08-12 07:21:58 +0000141PyAPI_FUNC(void) PyErr_Print(void);
142PyAPI_FUNC(void) PyErr_PrintEx(int);
143PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +0000144
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000145#ifndef Py_LIMITED_API
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000146/* Use macros for a bunch of old variants */
147#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
148#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
149#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000150 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000151#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000152 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000153#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000154#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
155#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
156#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
157#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
158#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000159 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000160#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000161 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000162#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000163 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000164#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000165
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000166/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000167#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300168PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000169#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000170PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300171PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000172#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000173PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000174#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000175
176/* Stack size, in "pointers" (so we get extra safety margins
177 on 64-bit platforms). On a 32-bit platform, this translates
178 to a 8k margin. */
179#define PYOS_STACK_MARGIN 2048
180
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000181#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000182/* Enable stack checking under Microsoft C */
183#define USE_STACKCHECK
184#endif
185
Jack Jansen275abb32000-08-07 21:00:42 +0000186#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000187/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000188PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000189#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000190
Guido van Rossuma3309961993-07-28 09:05:47 +0000191#ifdef __cplusplus
192}
193#endif
194#endif /* !Py_PYTHONRUN_H */