Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 2 | /* Interfaces to parse and execute pieces of python code */ |
| 3 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 4 | #ifndef Py_PYTHONRUN_H |
| 5 | #define Py_PYTHONRUN_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
Guido van Rossum | 57d8e3f | 1997-07-19 19:50:52 +0000 | [diff] [blame] | 9 | |
Benjamin Peterson | 466a782 | 2009-07-02 21:44:01 +0000 | [diff] [blame] | 10 | #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \ |
| 11 | CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \ |
Yury Selivanov | 8170e8c | 2015-05-09 11:44:30 -0400 | [diff] [blame] | 12 | CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \ |
| 13 | CO_FUTURE_GENERATOR_STOP) |
Benjamin Peterson | ffeaa88 | 2009-07-02 21:54:36 +0000 | [diff] [blame] | 14 | #define PyCF_MASK_OBSOLETE (CO_NESTED) |
Just van Rossum | 3aaf42c | 2003-02-10 08:21:10 +0000 | [diff] [blame] | 15 | #define PyCF_SOURCE_IS_UTF8 0x0100 |
Guido van Rossum | 4b499dd3 | 2003-02-13 22:07:59 +0000 | [diff] [blame] | 16 | #define PyCF_DONT_IMPLY_DEDENT 0x0200 |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | #define PyCF_ONLY_AST 0x0400 |
Benjamin Peterson | f5b5224 | 2009-03-02 23:31:26 +0000 | [diff] [blame] | 18 | #define PyCF_IGNORE_COOKIE 0x0800 |
Tim Peters | e2c18e9 | 2001-08-17 20:47:47 +0000 | [diff] [blame] | 19 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 20 | #ifndef Py_LIMITED_API |
Jeremy Hylton | 9f324e9 | 2001-03-01 22:59:14 +0000 | [diff] [blame] | 21 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 22 | int cf_flags; /* bitmask of CO_xxx flags relevant to future */ |
Jeremy Hylton | 9f324e9 | 2001-03-01 22:59:14 +0000 | [diff] [blame] | 23 | } PyCompilerFlags; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 24 | #endif |
Jeremy Hylton | 9f324e9 | 2001-03-01 22:59:14 +0000 | [diff] [blame] | 25 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 26 | #ifndef Py_LIMITED_API |
| 27 | PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); |
Martin v. Löwis | 056a69c | 2006-03-01 16:55:42 +0000 | [diff] [blame] | 28 | PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 29 | PyAPI_FUNC(int) PyRun_AnyFileExFlags( |
| 30 | FILE *fp, |
| 31 | const char *filename, /* decoded from the filesystem encoding */ |
| 32 | int closeit, |
| 33 | PyCompilerFlags *flags); |
| 34 | PyAPI_FUNC(int) PyRun_SimpleFileExFlags( |
| 35 | FILE *fp, |
| 36 | const char *filename, /* decoded from the filesystem encoding */ |
| 37 | int closeit, |
| 38 | PyCompilerFlags *flags); |
| 39 | PyAPI_FUNC(int) PyRun_InteractiveOneFlags( |
| 40 | FILE *fp, |
| 41 | const char *filename, /* decoded from the filesystem encoding */ |
| 42 | PyCompilerFlags *flags); |
Victor Stinner | 95701bd | 2013-11-06 18:41:07 +0100 | [diff] [blame] | 43 | PyAPI_FUNC(int) PyRun_InteractiveOneObject( |
| 44 | FILE *fp, |
| 45 | PyObject *filename, |
| 46 | PyCompilerFlags *flags); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 47 | PyAPI_FUNC(int) PyRun_InteractiveLoopFlags( |
| 48 | FILE *fp, |
| 49 | const char *filename, /* decoded from the filesystem encoding */ |
| 50 | PyCompilerFlags *flags); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 51 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 52 | PyAPI_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 Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 58 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( |
| 59 | const char *s, |
| 60 | PyObject *filename, |
| 61 | int start, |
| 62 | PyCompilerFlags *flags, |
| 63 | PyArena *arena); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 64 | PyAPI_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 Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 69 | const char *ps1, |
| 70 | const char *ps2, |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 71 | PyCompilerFlags *flags, |
| 72 | int *errcode, |
| 73 | PyArena *arena); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 74 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( |
| 75 | FILE *fp, |
| 76 | PyObject *filename, |
| 77 | const char* enc, |
| 78 | int start, |
Serhiy Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 79 | const char *ps1, |
| 80 | const char *ps2, |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 81 | PyCompilerFlags *flags, |
| 82 | int *errcode, |
| 83 | PyArena *arena); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | #ifndef PyParser_SimpleParseString |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 87 | #define PyParser_SimpleParseString(S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 88 | PyParser_SimpleParseStringFlags(S, B, 0) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 89 | #define PyParser_SimpleParseFile(FP, S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 90 | PyParser_SimpleParseFileFlags(FP, S, B, 0) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 91 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 92 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 93 | int); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 94 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 95 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *, |
| 96 | const char *, |
| 97 | int, int); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 98 | #endif |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 99 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 100 | int, int); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 101 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 102 | #ifndef Py_LIMITED_API |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 103 | PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, |
| 104 | PyObject *, PyCompilerFlags *); |
Guido van Rossum | 5b72218 | 1993-03-30 17:46:03 +0000 | [diff] [blame] | 105 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 106 | PyAPI_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öwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 114 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 115 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 116 | #ifdef Py_LIMITED_API |
Martin v. Löwis | 0d012f2 | 2010-12-04 12:00:49 +0000 | [diff] [blame] | 117 | PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 118 | #else |
Georg Brandl | 8334fd9 | 2010-12-04 10:26:46 +0000 | [diff] [blame] | 119 | #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 Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 121 | PyAPI_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 Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 127 | PyAPI_FUNC(PyObject *) Py_CompileStringObject( |
| 128 | const char *str, |
| 129 | PyObject *filename, int start, |
| 130 | PyCompilerFlags *flags, |
| 131 | int optimize); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 132 | #endif |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 133 | PyAPI_FUNC(struct symtable *) Py_SymtableString( |
| 134 | const char *str, |
| 135 | const char *filename, /* decoded from the filesystem encoding */ |
| 136 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 137 | #ifndef Py_LIMITED_API |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 138 | PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( |
| 139 | const char *str, |
| 140 | PyObject *filename, |
| 141 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 142 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 143 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 144 | PyAPI_FUNC(void) PyErr_Print(void); |
| 145 | PyAPI_FUNC(void) PyErr_PrintEx(int); |
| 146 | PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | c6cf1dd | 1994-09-07 14:35:10 +0000 | [diff] [blame] | 147 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 148 | #ifndef Py_LIMITED_API |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 149 | /* 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 Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 153 | PyRun_AnyFileExFlags(fp, name, closeit, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 154 | #define PyRun_AnyFileFlags(fp, name, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 155 | PyRun_AnyFileExFlags(fp, name, 0, flags) |
Mark Hammond | f3ddaee | 2005-10-23 10:53:06 +0000 | [diff] [blame] | 156 | #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 157 | #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 Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 162 | PyRun_FileExFlags(fp, p, s, g, l, 0, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 163 | #define PyRun_FileEx(fp, p, s, g, l, c) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 164 | PyRun_FileExFlags(fp, p, s, g, l, c, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 165 | #define PyRun_FileFlags(fp, p, s, g, l, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 166 | PyRun_FileExFlags(fp, p, s, g, l, 0, flags) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 167 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 168 | |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 169 | /* Stuff with no proper home (yet) */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 170 | #ifndef Py_LIMITED_API |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 171 | PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 172 | #endif |
Mark Hammond | 5d54667 | 2002-08-12 13:06:35 +0000 | [diff] [blame] | 173 | PyAPI_DATA(int) (*PyOS_InputHook)(void); |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 174 | PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 175 | #ifndef Py_LIMITED_API |
Jason Tishler | 0d2a75c | 2004-08-09 15:02:30 +0000 | [diff] [blame] | 176 | PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 177 | #endif |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 178 | |
| 179 | /* Stack size, in "pointers" (so we get extra safety margins |
| 180 | on 64-bit platforms). On a 32-bit platform, this translates |
Martin Panter | 4c35964 | 2016-05-08 13:53:41 +0000 | [diff] [blame] | 181 | to an 8k margin. */ |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 182 | #define PYOS_STACK_MARGIN 2048 |
| 183 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 184 | #if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300 |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 185 | /* Enable stack checking under Microsoft C */ |
| 186 | #define USE_STACKCHECK |
| 187 | #endif |
| 188 | |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 189 | #ifdef USE_STACKCHECK |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 190 | /* Check that we aren't overflowing our stack */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 191 | PyAPI_FUNC(int) PyOS_CheckStack(void); |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 192 | #endif |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 193 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 194 | #ifdef __cplusplus |
| 195 | } |
| 196 | #endif |
| 197 | #endif /* !Py_PYTHONRUN_H */ |