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 | CO_FUTURE_BARRY_AS_BDFL | \
13 CO_FUTURE_GENERATOR_STOP)
14#define PyCF_MASK_OBSOLETE (CO_NESTED)
15#define PyCF_SOURCE_IS_UTF8 0x0100
16#define PyCF_DONT_IMPLY_DEDENT 0x0200
17#define PyCF_ONLY_AST 0x0400
18#define PyCF_IGNORE_COOKIE 0x0800
19
20#ifndef Py_LIMITED_API
21typedef struct {
22 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
23} PyCompilerFlags;
24#endif
25
26#ifndef Py_LIMITED_API
27PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
28PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
29PyAPI_FUNC(int) PyRun_AnyFileExFlags(
30 FILE *fp,
31 const char *filename, /* decoded from the filesystem encoding */
32 int closeit,
33 PyCompilerFlags *flags);
34PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
35 FILE *fp,
36 const char *filename, /* decoded from the filesystem encoding */
37 int closeit,
38 PyCompilerFlags *flags);
39PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
40 FILE *fp,
41 const char *filename, /* decoded from the filesystem encoding */
42 PyCompilerFlags *flags);
43PyAPI_FUNC(int) PyRun_InteractiveOneObject(
44 FILE *fp,
45 PyObject *filename,
46 PyCompilerFlags *flags);
47PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
48 FILE *fp,
49 const char *filename, /* decoded from the filesystem encoding */
50 PyCompilerFlags *flags);
51
52PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
53 const char *s,
54 const char *filename, /* decoded from the filesystem encoding */
55 int start,
56 PyCompilerFlags *flags,
57 PyArena *arena);
58PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
59 const char *s,
60 PyObject *filename,
61 int start,
62 PyCompilerFlags *flags,
63 PyArena *arena);
64PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
65 FILE *fp,
66 const char *filename, /* decoded from the filesystem encoding */
67 const char* enc,
68 int start,
69 char *ps1,
70 char *ps2,
71 PyCompilerFlags *flags,
72 int *errcode,
73 PyArena *arena);
74PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
75 FILE *fp,
76 PyObject *filename,
77 const char* enc,
78 int start,
79 char *ps1,
80 char *ps2,
81 PyCompilerFlags *flags,
82 int *errcode,
83 PyArena *arena);
84#endif
85
86#ifndef PyParser_SimpleParseString
87#define PyParser_SimpleParseString(S, B) \
88 PyParser_SimpleParseStringFlags(S, B, 0)
89#define PyParser_SimpleParseFile(FP, S, B) \
90 PyParser_SimpleParseFileFlags(FP, S, B, 0)
91#endif
92PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
93 int);
94PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
95 const char *,
96 int, int);
97PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
98 int, int);
99
100#ifndef Py_LIMITED_API
101PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
102 PyObject *, PyCompilerFlags *);
103
104PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
105 FILE *fp,
106 const char *filename, /* decoded from the filesystem encoding */
107 int start,
108 PyObject *globals,
109 PyObject *locals,
110 int closeit,
111 PyCompilerFlags *flags);
112#endif
113
114#ifdef Py_LIMITED_API
115PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
116#else
117#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
118#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
119PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
120 const char *str,
121 const char *filename, /* decoded from the filesystem encoding */
122 int start,
123 PyCompilerFlags *flags,
124 int optimize);
125PyAPI_FUNC(PyObject *) Py_CompileStringObject(
126 const char *str,
127 PyObject *filename, int start,
128 PyCompilerFlags *flags,
129 int optimize);
130#endif
131PyAPI_FUNC(struct symtable *) Py_SymtableString(
132 const char *str,
133 const char *filename, /* decoded from the filesystem encoding */
134 int start);
135#ifndef Py_LIMITED_API
136PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
137 const char *str,
138 PyObject *filename,
139 int start);
140#endif
141
142PyAPI_FUNC(void) PyErr_Print(void);
143PyAPI_FUNC(void) PyErr_PrintEx(int);
144PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
145
146#ifndef Py_LIMITED_API
147/* Use macros for a bunch of old variants */
148#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
149#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
150#define PyRun_AnyFileEx(fp, name, closeit) \
151 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
152#define PyRun_AnyFileFlags(fp, name, flags) \
153 PyRun_AnyFileExFlags(fp, name, 0, flags)
154#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
155#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
156#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
157#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
158#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
159#define PyRun_File(fp, p, s, g, l) \
160 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
161#define PyRun_FileEx(fp, p, s, g, l, c) \
162 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
163#define PyRun_FileFlags(fp, p, s, g, l, flags) \
164 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
165#endif
166
167/* Stuff with no proper home (yet) */
168#ifndef Py_LIMITED_API
169PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
170#endif
171PyAPI_DATA(int) (*PyOS_InputHook)(void);
172PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
173#ifndef Py_LIMITED_API
174PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
175#endif
176
177/* Stack size, in "pointers" (so we get extra safety margins
178 on 64-bit platforms). On a 32-bit platform, this translates
179 to an 8k margin. */
180#define PYOS_STACK_MARGIN 2048
181
182#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
183/* Enable stack checking under Microsoft C */
184#define USE_STACKCHECK
185#endif
186
187#ifdef USE_STACKCHECK
188/* Check that we aren't overflowing our stack */
189PyAPI_FUNC(int) PyOS_CheckStack(void);
190#endif
191
192#ifdef __cplusplus
193}
194#endif
195#endif /* !Py_PYTHONRUN_H */
196