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 *); |
Martin v. Löwis | 056a69c | 2006-03-01 16:55:42 +0000 | [diff] [blame] | 12 | PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 13 | PyAPI_FUNC(int) PyRun_AnyFileExFlags( |
| 14 | FILE *fp, |
| 15 | const char *filename, /* decoded from the filesystem encoding */ |
| 16 | int closeit, |
| 17 | PyCompilerFlags *flags); |
| 18 | PyAPI_FUNC(int) PyRun_SimpleFileExFlags( |
| 19 | FILE *fp, |
| 20 | const char *filename, /* decoded from the filesystem encoding */ |
| 21 | int closeit, |
| 22 | PyCompilerFlags *flags); |
| 23 | PyAPI_FUNC(int) PyRun_InteractiveOneFlags( |
| 24 | FILE *fp, |
| 25 | const char *filename, /* decoded from the filesystem encoding */ |
| 26 | PyCompilerFlags *flags); |
Victor Stinner | 95701bd | 2013-11-06 18:41:07 +0100 | [diff] [blame] | 27 | PyAPI_FUNC(int) PyRun_InteractiveOneObject( |
| 28 | FILE *fp, |
| 29 | PyObject *filename, |
| 30 | PyCompilerFlags *flags); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 31 | PyAPI_FUNC(int) PyRun_InteractiveLoopFlags( |
| 32 | FILE *fp, |
| 33 | const char *filename, /* decoded from the filesystem encoding */ |
| 34 | PyCompilerFlags *flags); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 36 | PyAPI_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 Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 42 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( |
| 43 | const char *s, |
| 44 | PyObject *filename, |
| 45 | int start, |
| 46 | PyCompilerFlags *flags, |
| 47 | PyArena *arena); |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 48 | PyAPI_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 Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 53 | const char *ps1, |
| 54 | const char *ps2, |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 55 | PyCompilerFlags *flags, |
| 56 | int *errcode, |
| 57 | PyArena *arena); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 58 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( |
| 59 | FILE *fp, |
| 60 | PyObject *filename, |
| 61 | const char* enc, |
| 62 | int start, |
Serhiy Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 63 | const char *ps1, |
| 64 | const char *ps2, |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 65 | PyCompilerFlags *flags, |
| 66 | int *errcode, |
| 67 | PyArena *arena); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | #ifndef PyParser_SimpleParseString |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 71 | #define PyParser_SimpleParseString(S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 72 | PyParser_SimpleParseStringFlags(S, B, 0) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 73 | #define PyParser_SimpleParseFile(FP, S, B) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 74 | PyParser_SimpleParseFileFlags(FP, S, B, 0) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 75 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 76 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 77 | int); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 78 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 79 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *, |
| 80 | const char *, |
| 81 | int, int); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 82 | #endif |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 83 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, |
Eli Bendersky | 0813168 | 2012-06-03 08:07:47 +0300 | [diff] [blame] | 84 | int, int); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 85 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 86 | #ifndef Py_LIMITED_API |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 87 | PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, |
| 88 | PyObject *, PyCompilerFlags *); |
Guido van Rossum | 5b72218 | 1993-03-30 17:46:03 +0000 | [diff] [blame] | 89 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 90 | PyAPI_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öwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 98 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 99 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 100 | #ifdef Py_LIMITED_API |
Martin v. Löwis | 0d012f2 | 2010-12-04 12:00:49 +0000 | [diff] [blame] | 101 | PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 102 | #else |
Georg Brandl | 8334fd9 | 2010-12-04 10:26:46 +0000 | [diff] [blame] | 103 | #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 Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 105 | PyAPI_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 Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 111 | PyAPI_FUNC(PyObject *) Py_CompileStringObject( |
| 112 | const char *str, |
| 113 | PyObject *filename, int start, |
| 114 | PyCompilerFlags *flags, |
| 115 | int optimize); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 116 | #endif |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 117 | PyAPI_FUNC(struct symtable *) Py_SymtableString( |
| 118 | const char *str, |
| 119 | const char *filename, /* decoded from the filesystem encoding */ |
| 120 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 121 | #ifndef Py_LIMITED_API |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 122 | PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( |
| 123 | const char *str, |
| 124 | PyObject *filename, |
| 125 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 126 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 127 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 128 | PyAPI_FUNC(void) PyErr_Print(void); |
| 129 | PyAPI_FUNC(void) PyErr_PrintEx(int); |
| 130 | PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | c6cf1dd | 1994-09-07 14:35:10 +0000 | [diff] [blame] | 131 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 132 | #ifndef Py_LIMITED_API |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 133 | /* 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 Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 137 | PyRun_AnyFileExFlags(fp, name, closeit, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 138 | #define PyRun_AnyFileFlags(fp, name, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 139 | PyRun_AnyFileExFlags(fp, name, 0, flags) |
Mark Hammond | f3ddaee | 2005-10-23 10:53:06 +0000 | [diff] [blame] | 140 | #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 141 | #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 Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 146 | PyRun_FileExFlags(fp, p, s, g, l, 0, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 147 | #define PyRun_FileEx(fp, p, s, g, l, c) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 148 | PyRun_FileExFlags(fp, p, s, g, l, c, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 149 | #define PyRun_FileFlags(fp, p, s, g, l, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 150 | PyRun_FileExFlags(fp, p, s, g, l, 0, flags) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 151 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 152 | |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 153 | /* Stuff with no proper home (yet) */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 154 | #ifndef Py_LIMITED_API |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 155 | PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 156 | #endif |
Mark Hammond | 5d54667 | 2002-08-12 13:06:35 +0000 | [diff] [blame] | 157 | PyAPI_DATA(int) (*PyOS_InputHook)(void); |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 158 | PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 159 | #ifndef Py_LIMITED_API |
Jason Tishler | 0d2a75c | 2004-08-09 15:02:30 +0000 | [diff] [blame] | 160 | PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 161 | #endif |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 162 | |
| 163 | /* Stack size, in "pointers" (so we get extra safety margins |
| 164 | on 64-bit platforms). On a 32-bit platform, this translates |
Martin Panter | 4c35964 | 2016-05-08 13:53:41 +0000 | [diff] [blame] | 165 | to an 8k margin. */ |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 166 | #define PYOS_STACK_MARGIN 2048 |
| 167 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 168 | #if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300 |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 169 | /* Enable stack checking under Microsoft C */ |
| 170 | #define USE_STACKCHECK |
| 171 | #endif |
| 172 | |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 173 | #ifdef USE_STACKCHECK |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 174 | /* Check that we aren't overflowing our stack */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 175 | PyAPI_FUNC(int) PyOS_CheckStack(void); |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 176 | #endif |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 177 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 178 | #ifdef __cplusplus |
| 179 | } |
| 180 | #endif |
| 181 | #endif /* !Py_PYTHONRUN_H */ |