blob: d43734b5a12ff0ee7c2dea26bc4c0b3f845ebb7f [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum3f5da241990-12-20 15:06:42 +00002/* Interfaces to parse and execute pieces of python code */
3
Fred Drake3cf4d2b2000-07-09 00:55:06 +00004#ifndef Py_PYTHONRUN_H
5#define Py_PYTHONRUN_H
6#ifdef __cplusplus
7extern "C" {
8#endif
Guido van Rossum57d8e3f1997-07-19 19:50:52 +00009
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000010#ifndef Py_LIMITED_API
11PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Victor Stinner00676d12010-12-27 01:49:31 +000012PyAPI_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);
Victor Stinner95701bd2013-11-06 18:41:07 +010026PyAPI_FUNC(int) PyRun_InteractiveOneObject(
27 FILE *fp,
28 PyObject *filename,
29 PyCompilerFlags *flags);
Victor Stinner00676d12010-12-27 01:49:31 +000030PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
31 FILE *fp,
32 const char *filename, /* decoded from the filesystem encoding */
33 PyCompilerFlags *flags);
Guido van Rossum3f5da241990-12-20 15:06:42 +000034
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000035
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000036PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
37 PyObject *, PyCompilerFlags *);
Guido van Rossum5b722181993-03-30 17:46:03 +000038
Victor Stinner00676d12010-12-27 01:49:31 +000039PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
40 FILE *fp,
41 const char *filename, /* decoded from the filesystem encoding */
42 int start,
43 PyObject *globals,
44 PyObject *locals,
45 int closeit,
46 PyCompilerFlags *flags);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000047#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000048
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000049#ifdef Py_LIMITED_API
Martin v. Löwis0d012f22010-12-04 12:00:49 +000050PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000051#else
Georg Brandl8334fd92010-12-04 10:26:46 +000052#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
53#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
Victor Stinner00676d12010-12-27 01:49:31 +000054PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
55 const char *str,
56 const char *filename, /* decoded from the filesystem encoding */
57 int start,
58 PyCompilerFlags *flags,
59 int optimize);
Victor Stinner14e461d2013-08-26 22:28:21 +020060PyAPI_FUNC(PyObject *) Py_CompileStringObject(
61 const char *str,
62 PyObject *filename, int start,
63 PyCompilerFlags *flags,
64 int optimize);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000065#endif
Victor Stinner00676d12010-12-27 01:49:31 +000066PyAPI_FUNC(struct symtable *) Py_SymtableString(
67 const char *str,
68 const char *filename, /* decoded from the filesystem encoding */
69 int start);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +010070#ifndef Py_LIMITED_API
Dino Viehland41540692019-05-28 16:21:17 -070071PyAPI_FUNC(const char *) _Py_SourceAsString(
72 PyObject *cmd,
73 const char *funcname,
Victor Stinner343ed0f2019-06-18 00:15:13 +020074 const char *what,
Dino Viehland41540692019-05-28 16:21:17 -070075 PyCompilerFlags *cf,
76 PyObject **cmd_copy);
77
Victor Stinner14e461d2013-08-26 22:28:21 +020078PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
79 const char *str,
80 PyObject *filename,
81 int start);
Dino Viehland41540692019-05-28 16:21:17 -070082
83PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags(
84 const char *str,
85 PyObject *filename,
86 int start,
87 PyCompilerFlags *flags);
Martin v. Löwis1c0689c2014-01-03 21:36:49 +010088#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +000089
Mark Hammond91a681d2002-08-12 07:21:58 +000090PyAPI_FUNC(void) PyErr_Print(void);
91PyAPI_FUNC(void) PyErr_PrintEx(int);
92PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Guido van Rossumc6cf1dd1994-09-07 14:35:10 +000093
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000094#ifndef Py_LIMITED_API
Victor Stinner343ed0f2019-06-18 00:15:13 +020095/* A function flavor is also exported by libpython. It is required when
96 libpython is accessed directly rather than using header files which defines
97 macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to
98 export functions in pythonXX.dll. */
99PyAPI_FUNC(PyObject *) PyRun_String(const char *str, int s, PyObject *g, PyObject *l);
100PyAPI_FUNC(int) PyRun_AnyFile(FILE *fp, const char *name);
101PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *fp, const char *name, int closeit);
102PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
103PyAPI_FUNC(int) PyRun_SimpleString(const char *s);
104PyAPI_FUNC(int) PyRun_SimpleFile(FILE *f, const char *p);
105PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *f, const char *p, int c);
106PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *f, const char *p);
107PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *f, const char *p);
108PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l);
109PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c);
110PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags);
111
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000112/* Use macros for a bunch of old variants */
113#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
114#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
115#define PyRun_AnyFileEx(fp, name, closeit) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000116 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000117#define PyRun_AnyFileFlags(fp, name, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000118 PyRun_AnyFileExFlags(fp, name, 0, flags)
Mark Hammondf3ddaee2005-10-23 10:53:06 +0000119#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000120#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
121#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
122#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
123#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
124#define PyRun_File(fp, p, s, g, l) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000125 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000126#define PyRun_FileEx(fp, p, s, g, l, c) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000127 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000128#define PyRun_FileFlags(fp, p, s, g, l, flags) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000129 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000130#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000131
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000132/* Stuff with no proper home (yet) */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000133#ifndef Py_LIMITED_API
Serhiy Storchakac6792272013-10-19 21:03:34 +0300134PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000135#endif
Mark Hammond5d546672002-08-12 13:06:35 +0000136PyAPI_DATA(int) (*PyOS_InputHook)(void);
Serhiy Storchakac6792272013-10-19 21:03:34 +0300137PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000138#ifndef Py_LIMITED_API
Jason Tishler0d2a75c2004-08-09 15:02:30 +0000139PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000140#endif
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000141
142/* Stack size, in "pointers" (so we get extra safety margins
143 on 64-bit platforms). On a 32-bit platform, this translates
Martin Panter4c359642016-05-08 13:53:41 +0000144 to an 8k margin. */
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000145#define PYOS_STACK_MARGIN 2048
146
Paul Monson11efd792019-04-17 18:09:16 -0700147#if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000148/* Enable stack checking under Microsoft C */
149#define USE_STACKCHECK
150#endif
151
Jack Jansen275abb32000-08-07 21:00:42 +0000152#ifdef USE_STACKCHECK
Fredrik Lundh2f15b252000-08-27 19:15:31 +0000153/* Check that we aren't overflowing our stack */
Mark Hammond91a681d2002-08-12 07:21:58 +0000154PyAPI_FUNC(int) PyOS_CheckStack(void);
Jack Jansen275abb32000-08-07 21:00:42 +0000155#endif
Guido van Rossum3fb1aea1997-08-12 15:14:22 +0000156
Guido van Rossuma3309961993-07-28 09:05:47 +0000157#ifdef __cplusplus
158}
159#endif
160#endif /* !Py_PYTHONRUN_H */