您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

100 行
1.8 KiB

  1. #include <errno.h>
  2. #include "Python.h"
  3. #include "uv.h"
  4. #ifndef EWOULDBLOCK
  5. #define EWOULDBLOCK EAGAIN
  6. #endif
  7. #ifdef __APPLE__
  8. #define PLATFORM_IS_APPLE 1
  9. #else
  10. #define PLATFORM_IS_APPLE 0
  11. #endif
  12. #ifdef __linux__
  13. # define PLATFORM_IS_LINUX 1
  14. # include <sys/epoll.h>
  15. #else
  16. # define PLATFORM_IS_LINUX 0
  17. # define EPOLL_CTL_DEL 2
  18. struct epoll_event {};
  19. int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) {};
  20. #endif
  21. #if PY_VERSION_HEX < 0x03070000
  22. PyObject * Context_CopyCurrent(void) {
  23. PyErr_SetString(PyExc_NotImplementedError,
  24. "\"contextvars\" support requires Python 3.7+");
  25. return NULL;
  26. };
  27. int Context_Enter(PyObject *ctx) {
  28. PyErr_SetString(PyExc_NotImplementedError,
  29. "\"contextvars\" support requires Python 3.7+");
  30. return -1;
  31. }
  32. int Context_Exit(PyObject *ctx) {
  33. PyErr_SetString(PyExc_NotImplementedError,
  34. "\"contextvars\" support requires Python 3.7+");
  35. return -1;
  36. }
  37. #elif PY_VERSION_HEX < 0x03070100
  38. PyObject * Context_CopyCurrent(void) {
  39. return (PyObject *)PyContext_CopyCurrent();
  40. };
  41. int Context_Enter(PyObject *ctx) {
  42. return PyContext_Enter((PyContext *)ctx);
  43. }
  44. int Context_Exit(PyObject *ctx) {
  45. return PyContext_Exit((PyContext *)ctx);
  46. }
  47. #else
  48. PyObject * Context_CopyCurrent(void) {
  49. return PyContext_CopyCurrent();
  50. };
  51. int Context_Enter(PyObject *ctx) {
  52. return PyContext_Enter(ctx);
  53. }
  54. int Context_Exit(PyObject *ctx) {
  55. return PyContext_Exit(ctx);
  56. }
  57. #endif
  58. #if PY_VERSION_HEX < 0x03070000
  59. void PyOS_BeforeFork(void)
  60. {
  61. _PyImport_AcquireLock();
  62. }
  63. void PyOS_AfterFork_Parent(void)
  64. {
  65. if (_PyImport_ReleaseLock() <= 0) {
  66. Py_FatalError("failed releasing import lock after fork");
  67. }
  68. }
  69. void PyOS_AfterFork_Child(void)
  70. {
  71. PyOS_AfterFork();
  72. }
  73. #endif