blob: 57529072432ea75545e8a24da37c88282113b6c0 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001
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#ifndef Py_LIMITED_API
11PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
12PyAPI_FUNC(int) PyRun_AnyFileExFlags(
13 FILE *fp,
14 const char *filename, /* decoded from the filesystem encoding */
15 int closeit,
16 PyCompilerFlags *flags);
17PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
18 FILE *fp,
19 const char *filename, /* decoded from the filesystem encoding */
20 int closeit,
21 PyCompilerFlags *flags);
22PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
23 FILE *fp,
24 const char *filename, /* decoded from the filesystem encoding */
25 PyCompilerFlags *flags);
26PyAPI_FUNC(int) PyRun_InteractiveOneObject(
27 FILE *fp,
28 PyObject *filename,
29 PyCompilerFlags *flags);
30PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
31 FILE *fp,
32 const char *filename, /* decoded from the filesystem encoding */
33 PyCompilerFlags *flags);
34
35PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
36 const char *s,
37 const char *filename, /* decoded from the filesystem encoding */
38 int start,
39 PyCompilerFlags *flags,
40 PyArena *arena);
41PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
42 const char *s,
43 PyObject *filename,
44 int start,
45 PyCompilerFlags *flags,
46 PyArena *arena);
47PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
48 FILE *fp,
49 const char *filename, /* decoded from the filesystem encoding */
50 const char* enc,
51 int start,
52 const char *ps1,
53 const char *ps2,
54 PyCompilerFlags *flags,
55 int *errcode,
56 PyArena *arena);
57PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
58 FILE *fp,
59 PyObject *filename,
60 const char* enc,
61 int start,
62 const char *ps1,
63 const char *ps2,
64 PyCompilerFlags *flags,
65 int *errcode,
66 PyArena *arena);
67#endif
68
69#ifndef PyParser_SimpleParseString
70#define PyParser_SimpleParseString(S, B) \
71 PyParser_SimpleParseStringFlags(S, B, 0)
72#define PyParser_SimpleParseFile(FP, S, B) \
73 PyParser_SimpleParseFileFlags(FP, S, B, 0)
74#endif
75
76#ifndef Py_BUILD_CORE
77Py_DEPRECATED(3.9)
78#endif
79PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, int);
80#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
81#ifndef Py_BUILD_CORE
82Py_DEPRECATED(3.9)
83#endif
84PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
85 const char *,
86 int, int);
87#endif
88#ifndef Py_BUILD_CORE
89Py_DEPRECATED(3.9)
90#endif
91PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, int, int);
92#ifndef Py_LIMITED_API
93PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
94 PyObject *, PyCompilerFlags *);
95
96PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
97 FILE *fp,
98 const char *filename, /* decoded from the filesystem encoding */
99 int start,
100 PyObject *globals,
101 PyObject *locals,
102 int closeit,
103 PyCompilerFlags *flags);
104#endif
105
106#ifdef Py_LIMITED_API
107PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
108#else
109#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
110#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
111PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
112 const char *str,
113 const char *filename, /* decoded from the filesystem encoding */
114 int start,
115 PyCompilerFlags *flags,
116 int optimize);
117PyAPI_FUNC(PyObject *) Py_CompileStringObject(
118 const char *str,
119 PyObject *filename, int start,
120 PyCompilerFlags *flags,
121 int optimize);
122#endif
123PyAPI_FUNC(struct symtable *) Py_SymtableString(
124 const char *str,
125 const char *filename, /* decoded from the filesystem encoding */
126 int start);
127#ifndef Py_LIMITED_API
128PyAPI_FUNC(const char *) _Py_SourceAsString(
129 PyObject *cmd,
130 const char *funcname,
131 const char *what,
132 PyCompilerFlags *cf,
133 PyObject **cmd_copy);
134
135PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
136 const char *str,
137 PyObject *filename,
138 int start);
139
140PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags(
141 const char *str,
142 PyObject *filename,
143 int start,
144 PyCompilerFlags *flags);
145#endif
146
147PyAPI_FUNC(void) PyErr_Print(void);
148PyAPI_FUNC(void) PyErr_PrintEx(int);
149PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
150
151#ifndef Py_LIMITED_API
152/* A function flavor is also exported by libpython. It is required when
153 libpython is accessed directly rather than using header files which defines
154 macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to
155 export functions in pythonXX.dll. */
156PyAPI_FUNC(PyObject *) PyRun_String(const char *str, int s, PyObject *g, PyObject *l);
157PyAPI_FUNC(int) PyRun_AnyFile(FILE *fp, const char *name);
158PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *fp, const char *name, int closeit);
159PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
160PyAPI_FUNC(int) PyRun_SimpleString(const char *s);
161PyAPI_FUNC(int) PyRun_SimpleFile(FILE *f, const char *p);
162PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *f, const char *p, int c);
163PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *f, const char *p);
164PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *f, const char *p);
165PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l);
166PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c);
167PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags);
168
169/* Use macros for a bunch of old variants */
170#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
171#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
172#define PyRun_AnyFileEx(fp, name, closeit) \
173 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
174#define PyRun_AnyFileFlags(fp, name, flags) \
175 PyRun_AnyFileExFlags(fp, name, 0, flags)
176#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
177#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
178#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
179#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
180#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
181#define PyRun_File(fp, p, s, g, l) \
182 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
183#define PyRun_FileEx(fp, p, s, g, l, c) \
184 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
185#define PyRun_FileFlags(fp, p, s, g, l, flags) \
186 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
187#endif
188
189/* Stuff with no proper home (yet) */
190#ifndef Py_LIMITED_API
191PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
192#endif
193PyAPI_DATA(int) (*PyOS_InputHook)(void);
194PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
195#ifndef Py_LIMITED_API
196PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
197#endif
198
199/* Stack size, in "pointers" (so we get extra safety margins
200 on 64-bit platforms). On a 32-bit platform, this translates
201 to an 8k margin. */
202#define PYOS_STACK_MARGIN 2048
203
204#if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
205/* Enable stack checking under Microsoft C */
206#define USE_STACKCHECK
207#endif
208
209#ifdef USE_STACKCHECK
210/* Check that we aren't overflowing our stack */
211PyAPI_FUNC(int) PyOS_CheckStack(void);
212#endif
213
214#ifdef __cplusplus
215}
216#endif
217#endif /* !Py_PYTHONRUN_H */