pythonrun.h 7.5 KB

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