multiprocessing.c.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. #if defined(MS_WINDOWS)
  9. PyDoc_STRVAR(_multiprocessing_closesocket__doc__,
  10. "closesocket($module, handle, /)\n"
  11. "--\n"
  12. "\n");
  13. #define _MULTIPROCESSING_CLOSESOCKET_METHODDEF \
  14. {"closesocket", (PyCFunction)_multiprocessing_closesocket, METH_O, _multiprocessing_closesocket__doc__},
  15. static PyObject *
  16. _multiprocessing_closesocket_impl(PyObject *module, HANDLE handle);
  17. static PyObject *
  18. _multiprocessing_closesocket(PyObject *module, PyObject *arg)
  19. {
  20. PyObject *return_value = NULL;
  21. HANDLE handle;
  22. handle = PyLong_AsVoidPtr(arg);
  23. if (!handle && PyErr_Occurred()) {
  24. goto exit;
  25. }
  26. return_value = _multiprocessing_closesocket_impl(module, handle);
  27. exit:
  28. return return_value;
  29. }
  30. #endif /* defined(MS_WINDOWS) */
  31. #if defined(MS_WINDOWS)
  32. PyDoc_STRVAR(_multiprocessing_recv__doc__,
  33. "recv($module, handle, size, /)\n"
  34. "--\n"
  35. "\n");
  36. #define _MULTIPROCESSING_RECV_METHODDEF \
  37. {"recv", _PyCFunction_CAST(_multiprocessing_recv), METH_FASTCALL, _multiprocessing_recv__doc__},
  38. static PyObject *
  39. _multiprocessing_recv_impl(PyObject *module, HANDLE handle, int size);
  40. static PyObject *
  41. _multiprocessing_recv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  42. {
  43. PyObject *return_value = NULL;
  44. HANDLE handle;
  45. int size;
  46. if (!_PyArg_CheckPositional("recv", nargs, 2, 2)) {
  47. goto exit;
  48. }
  49. handle = PyLong_AsVoidPtr(args[0]);
  50. if (!handle && PyErr_Occurred()) {
  51. goto exit;
  52. }
  53. size = _PyLong_AsInt(args[1]);
  54. if (size == -1 && PyErr_Occurred()) {
  55. goto exit;
  56. }
  57. return_value = _multiprocessing_recv_impl(module, handle, size);
  58. exit:
  59. return return_value;
  60. }
  61. #endif /* defined(MS_WINDOWS) */
  62. #if defined(MS_WINDOWS)
  63. PyDoc_STRVAR(_multiprocessing_send__doc__,
  64. "send($module, handle, buf, /)\n"
  65. "--\n"
  66. "\n");
  67. #define _MULTIPROCESSING_SEND_METHODDEF \
  68. {"send", _PyCFunction_CAST(_multiprocessing_send), METH_FASTCALL, _multiprocessing_send__doc__},
  69. static PyObject *
  70. _multiprocessing_send_impl(PyObject *module, HANDLE handle, Py_buffer *buf);
  71. static PyObject *
  72. _multiprocessing_send(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  73. {
  74. PyObject *return_value = NULL;
  75. HANDLE handle;
  76. Py_buffer buf = {NULL, NULL};
  77. if (!_PyArg_CheckPositional("send", nargs, 2, 2)) {
  78. goto exit;
  79. }
  80. handle = PyLong_AsVoidPtr(args[0]);
  81. if (!handle && PyErr_Occurred()) {
  82. goto exit;
  83. }
  84. if (PyObject_GetBuffer(args[1], &buf, PyBUF_SIMPLE) != 0) {
  85. goto exit;
  86. }
  87. if (!PyBuffer_IsContiguous(&buf, 'C')) {
  88. _PyArg_BadArgument("send", "argument 2", "contiguous buffer", args[1]);
  89. goto exit;
  90. }
  91. return_value = _multiprocessing_send_impl(module, handle, &buf);
  92. exit:
  93. /* Cleanup for buf */
  94. if (buf.obj) {
  95. PyBuffer_Release(&buf);
  96. }
  97. return return_value;
  98. }
  99. #endif /* defined(MS_WINDOWS) */
  100. PyDoc_STRVAR(_multiprocessing_sem_unlink__doc__,
  101. "sem_unlink($module, name, /)\n"
  102. "--\n"
  103. "\n");
  104. #define _MULTIPROCESSING_SEM_UNLINK_METHODDEF \
  105. {"sem_unlink", (PyCFunction)_multiprocessing_sem_unlink, METH_O, _multiprocessing_sem_unlink__doc__},
  106. static PyObject *
  107. _multiprocessing_sem_unlink_impl(PyObject *module, const char *name);
  108. static PyObject *
  109. _multiprocessing_sem_unlink(PyObject *module, PyObject *arg)
  110. {
  111. PyObject *return_value = NULL;
  112. const char *name;
  113. if (!PyUnicode_Check(arg)) {
  114. _PyArg_BadArgument("sem_unlink", "argument", "str", arg);
  115. goto exit;
  116. }
  117. Py_ssize_t name_length;
  118. name = PyUnicode_AsUTF8AndSize(arg, &name_length);
  119. if (name == NULL) {
  120. goto exit;
  121. }
  122. if (strlen(name) != (size_t)name_length) {
  123. PyErr_SetString(PyExc_ValueError, "embedded null character");
  124. goto exit;
  125. }
  126. return_value = _multiprocessing_sem_unlink_impl(module, name);
  127. exit:
  128. return return_value;
  129. }
  130. #ifndef _MULTIPROCESSING_CLOSESOCKET_METHODDEF
  131. #define _MULTIPROCESSING_CLOSESOCKET_METHODDEF
  132. #endif /* !defined(_MULTIPROCESSING_CLOSESOCKET_METHODDEF) */
  133. #ifndef _MULTIPROCESSING_RECV_METHODDEF
  134. #define _MULTIPROCESSING_RECV_METHODDEF
  135. #endif /* !defined(_MULTIPROCESSING_RECV_METHODDEF) */
  136. #ifndef _MULTIPROCESSING_SEND_METHODDEF
  137. #define _MULTIPROCESSING_SEND_METHODDEF
  138. #endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */
  139. /*[clinic end generated code: output=4a6afc67c1f5ec85 input=a9049054013a1b77]*/