pythonrun.h 8.79 KB
Newer Older
1

Guido van Rossum's avatar
Guido van Rossum committed
2 3
/* Interfaces to parse and execute pieces of python code */

4 5 6 7 8 9
#ifndef Py_PYTHONRUN_H
#define Py_PYTHONRUN_H
#ifdef __cplusplus
extern "C" {
#endif

10 11 12
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
                   CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL)
13
#define PyCF_MASK_OBSOLETE (CO_NESTED)
14
#define PyCF_SOURCE_IS_UTF8  0x0100
15
#define PyCF_DONT_IMPLY_DEDENT 0x0200
16
#define PyCF_ONLY_AST 0x0400
17
#define PyCF_IGNORE_COOKIE 0x0800
18

19
#ifndef Py_LIMITED_API
20
typedef struct {
21
    int cf_flags;  /* bitmask of CO_xxx flags relevant to future */
22
} PyCompilerFlags;
23
#endif
24

25 26
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
27

28 29
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
30 31

PyAPI_FUNC(void) Py_Initialize(void);
32
PyAPI_FUNC(void) Py_InitializeEx(int);
33 34 35
#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int);
#endif
36 37 38 39 40
PyAPI_FUNC(void) Py_Finalize(void);
PyAPI_FUNC(int) Py_IsInitialized(void);
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);

41 42
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
43
PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
PyAPI_FUNC(int) PyRun_AnyFileExFlags(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    int closeit,
    PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    int closeit,
    PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    PyCompilerFlags *flags);

PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
    const char *s,
    const char *filename,       /* decoded from the filesystem encoding */
    int start,
    PyCompilerFlags *flags,
    PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    const char* enc,
    int start,
    char *ps1,
    char *ps2,
    PyCompilerFlags *flags,
    int *errcode,
    PyArena *arena);
79 80 81
#endif

#ifndef PyParser_SimpleParseString
Jeremy Hylton's avatar
Jeremy Hylton committed
82
#define PyParser_SimpleParseString(S, B) \
83
    PyParser_SimpleParseStringFlags(S, B, 0)
Jeremy Hylton's avatar
Jeremy Hylton committed
84
#define PyParser_SimpleParseFile(FP, S, B) \
85
    PyParser_SimpleParseFileFlags(FP, S, B, 0)
86
#endif
87
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
88 89 90 91
                                                           int);
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
                                                                   const char *,
                                                                   int, int);
92
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
93
                                                         int, int);
Guido van Rossum's avatar
Guido van Rossum committed
94

95
#ifndef Py_LIMITED_API
96 97
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
                                         PyObject *, PyCompilerFlags *);
Jeremy Hylton's avatar
Jeremy Hylton committed
98

99 100 101 102 103 104 105 106
PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
    FILE *fp,
    const char *filename,       /* decoded from the filesystem encoding */
    int start,
    PyObject *globals,
    PyObject *locals,
    int closeit,
    PyCompilerFlags *flags);
107
#endif
Jeremy Hylton's avatar
Jeremy Hylton committed
108

109
#ifdef Py_LIMITED_API
110
PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
111
#else
112 113
#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
114 115 116 117 118 119
PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
    const char *str,
    const char *filename,       /* decoded from the filesystem encoding */
    int start,
    PyCompilerFlags *flags,
    int optimize);
120
#endif
121 122 123 124
PyAPI_FUNC(struct symtable *) Py_SymtableString(
    const char *str,
    const char *filename,       /* decoded from the filesystem encoding */
    int start);
125

126 127 128
PyAPI_FUNC(void) PyErr_Print(void);
PyAPI_FUNC(void) PyErr_PrintEx(int);
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossum's avatar
Guido van Rossum committed
129

130 131 132
/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
 * exit functions.
 */
133
#ifndef Py_LIMITED_API
134
PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void));
135
#endif
136
PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
137

138
PyAPI_FUNC(void) Py_Exit(int);
139

140
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
141
#ifndef Py_LIMITED_API
142 143
PyAPI_FUNC(void) _Py_RestoreSignals(void);

144
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
145
#endif
146

147
/* Bootstrap */
148
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
149

150
#ifndef Py_LIMITED_API
Jeremy Hylton's avatar
Jeremy Hylton committed
151 152 153 154
/* Use macros for a bunch of old variants */
#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
#define PyRun_AnyFileEx(fp, name, closeit) \
155
    PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton's avatar
Jeremy Hylton committed
156
#define PyRun_AnyFileFlags(fp, name, flags) \
157
    PyRun_AnyFileExFlags(fp, name, 0, flags)
