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.

181 lines
7.1 KiB

Mass checkin (more to follow for other directories). Introduce truly separate (sub)interpreter objects. For now, these must be used by separate threads, created from C. See Demo/pysvr for an example of how to use this. This also rationalizes Python's initialization and finalization behavior: Py_Initialize() -- initialize the whole interpreter Py_Finalize() -- finalize the whole interpreter tstate = Py_NewInterpreter() -- create a new (sub)interpreter Py_EndInterpreter(tstate) -- delete a new (sub)interpreter There are also new interfaces relating to threads and the interpreter lock, which can be used to create new threads, and sometimes have to be used to manipulate the interpreter lock when creating or deleting sub-interpreters. These are only defined when WITH_THREAD is defined: PyEval_AcquireLock() -- acquire the interpreter lock PyEval_ReleaseLock() -- release the interpreter lock PyEval_AcquireThread(tstate) -- acquire the lock and make the thread current PyEval_ReleaseThread(tstate) -- release the lock and make NULL current Other administrative changes: - The header file bltinmodule.h is deleted. - The init functions for Import, Sys and Builtin are now internal and declared in pythonrun.h. - Py_Setup() and Py_Cleanup() are no longer declared. - The interpreter state and thread state structures are now linked together in a chain (the chain of interpreters is a static variable in pythonrun.c). - Some members of the interpreter and thread structures have new, shorter, more consistent, names. - Added declarations for _PyImport_{Find,Fixup}Extension() to import.h.
29 years ago
Mass checkin (more to follow for other directories). Introduce truly separate (sub)interpreter objects. For now, these must be used by separate threads, created from C. See Demo/pysvr for an example of how to use this. This also rationalizes Python's initialization and finalization behavior: Py_Initialize() -- initialize the whole interpreter Py_Finalize() -- finalize the whole interpreter tstate = Py_NewInterpreter() -- create a new (sub)interpreter Py_EndInterpreter(tstate) -- delete a new (sub)interpreter There are also new interfaces relating to threads and the interpreter lock, which can be used to create new threads, and sometimes have to be used to manipulate the interpreter lock when creating or deleting sub-interpreters. These are only defined when WITH_THREAD is defined: PyEval_AcquireLock() -- acquire the interpreter lock PyEval_ReleaseLock() -- release the interpreter lock PyEval_AcquireThread(tstate) -- acquire the lock and make the thread current PyEval_ReleaseThread(tstate) -- release the lock and make NULL current Other administrative changes: - The header file bltinmodule.h is deleted. - The init functions for Import, Sys and Builtin are now internal and declared in pythonrun.h. - Py_Setup() and Py_Cleanup() are no longer declared. - The interpreter state and thread state structures are now linked together in a chain (the chain of interpreters is a static variable in pythonrun.c). - Some members of the interpreter and thread structures have new, shorter, more consistent, names. - Added declarations for _PyImport_{Find,Fixup}Extension() to import.h.
29 years ago
  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)
  10. #define PyCF_MASK_OBSOLETE (CO_NESTED)
  11. #define PyCF_SOURCE_IS_UTF8 0x0100
  12. #define PyCF_DONT_IMPLY_DEDENT 0x0200
  13. #define PyCF_ONLY_AST 0x0400
  14. typedef struct {
  15. int cf_flags; /* bitmask of CO_xxx flags relevant to future */
  16. } PyCompilerFlags;
  17. PyAPI_FUNC(void) Py_SetProgramName(char *);
  18. PyAPI_FUNC(char *) Py_GetProgramName(void);
  19. PyAPI_FUNC(void) Py_SetPythonHome(char *);
  20. PyAPI_FUNC(char *) Py_GetPythonHome(void);
  21. PyAPI_FUNC(void) Py_Initialize(void);
  22. PyAPI_FUNC(void) Py_InitializeEx(int);
  23. PyAPI_FUNC(void) Py_Finalize(void);
  24. PyAPI_FUNC(int) Py_IsInitialized(void);
  25. PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
  26. PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
  27. PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
  28. PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
  29. PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
  30. PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
  31. PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
  32. PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
  33. PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
  34. int, PyCompilerFlags *flags,
  35. PyArena *);
  36. PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,
  37. char *, char *,
  38. PyCompilerFlags *, int *,
  39. PyArena *);
  40. #define PyParser_SimpleParseString(S, B) \
  41. PyParser_SimpleParseStringFlags(S, B, 0)
  42. #define PyParser_SimpleParseFile(FP, S, B) \
  43. PyParser_SimpleParseFileFlags(FP, S, B, 0)
  44. PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
  45. int);
  46. PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
  47. int, int);
  48. PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
  49. PyObject *, PyCompilerFlags *);
  50. PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
  51. PyObject *, PyObject *, int,
  52. PyCompilerFlags *);
  53. #define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
  54. PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
  55. PyCompilerFlags *);
  56. PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
  57. PyAPI_FUNC(void) PyErr_Print(void);
  58. PyAPI_FUNC(void) PyErr_PrintEx(int);
  59. PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
  60. PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
  61. PyAPI_FUNC(void) Py_Exit(int);
  62. PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
  63. /* Bootstrap */
  64. PyAPI_FUNC(int) Py_Main(int argc, char **argv);
  65. /* Use macros for a bunch of old variants */
  66. #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
  67. #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
  68. #define PyRun_AnyFileEx(fp, name, closeit) \
  69. PyRun_AnyFileExFlags(fp, name, closeit, NULL)
  70. #define PyRun_AnyFileFlags(fp, name, flags) \
  71. PyRun_AnyFileExFlags(fp, name, 0, flags)
  72. #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
  73. #define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
  74. #define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
  75. #define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
  76. #define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
  77. #define PyRun_File(fp, p, s, g, l) \
  78. PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
  79. #define PyRun_FileEx(fp, p, s, g, l, c) \
  80. PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
  81. #define PyRun_FileFlags(fp, p, s, g, l, flags) \
  82. PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
  83. /* In getpath.c */
  84. PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
  85. PyAPI_FUNC(char *) Py_GetPrefix(void);
  86. PyAPI_FUNC(char *) Py_GetExecPrefix(void);
  87. PyAPI_FUNC(char *) Py_GetPath(void);
  88. /* In their own files */
  89. PyAPI_FUNC(const char *) Py_GetVersion(void);
  90. PyAPI_FUNC(const char *) Py_GetPlatform(void);
  91. PyAPI_FUNC(const char *) Py_GetCopyright(void);
  92. PyAPI_FUNC(const char *) Py_GetCompiler(void);
  93. PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
  94. PyAPI_FUNC(const char *) _Py_svnversion(void);
  95. PyAPI_FUNC(const char *) Py_SubversionRevision(void);
  96. PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
  97. PyAPI_FUNC(const char *) _Py_hgidentifier(void);
  98. PyAPI_FUNC(const char *) _Py_hgversion(void);
  99. /* Internal -- various one-time initializations */
  100. PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
  101. PyAPI_FUNC(PyObject *) _PySys_Init(void);
  102. PyAPI_FUNC(void) _PyImport_Init(void);
  103. PyAPI_FUNC(void) _PyExc_Init(void);
  104. PyAPI_FUNC(void) _PyImportHooks_Init(void);
  105. PyAPI_FUNC(int) _PyFrame_Init(void);
  106. PyAPI_FUNC(int) _PyInt_Init(void);
  107. PyAPI_FUNC(int) _PyLong_Init(void);
  108. PyAPI_FUNC(void) _PyFloat_Init(void);
  109. PyAPI_FUNC(int) PyByteArray_Init(void);
  110. PyAPI_FUNC(void) _PyRandom_Init(void);
  111. /* Various internal finalizers */
  112. PyAPI_FUNC(void) _PyExc_Fini(void);
  113. PyAPI_FUNC(void) _PyImport_Fini(void);
  114. PyAPI_FUNC(void) PyMethod_Fini(void);
  115. PyAPI_FUNC(void) PyFrame_Fini(void);
  116. PyAPI_FUNC(void) PyCFunction_Fini(void);
  117. PyAPI_FUNC(void) PyDict_Fini(void);
  118. PyAPI_FUNC(void) PyTuple_Fini(void);
  119. PyAPI_FUNC(void) PyList_Fini(void);
  120. PyAPI_FUNC(void) PySet_Fini(void);
  121. PyAPI_FUNC(void) PyString_Fini(void);
  122. PyAPI_FUNC(void) PyInt_Fini(void);
  123. PyAPI_FUNC(void) PyFloat_Fini(void);
  124. PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
  125. PyAPI_FUNC(void) PyByteArray_Fini(void);
  126. /* Stuff with no proper home (yet) */
  127. PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
  128. PyAPI_DATA(int) (*PyOS_InputHook)(void);
  129. PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
  130. PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
  131. /* Stack size, in "pointers" (so we get extra safety margins
  132. on 64-bit platforms). On a 32-bit platform, this translates
  133. to a 8k margin. */
  134. #define PYOS_STACK_MARGIN 2048
  135. #if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
  136. /* Enable stack checking under Microsoft C */
  137. #define USE_STACKCHECK
  138. #endif
  139. #ifdef USE_STACKCHECK
  140. /* Check that we aren't overflowing our stack */
  141. PyAPI_FUNC(int) PyOS_CheckStack(void);
  142. #endif
  143. /* Signals */
  144. typedef void (*PyOS_sighandler_t)(int);
  145. PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
  146. PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
  147. /* Random */
  148. PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* !Py_PYTHONRUN_H */