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 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 10 | #define PyCF_MASK 0 |
| 11 | #define PyCF_MASK_OBSOLETE 0 |
Just van Rossum | 3aaf42c | 2003-02-10 08:21:10 +0000 | [diff] [blame] | 12 | #define PyCF_SOURCE_IS_UTF8 0x0100 |
Guido van Rossum | 4b499dd3 | 2003-02-13 22:07:59 +0000 | [diff] [blame] | 13 | #define PyCF_DONT_IMPLY_DEDENT 0x0200 |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 14 | #define PyCF_ONLY_AST 0x0400 |
Tim Peters | e2c18e9 | 2001-08-17 20:47:47 +0000 | [diff] [blame] | 15 | |
Jeremy Hylton | 9f324e9 | 2001-03-01 22:59:14 +0000 | [diff] [blame] | 16 | typedef struct { |
Jeremy Hylton | fdd12f6 | 2001-08-10 21:38:04 +0000 | [diff] [blame] | 17 | int cf_flags; /* bitmask of CO_xxx flags relevant to future */ |
Jeremy Hylton | 9f324e9 | 2001-03-01 22:59:14 +0000 | [diff] [blame] | 18 | } PyCompilerFlags; |
| 19 | |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 20 | PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); |
| 21 | PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); |
Guido van Rossum | 66d4b90 | 1998-02-06 22:28:05 +0000 | [diff] [blame] | 22 | |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 23 | PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); |
| 24 | PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 25 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 26 | PyAPI_FUNC(void) Py_Initialize(void); |
Martin v. Löwis | 336e85f | 2004-08-19 11:31:58 +0000 | [diff] [blame] | 27 | PyAPI_FUNC(void) Py_InitializeEx(int); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 28 | PyAPI_FUNC(void) Py_Finalize(void); |
| 29 | PyAPI_FUNC(int) Py_IsInitialized(void); |
| 30 | PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); |
| 31 | PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 32 | |
Martin v. Löwis | 056a69c | 2006-03-01 16:55:42 +0000 | [diff] [blame] | 33 | PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); |
| 34 | PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 35 | PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 37 | PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 38 | PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 39 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 40 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *, |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 41 | int, PyCompilerFlags *flags, |
| 42 | PyArena *); |
Martin v. Löwis | 85bcc66 | 2007-09-04 09:18:06 +0000 | [diff] [blame] | 43 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, |
| 44 | const char*, int, |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 45 | char *, char *, |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 46 | PyCompilerFlags *, int *, |
| 47 | PyArena *); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 48 | #define PyParser_SimpleParseString(S, B) \ |
| 49 | PyParser_SimpleParseStringFlags(S, B, 0) |
| 50 | #define PyParser_SimpleParseFile(FP, S, B) \ |
| 51 | PyParser_SimpleParseFileFlags(FP, S, B, 0) |
| 52 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, |
| 53 | int); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 54 | PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, |
Tim Peters | fe2127d | 2001-07-16 05:37:24 +0000 | [diff] [blame] | 55 | int, int); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 56 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 57 | PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, |
| 58 | PyObject *, PyCompilerFlags *); |
Guido van Rossum | 5b72218 | 1993-03-30 17:46:03 +0000 | [diff] [blame] | 59 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 60 | PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int, |
| 61 | PyObject *, PyObject *, int, |
| 62 | PyCompilerFlags *); |
| 63 | |
| 64 | #define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL) |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 65 | PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int, |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 66 | PyCompilerFlags *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 67 | PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 68 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 69 | PyAPI_FUNC(void) PyErr_Print(void); |
| 70 | PyAPI_FUNC(void) PyErr_PrintEx(int); |
| 71 | PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | c6cf1dd | 1994-09-07 14:35:10 +0000 | [diff] [blame] | 72 | |
Collin Winter | 670e692 | 2007-03-21 02:57:17 +0000 | [diff] [blame] | 73 | /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level |
| 74 | * exit functions. |
| 75 | */ |
| 76 | PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void)); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 77 | PyAPI_FUNC(int) Py_AtExit(void (*func)(void)); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 78 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 79 | PyAPI_FUNC(void) Py_Exit(int); |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 80 | |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 81 | PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); |
Guido van Rossum | 5c4998b | 1997-02-14 19:51:34 +0000 | [diff] [blame] | 82 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 83 | /* Bootstrap */ |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 84 | PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 85 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 86 | /* Use macros for a bunch of old variants */ |
| 87 | #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL) |
| 88 | #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL) |
| 89 | #define PyRun_AnyFileEx(fp, name, closeit) \ |
| 90 | PyRun_AnyFileExFlags(fp, name, closeit, NULL) |
| 91 | #define PyRun_AnyFileFlags(fp, name, flags) \ |
| 92 | PyRun_AnyFileExFlags(fp, name, 0, flags) |
Mark Hammond | f3ddaee | 2005-10-23 10:53:06 +0000 | [diff] [blame] | 93 | #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 94 | #define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL) |
| 95 | #define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL) |
| 96 | #define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL) |
| 97 | #define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL) |
| 98 | #define PyRun_File(fp, p, s, g, l) \ |
| 99 | PyRun_FileExFlags(fp, p, s, g, l, 0, NULL) |
| 100 | #define PyRun_FileEx(fp, p, s, g, l, c) \ |
| 101 | PyRun_FileExFlags(fp, p, s, g, l, c, NULL) |
| 102 | #define PyRun_FileFlags(fp, p, s, g, l, flags) \ |
| 103 | PyRun_FileExFlags(fp, p, s, g, l, 0, flags) |
| 104 | |
Guido van Rossum | 57d8e3f | 1997-07-19 19:50:52 +0000 | [diff] [blame] | 105 | /* In getpath.c */ |
Martin v. Löwis | 790465f | 2008-04-05 20:41:37 +0000 | [diff] [blame] | 106 | PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); |
| 107 | PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); |
| 108 | PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); |
| 109 | PyAPI_FUNC(wchar_t *) Py_GetPath(void); |
Guido van Rossum | 57d8e3f | 1997-07-19 19:50:52 +0000 | [diff] [blame] | 110 | |
| 111 | /* In their own files */ |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 112 | PyAPI_FUNC(const char *) Py_GetVersion(void); |
| 113 | PyAPI_FUNC(const char *) Py_GetPlatform(void); |
| 114 | PyAPI_FUNC(const char *) Py_GetCopyright(void); |
| 115 | PyAPI_FUNC(const char *) Py_GetCompiler(void); |
| 116 | PyAPI_FUNC(const char *) Py_GetBuildInfo(void); |
Martin v. Löwis | 43b5780 | 2006-01-05 23:38:54 +0000 | [diff] [blame] | 117 | PyAPI_FUNC(const char *) _Py_svnversion(void); |
| 118 | PyAPI_FUNC(const char *) Py_SubversionRevision(void); |
| 119 | PyAPI_FUNC(const char *) Py_SubversionShortBranch(void); |
Guido van Rossum | 57d8e3f | 1997-07-19 19:50:52 +0000 | [diff] [blame] | 120 | |
Guido van Rossum | 29e46a9 | 1997-08-02 02:56:48 +0000 | [diff] [blame] | 121 | /* Internal -- various one-time initializations */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 122 | PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); |
| 123 | PyAPI_FUNC(PyObject *) _PySys_Init(void); |
| 124 | PyAPI_FUNC(void) _PyImport_Init(void); |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 125 | PyAPI_FUNC(void) _PyExc_Init(void); |
Just van Rossum | 52e14d6 | 2002-12-30 22:08:05 +0000 | [diff] [blame] | 126 | PyAPI_FUNC(void) _PyImportHooks_Init(void); |
Neal Norwitz | b2501f4 | 2002-12-31 03:42:13 +0000 | [diff] [blame] | 127 | PyAPI_FUNC(int) _PyFrame_Init(void); |
Michael W. Hudson | ba283e2 | 2005-05-27 15:23:20 +0000 | [diff] [blame] | 128 | PyAPI_FUNC(void) _PyFloat_Init(void); |
Christian Heimes | 9c4756e | 2008-05-26 13:22:05 +0000 | [diff] [blame] | 129 | PyAPI_FUNC(int) PyByteArray_Init(void); |
Guido van Rossum | 29e46a9 | 1997-08-02 02:56:48 +0000 | [diff] [blame] | 130 | |
Guido van Rossum | 8e5e446 | 1997-08-12 14:57:21 +0000 | [diff] [blame] | 131 | /* Various internal finalizers */ |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 132 | PyAPI_FUNC(void) _PyExc_Fini(void); |
| 133 | PyAPI_FUNC(void) _PyImport_Fini(void); |
| 134 | PyAPI_FUNC(void) PyMethod_Fini(void); |
| 135 | PyAPI_FUNC(void) PyFrame_Fini(void); |
| 136 | PyAPI_FUNC(void) PyCFunction_Fini(void); |
Christian Heimes | 77c02eb | 2008-02-09 02:18:51 +0000 | [diff] [blame] | 137 | PyAPI_FUNC(void) PyDict_Fini(void); |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 138 | PyAPI_FUNC(void) PyTuple_Fini(void); |
Raymond Hettinger | fb09f0e | 2004-10-07 03:58:07 +0000 | [diff] [blame] | 139 | PyAPI_FUNC(void) PyList_Fini(void); |
Raymond Hettinger | d794666 | 2005-08-01 21:39:29 +0000 | [diff] [blame] | 140 | PyAPI_FUNC(void) PySet_Fini(void); |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 141 | PyAPI_FUNC(void) PyBytes_Fini(void); |
Christian Heimes | 9c4756e | 2008-05-26 13:22:05 +0000 | [diff] [blame] | 142 | PyAPI_FUNC(void) PyByteArray_Fini(void); |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 143 | PyAPI_FUNC(void) PyFloat_Fini(void); |
| 144 | PyAPI_FUNC(void) PyOS_FiniInterrupts(void); |
Guido van Rossum | 8e5e446 | 1997-08-12 14:57:21 +0000 | [diff] [blame] | 145 | |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 146 | /* Stuff with no proper home (yet) */ |
Martin v. Löwis | 566f6af | 2002-10-26 14:39:10 +0000 | [diff] [blame] | 147 | PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *); |
Mark Hammond | 5d54667 | 2002-08-12 13:06:35 +0000 | [diff] [blame] | 148 | PyAPI_DATA(int) (*PyOS_InputHook)(void); |
Martin v. Löwis | 566f6af | 2002-10-26 14:39:10 +0000 | [diff] [blame] | 149 | PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); |
Jason Tishler | 0d2a75c | 2004-08-09 15:02:30 +0000 | [diff] [blame] | 150 | PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 151 | |
| 152 | /* Stack size, in "pointers" (so we get extra safety margins |
| 153 | on 64-bit platforms). On a 32-bit platform, this translates |
| 154 | to a 8k margin. */ |
| 155 | #define PYOS_STACK_MARGIN 2048 |
| 156 | |
Trent Mick | 0a7af40 | 2000-10-11 17:18:11 +0000 | [diff] [blame] | 157 | #if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 158 | /* Enable stack checking under Microsoft C */ |
| 159 | #define USE_STACKCHECK |
| 160 | #endif |
| 161 | |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 162 | #ifdef USE_STACKCHECK |
Fredrik Lundh | 2f15b25 | 2000-08-27 19:15:31 +0000 | [diff] [blame] | 163 | /* Check that we aren't overflowing our stack */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 164 | PyAPI_FUNC(int) PyOS_CheckStack(void); |
Jack Jansen | 275abb3 | 2000-08-07 21:00:42 +0000 | [diff] [blame] | 165 | #endif |
Guido van Rossum | 3fb1aea | 1997-08-12 15:14:22 +0000 | [diff] [blame] | 166 | |
Guido van Rossum | c7247ce | 2000-09-16 16:31:31 +0000 | [diff] [blame] | 167 | /* Signals */ |
| 168 | typedef void (*PyOS_sighandler_t)(int); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 169 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); |
| 170 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); |
Guido van Rossum | c7247ce | 2000-09-16 16:31:31 +0000 | [diff] [blame] | 171 | |
| 172 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 173 | #ifdef __cplusplus |
| 174 | } |
| 175 | #endif |
| 176 | #endif /* !Py_PYTHONRUN_H */ |