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 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 10 | #ifndef Py_LIMITED_API |
| 11 | PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 12 | PyAPI_FUNC(int) PyRun_AnyFileExFlags( |
| 13 | FILE *fp, |
| 14 | const char *filename, /* decoded from the filesystem encoding */ |
| 15 | int closeit, |
| 16 | PyCompilerFlags *flags); |
| 17 | PyAPI_FUNC(int) PyRun_SimpleFileExFlags( |
| 18 | FILE *fp, |
| 19 | const char *filename, /* decoded from the filesystem encoding */ |
| 20 | int closeit, |
| 21 | PyCompilerFlags *flags); |
| 22 | PyAPI_FUNC(int) PyRun_InteractiveOneFlags( |
| 23 | FILE *fp, |
| 24 | const char *filename, /* decoded from the filesystem encoding */ |
| 25 | PyCompilerFlags *flags); |
Victor Stinner | 95701bd | 2013-11-06 18:41:07 +0100 | [diff] [blame] | 26 | PyAPI_FUNC(int) PyRun_InteractiveOneObject( |
| 27 | FILE *fp, |
| 28 | PyObject *filename, |
| 29 | PyCompilerFlags *flags); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 30 | PyAPI_FUNC(int) PyRun_InteractiveLoopFlags( |
| 31 | FILE *fp, |
| 32 | const char *filename, /* decoded from the filesystem encoding */ |
| 33 | PyCompilerFlags *flags); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 34 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 35 | PyAPI_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 Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 41 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( |
| 42 | const char *s, |
| 43 | PyObject *filename, |
| 44 | int start, |
| 45 | PyCompilerFlags *flags, |
| 46 | PyArena *arena); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 47 | PyAPI_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 Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 52 | const char *ps1, |
| 53 | const char *ps2, |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 54 | PyCompilerFlags *flags, |
| 55 | int *errcode, |
| 56 | PyArena *arena); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 57 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( |
| 58 | FILE *fp, |
| 59 | PyObject *filename, |
| 60 | const char* enc, |
| 61 | int start, |
Serhiy Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 62 | const char *ps1, |
| 63 | const char *ps2, |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 64 | PyCompilerFlags *flags, |
| 65 | int *errcode, |
| 66 | PyArena *arena); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | #ifndef PyParser_SimpleParseString |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 70 | #define PyParser_SimpleParseString(S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 71 | PyParser_SimpleParseStringFlags(S, B, 0) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 72 | #define PyParser_SimpleParseFile(FP, S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 73 | PyParser_SimpleParseFileFlags(FP, S, B, 0) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 74 | #endif |
Pablo Galindo | 5b1a311 | 2020-06-21 21:26:59 +0100 | [diff] [blame] | 75 | |
| 76 | #ifndef Py_BUILD_CORE |
| 77 | Py_DEPRECATED(3.9) |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 78 | #endif |
Pablo Galindo | 5b1a311 | 2020-06-21 21:26:59 +0100 | [diff] [blame] | 79 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, int); |
| 80 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 |
| 81 | #ifndef Py_BUILD_CORE |
| 82 | Py_DEPRECATED(3.9) |
| 83 | #endif |
| 84 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *, |
| 85 | const char *, |
| 86 | int, int); |
| 87 | #endif |
| 88 | #ifndef Py_BUILD_CORE |
| 89 | Py_DEPRECATED(3.9) |
| 90 | #endif |
| 91 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, int, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 92 | #ifndef Py_LIMITED_API |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 93 | PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, |
| 94 | PyObject *, PyCompilerFlags *); |
Guido van Rossum | 5b72218 | 1993-03-30 17:46:03 +0000 | [diff] [blame] | 95 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 96 | PyAPI_FUNC(PyObject *) PyRun_FileExFlags( |
| 97 | FILE *fp, |
| 98 | const char *filename, /* decoded from the filesystem encoding */ |
| 99 | int start, |
| 100 | PyObject *globals, |
| 101 | PyObject *locals, |
| 102 | int closeit, |
| 103 | PyCompilerFlags *flags); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 104 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 105 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 106 | #ifdef Py_LIMITED_API |
Martin v. Löwis | 0d012f2 | 2010-12-04 12:00:49 +0000 | [diff] [blame] | 107 | PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 108 | #else |
Georg Brandl | 8334fd9 | 2010-12-04 10:26:46 +0000 | [diff] [blame] | 109 | #define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1) |
| 110 | #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] | 111 | PyAPI_FUNC(PyObject *) Py_CompileStringExFlags( |
| 112 | const char *str, |
| 113 | const char *filename, /* decoded from the filesystem encoding */ |
| 114 | int start, |
| 115 | PyCompilerFlags *flags, |
| 116 | int optimize); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 117 | PyAPI_FUNC(PyObject *) Py_CompileStringObject( |
| 118 | const char *str, |
| 119 | PyObject *filename, int start, |
| 120 | PyCompilerFlags *flags, |
| 121 | int optimize); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 122 | #endif |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 123 | PyAPI_FUNC(struct symtable *) Py_SymtableString( |
| 124 | const char *str, |
| 125 | const char *filename, /* decoded from the filesystem encoding */ |
| 126 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 127 | #ifndef Py_LIMITED_API |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 128 | PyAPI_FUNC(const char *) _Py_SourceAsString( |
| 129 | PyObject *cmd, |
| 130 | const char *funcname, |
Victor Stinner | 343ed0f | 2019-06-18 00:15:13 +0200 | [diff] [blame] | 131 | const char *what, |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 132 | PyCompilerFlags *cf, |
| 133 | PyObject **cmd_copy); |
| 134 | |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 135 | PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( |
| 136 | const char *str, |
| 137 | PyObject *filename, |
| 138 | int start); |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 139 | |
| 140 | PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags( |
| 141 | const char *str, |
| 142 | PyObject *filename, |
| 143 | int start, |
| 144 | PyCompilerFlags *flags); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 145 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 146 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 147 | PyAPI_FUNC(void) PyErr_Print(void); |
| 148 | PyAPI_FUNC(void) PyErr_PrintEx(int); |
| 149 | PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | c6cf1dd | 1994-09-07 14:35:10 +0000 | [diff] [blame] | 150 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 151 | #ifndef Py_LIMITED_API |
Victor Stinner | 343ed0f | 2019-06-18 00:15:13 +0200 | [diff] [blame] | 152 | /* A function flavor is also exported by libpython. It is required when |
| 153 | libpython is accessed directly rather than using header files which defines |
| 154 | macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to |
| 155 | export functions in pythonXX.dll. */ |
| 156 | PyAPI_FUNC(PyObject *) PyRun_String(const char *str, int s, PyObject *g, PyObject *l); |
| 157 | PyAPI_FUNC(int) PyRun_AnyFile(FILE *fp, const char *name); |
| 158 | PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *fp, const char *name, int closeit); |
| 159 | PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); |
| 160 | PyAPI_FUNC(int) PyRun_SimpleString(const char *s); |
| 161 | PyAPI_FUNC(int) PyRun_SimpleFile(FILE *f, const char *p); |
| 162 | PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *f, const char *p, int c); |
| 163 | PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *f, const char *p); |
| 164 | PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *f, const char *p); |
| 165 | PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l); |
| 166 | PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c); |
| 167 | PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags); |
| 168 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 169 | /* Use macros for a bunch of old variants */ |
| 170 | #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL) |
| 171 | #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL) |
| 172 | #define PyRun_AnyFileEx(fp, name, closeit) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 173 | PyRun_AnyFileExFlags(fp, name, closeit, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 174 | #define PyRun_AnyFileFlags(fp, name, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 175 | PyRun_AnyFileExFlags(fp, name, 0, flags) |
Mark Hammond | f3ddaee | 2005-10-23 10:53:06 +0000 | [diff] [blame] | 176 | #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 177 | #define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL) |
| 178 | #define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL) |
| 179 | #define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL) |
| 180 | #define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL) |
| 181 | #define PyRun_File(fp, p, s, g, l) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 182 | PyRun_FileExFlags(fp, p, s, g, l, 0, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 183 | #define PyRun_FileEx(fp, p, s, g, l, c) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 184 | PyRun_FileExFlags(fp, p, s, g, l, c, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 185 | #define PyRun_FileFlags(fp, p, s, g, l, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 186 | PyRun_FileExFlags(fp, p, s, g, l, 0, flags) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 187 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 188 | |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 189 | /* Stuff with no proper home (yet) */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 190 | #ifndef Py_LIMITED_API |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 191 | PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 192 | #endif |
Mark Hammond | 5d54667 | 2002-08-12 13:06:35 +0000 | [diff] [blame] | 193 | PyAPI_DATA(int) (*PyOS_InputHook)(void); |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 194 | PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 195 | #ifndef Py_LIMITED_API |
Jason Tishler | 0d2a75c | 2004-08-09 15:02:30 +0000 | [diff] [blame] | 196 | PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 197 | #endif |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 198 | |
| 199 | /* Stack size, in "pointers" (so we get extra safety margins |
| 200 | on 64-bit platforms). On a 32-bit platform, this translates |
Martin Panter | 4c35964 | 2016-05-08 13:53:41 +0000 | [diff] [blame] | 201 | to an 8k margin. */ |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 202 | #define PYOS_STACK_MARGIN 2048 |
| 203 | |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 204 | #if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300 |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 205 | /* Enable stack checking under Microsoft C */ |
| 206 | #define USE_STACKCHECK |
| 207 | #endif |
| 208 | |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 209 | #ifdef USE_STACKCHECK |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 210 | /* Check that we aren't overflowing our stack */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 211 | PyAPI_FUNC(int) PyOS_CheckStack(void); |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 212 | #endif |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 213 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 214 | #ifdef __cplusplus |
| 215 | } |
| 216 | #endif |
| 217 | #endif /* !Py_PYTHONRUN_H */ |