You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.6 KiB

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