158
#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton's avatar
Jeremy Hylton committed
159 160 161 162 163
#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
#define PyRun_File(fp, p, s, g, l) \
164
    PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton's avatar
Jeremy Hylton committed
165
#define PyRun_FileEx(fp, p, s, g, l, c) \
166
    PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton's avatar
Jeremy Hylton committed
167
#define PyRun_FileFlags(fp, p, s, g, l, flags) \
168
    PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
169
#endif
Jeremy Hylton's avatar
Jeremy Hylton committed
170

171
/* In getpath.c */
172 173 174 175
PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
Kristján Valur Jónsson's avatar
Kristján Valur Jónsson committed
176
PyAPI_FUNC(void)      Py_SetPath(const wchar_t *);
177 178 179
#ifdef MS_WINDOWS
int _Py_CheckPython3();
#endif
180 181

/* In their own files */
182 183 184 185 186
PyAPI_FUNC(const char *) Py_GetVersion(void);
PyAPI_FUNC(const char *) Py_GetPlatform(void);
PyAPI_FUNC(const char *) Py_GetCopyright(void);
PyAPI_FUNC(const char *) Py_GetCompiler(void);
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
187
#ifndef Py_LIMITED_API
188 189
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
PyAPI_FUNC(const char *) _Py_hgversion(void);
190
#endif
191

192
/* Internal -- various one-time initializations */
193
#ifndef Py_LIMITED_API
194 195 196
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
PyAPI_FUNC(PyObject *) _PySys_Init(void);
PyAPI_FUNC(void) _PyImport_Init(void);
197
PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod);
Just van Rossum's avatar
Just van Rossum committed
198
PyAPI_FUNC(void) _PyImportHooks_Init(void);
199
PyAPI_FUNC(int) _PyFrame_Init(void);
Michael W. Hudson's avatar
Michael W. Hudson committed
200
PyAPI_FUNC(void) _PyFloat_Init(void);
201
PyAPI_FUNC(int) PyByteArray_Init(void);
202
PyAPI_FUNC(void) _PyRandom_Init(void);
203
#endif
204

205
/* Various internal finalizers */
206
#ifndef Py_LIMITED_API
207 208 209 210 211
PyAPI_FUNC(void) _PyExc_Fini(void);
PyAPI_FUNC(void) _PyImport_Fini(void);
PyAPI_FUNC(void) PyMethod_Fini(void);
PyAPI_FUNC(void) PyFrame_Fini(void);
PyAPI_FUNC(void) PyCFunction_Fini(void);
Christian Heimes's avatar
Christian Heimes committed
212
PyAPI_FUNC(void) PyDict_Fini(void);
213
PyAPI_FUNC(void) PyTuple_Fini(void);
214
PyAPI_FUNC(void) PyList_Fini(void);
215
PyAPI_FUNC(void) PySet_Fini(void);
216
PyAPI_FUNC(void) PyBytes_Fini(void);
217
PyAPI_FUNC(void) PyByteArray_Fini(void);
218 219
PyAPI_FUNC(void) PyFloat_Fini(void);
PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
220
PyAPI_FUNC(void) _PyGC_Fini(void);
221
PyAPI_FUNC(void) PySlice_Fini(void);
222
PyAPI_FUNC(void) _PyType_Fini(void);
223 224

PyAPI_DATA(PyThreadState *) _Py_Finalizing;
225
#endif
226

227
/* Stuff with no proper home (yet) */
228
#ifndef Py_LIMITED_API
229
PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
230
#endif
231
PyAPI_DATA(int) (*PyOS_InputHook)(void);
232
PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
233
#ifndef Py_LIMITED_API
234
PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
235
#endif
236 237 238 239 240 241

/* Stack size, in "pointers" (so we get extra safety margins
   on 64-bit platforms).  On a 32-bit platform, this translates
   to a 8k margin. */
#define PYOS_STACK_MARGIN 2048

242
#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
243 244 245 246
/* Enable stack checking under Microsoft C */
#define USE_STACKCHECK
#endif

247
#ifdef USE_STACKCHECK
248
/* Check that we aren't overflowing our stack */
249
PyAPI_FUNC(int) PyOS_CheckStack(void);
250
#endif
251

252 253
/* Signals */
typedef void (*PyOS_sighandler_t)(int);
254 255
PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
256

257 258
/* Random */
PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size);
259

260 261 262 263
#ifdef __cplusplus
}
#endif
#endif /* !Py_PYTHONRUN_H */