1
2/* Interfaces to parse and execute pieces of python code */
3
4#ifndef Py_PYTHONRUN_H
5#define Py_PYTHONRUN_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
11                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
12                   CO_FUTURE_UNICODE_LITERALS)
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
18typedef struct {
19    int cf_flags;  /* bitmask of CO_xxx flags relevant to future */
20} PyCompilerFlags;
21
22PyAPI_FUNC(void) Py_SetProgramName(char *);
23PyAPI_FUNC(char *) Py_GetProgramName(void);
24
25PyAPI_FUNC(void) Py_SetPythonHome(char *);
26PyAPI_FUNC(char *) Py_GetPythonHome(void);
27
28PyAPI_FUNC(void) Py_Initialize(void);
29PyAPI_FUNC(void) Py_InitializeEx(int);
30PyAPI_FUNC(void) Py_Finalize(void);
31PyAPI_FUNC(int) Py_IsInitialized(void);
32PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
33PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
34
35PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
36PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
37PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
38PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
39PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
40PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
41
42PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
43                                                 int, PyCompilerFlags *flags,
44                                                 PyArena *);
45PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,
46                                               char *, char *,
47                                               PyCompilerFlags *, int *,
48                                               PyArena *);
49#define PyParser_SimpleParseString(S, B) \
50    PyParser_SimpleParseStringFlags(S, B, 0)
51#define PyParser_SimpleParseFile(FP, S, B) \
52    PyParser_SimpleParseFileFlags(FP, S, B, 0)
53PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
54                                                          int);
55PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
56                                                        int, int);
57
58PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
59                                         PyObject *, PyCompilerFlags *);
60
61PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
62                                         PyObject *, PyObject *, int,
63                                         PyCompilerFlags *);
64
65#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
66PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
67                                             PyCompilerFlags *);
68PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
69
70PyAPI_FUNC(void) PyErr_Print(void);
71PyAPI_FUNC(void) PyErr_PrintEx(int);
72PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
73
74PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
75
76PyAPI_FUNC(void) Py_Exit(int);
77
78PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
79
80/* Bootstrap */
81PyAPI_FUNC(int) Py_Main(int argc, char **argv);
82
83/* Use macros for a bunch of old variants */
84#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
85#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
86#define PyRun_AnyFileEx(fp, name, closeit) \
87    PyRun_AnyFileExFlags(fp, name, closeit, NULL)
88#define PyRun_AnyFileFlags(fp, name, flags) \
89    PyRun_AnyFileExFlags(fp, name, 0, flags)
90#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
91#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
92#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
93#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
94#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
95#define PyRun_File(fp, p, s, g, l) \
96    PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
97#define PyRun_FileEx(fp, p, s, g, l, c) \
98    PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
99#define PyRun_FileFlags(fp, p, s, g, l, flags) \
100    PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
101
102/* In getpath.c */
103PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
104PyAPI_FUNC(char *) Py_GetPrefix(void);
105PyAPI_FUNC(char *) Py_GetExecPrefix(void);
106PyAPI_FUNC(char *) Py_GetPath(void);
107
108/* In their own files */
109PyAPI_FUNC(const char *) Py_GetVersion(void);
110PyAPI_FUNC(const char *) Py_GetPlatform(void);
111PyAPI_FUNC(const char *) Py_GetCopyright(void);
112PyAPI_FUNC(const char *) Py_GetCompiler(void);
113PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
114PyAPI_FUNC(const char *) _Py_svnversion(void);
115PyAPI_FUNC(const char *) Py_SubversionRevision(void);
116PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
117PyAPI_FUNC(const char *) _Py_hgidentifier(void);
118PyAPI_FUNC(const char *) _Py_hgversion(void);
119
120/* Internal -- various one-time initializations */
121PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
122PyAPI_FUNC(PyObject *) _PySys_Init(void);
123PyAPI_FUNC(void) _PyImport_Init(void);
124PyAPI_FUNC(void) _PyExc_Init(void);
125PyAPI_FUNC(void) _PyImportHooks_Init(void);
126PyAPI_FUNC(int) _PyFrame_Init(void);
127PyAPI_FUNC(int) _PyInt_Init(void);
128PyAPI_FUNC(int) _PyLong_Init(void);
129PyAPI_FUNC(void) _PyFloat_Init(void);
130PyAPI_FUNC(int) PyByteArray_Init(void);
131PyAPI_FUNC(void) _PyRandom_Init(void);
132
133/* Various internal finalizers */
134PyAPI_FUNC(void) _PyExc_Fini(void);
135PyAPI_FUNC(void) _PyImport_Fini(void);
136PyAPI_FUNC(void) PyMethod_Fini(void);
137PyAPI_FUNC(void) PyFrame_Fini(void);
138PyAPI_FUNC(void) PyCFunction_Fini(void);
139PyAPI_FUNC(void) PyDict_Fini(void);
140PyAPI_FUNC(void) PyTuple_Fini(void);
141PyAPI_FUNC(void) PyList_Fini(void);
142PyAPI_FUNC(void) PySet_Fini(void);
143PyAPI_FUNC(void) PyString_Fini(void);
144PyAPI_FUNC(void) PyInt_Fini(void);
145PyAPI_FUNC(void) PyFloat_Fini(void);
146PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
147PyAPI_FUNC(void) PyByteArray_Fini(void);
148
149/* Stuff with no proper home (yet) */
150PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
151PyAPI_DATA(int) (*PyOS_InputHook)(void);
152PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
153PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
154
155/* Stack size, in "pointers" (so we get extra safety margins
156   on 64-bit platforms).  On a 32-bit platform, this translates
157   to a 8k margin. */
158#define PYOS_STACK_MARGIN 2048
159
160#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
161/* Enable stack checking under Microsoft C */
162#define USE_STACKCHECK
163#endif
164
165#ifdef USE_STACKCHECK
166/* Check that we aren't overflowing our stack */
167PyAPI_FUNC(int) PyOS_CheckStack(void);
168#endif
169
170/* Signals */
171typedef void (*PyOS_sighandler_t)(int);
172PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
173PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
174
175/* Random */
176PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size);
177
178#ifdef __cplusplus
179}
180#endif
181#endif /* !Py_PYTHONRUN_H */
182