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 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 35 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, |
| 37 | PyObject *, PyCompilerFlags *); |
Guido van Rossum | 5b72218 | 1993-03-30 17:46:03 +0000 | [diff] [blame] | 38 | |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 39 | PyAPI_FUNC(PyObject *) PyRun_FileExFlags( |
| 40 | FILE *fp, |
| 41 | const char *filename, /* decoded from the filesystem encoding */ |
| 42 | int start, |
| 43 | PyObject *globals, |
| 44 | PyObject *locals, |
| 45 | int closeit, |
| 46 | PyCompilerFlags *flags); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 47 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 48 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 49 | #ifdef Py_LIMITED_API |
Martin v. Löwis | 0d012f2 | 2010-12-04 12:00:49 +0000 | [diff] [blame] | 50 | PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 51 | #else |
Georg Brandl | 8334fd9 | 2010-12-04 10:26:46 +0000 | [diff] [blame] | 52 | #define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1) |
| 53 | #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] | 54 | PyAPI_FUNC(PyObject *) Py_CompileStringExFlags( |
| 55 | const char *str, |
| 56 | const char *filename, /* decoded from the filesystem encoding */ |
| 57 | int start, |
| 58 | PyCompilerFlags *flags, |
| 59 | int optimize); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 60 | PyAPI_FUNC(PyObject *) Py_CompileStringObject( |
| 61 | const char *str, |
| 62 | PyObject *filename, int start, |
| 63 | PyCompilerFlags *flags, |
| 64 | int optimize); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 65 | #endif |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 66 | PyAPI_FUNC(struct symtable *) Py_SymtableString( |
| 67 | const char *str, |
| 68 | const char *filename, /* decoded from the filesystem encoding */ |
| 69 | int start); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 70 | #ifndef Py_LIMITED_API |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 71 | PyAPI_FUNC(const char *) _Py_SourceAsString( |
| 72 | PyObject *cmd, |
| 73 | const char *funcname, |
Victor Stinner | 343ed0f | 2019-06-18 00:15:13 +0200 | [diff] [blame] | 74 | const char *what, |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 75 | PyCompilerFlags *cf, |
| 76 | PyObject **cmd_copy); |
| 77 | |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 78 | PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( |
| 79 | const char *str, |
| 80 | PyObject *filename, |
| 81 | int start); |
Dino Viehland | 4154069 | 2019-05-28 16:21:17 -0700 | [diff] [blame] | 82 | |
| 83 | PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags( |
| 84 | const char *str, |
| 85 | PyObject *filename, |
| 86 | int start, |
| 87 | PyCompilerFlags *flags); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 88 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 89 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 90 | PyAPI_FUNC(void) PyErr_Print(void); |
| 91 | PyAPI_FUNC(void) PyErr_PrintEx(int); |
| 92 | PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | c6cf1dd | 1994-09-07 14:35:10 +0000 | [diff] [blame] | 93 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 94 | #ifndef Py_LIMITED_API |
Victor Stinner | 343ed0f | 2019-06-18 00:15:13 +0200 | [diff] [blame] | 95 | /* A function flavor is also exported by libpython. It is required when |
| 96 | libpython is accessed directly rather than using header files which defines |
| 97 | macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to |
| 98 | export functions in pythonXX.dll. */ |
| 99 | PyAPI_FUNC(PyObject *) PyRun_String(const char *str, int s, PyObject *g, PyObject *l); |
| 100 | PyAPI_FUNC(int) PyRun_AnyFile(FILE *fp, const char *name); |
| 101 | PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *fp, const char *name, int closeit); |
| 102 | PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); |
| 103 | PyAPI_FUNC(int) PyRun_SimpleString(const char *s); |
| 104 | PyAPI_FUNC(int) PyRun_SimpleFile(FILE *f, const char *p); |
| 105 | PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *f, const char *p, int c); |
| 106 | PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *f, const char *p); |
| 107 | PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *f, const char *p); |
| 108 | PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l); |
| 109 | PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c); |
| 110 | PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags); |
| 111 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 112 | /* Use macros for a bunch of old variants */ |
| 113 | #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL) |
| 114 | #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL) |
| 115 | #define PyRun_AnyFileEx(fp, name, closeit) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 116 | PyRun_AnyFileExFlags(fp, name, closeit, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 117 | #define PyRun_AnyFileFlags(fp, name, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 118 | PyRun_AnyFileExFlags(fp, name, 0, flags) |
Mark Hammond | f3ddaee | 2005-10-23 10:53:06 +0000 | [diff] [blame] | 119 | #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 120 | #define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL) |
| 121 | #define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL) |
| 122 | #define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL) |
| 123 | #define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL) |
| 124 | #define PyRun_File(fp, p, s, g, l) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 125 | PyRun_FileExFlags(fp, p, s, g, l, 0, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 126 | #define PyRun_FileEx(fp, p, s, g, l, c) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 127 | PyRun_FileExFlags(fp, p, s, g, l, c, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 128 | #define PyRun_FileFlags(fp, p, s, g, l, flags) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 129 | PyRun_FileExFlags(fp, p, s, g, l, 0, flags) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 130 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 131 | |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 132 | /* Stuff with no proper home (yet) */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 133 | #ifndef Py_LIMITED_API |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 134 | PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 135 | #endif |
Mark Hammond | 5d54667 | 2002-08-12 13:06:35 +0000 | [diff] [blame] | 136 | PyAPI_DATA(int) (*PyOS_InputHook)(void); |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 137 | PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 138 | #ifndef Py_LIMITED_API |
Jason Tishler | 0d2a75c | 2004-08-09 15:02:30 +0000 | [diff] [blame] | 139 | PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 140 | #endif |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 141 | |
| 142 | /* Stack size, in "pointers" (so we get extra safety margins |
| 143 | on 64-bit platforms). On a 32-bit platform, this translates |
Martin Panter | 4c35964 | 2016-05-08 13:53:41 +0000 | [diff] [blame] | 144 | to an 8k margin. */ |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 145 | #define PYOS_STACK_MARGIN 2048 |
| 146 | |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 147 | #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] | 148 | /* Enable stack checking under Microsoft C */ |
| 149 | #define USE_STACKCHECK |
| 150 | #endif |
| 151 | |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 152 | #ifdef USE_STACKCHECK |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 153 | /* Check that we aren't overflowing our stack */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 154 | PyAPI_FUNC(int) PyOS_CheckStack(void); |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 155 | #endif |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 156 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 157 | #ifdef __cplusplus |
| 158 | } |
| 159 | #endif |
| 160 | #endif /* !Py_PYTHONRUN_H */ |