diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/_multiprocessing | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/_multiprocessing')
3 files changed, 284 insertions, 284 deletions
diff --git a/contrib/tools/python3/src/Modules/_multiprocessing/clinic/posixshmem.c.h b/contrib/tools/python3/src/Modules/_multiprocessing/clinic/posixshmem.c.h index cbe09befea..a99f0d2aae 100644 --- a/contrib/tools/python3/src/Modules/_multiprocessing/clinic/posixshmem.c.h +++ b/contrib/tools/python3/src/Modules/_multiprocessing/clinic/posixshmem.c.h @@ -1,133 +1,133 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -#if defined(HAVE_SHM_OPEN) - -PyDoc_STRVAR(_posixshmem_shm_open__doc__, -"shm_open($module, /, path, flags, mode=511)\n" -"--\n" -"\n" -"Open a shared memory object. Returns a file descriptor (integer)."); - -#define _POSIXSHMEM_SHM_OPEN_METHODDEF \ - {"shm_open", (PyCFunction)(void(*)(void))_posixshmem_shm_open, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__}, - -static int -_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags, - int mode); - -static PyObject * -_posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"path", "flags", "mode", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "shm_open", 0}; - PyObject *argsbuf[3]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; - PyObject *path; - int flags; - int mode = 511; - int _return_value; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); - if (!args) { - goto exit; - } - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]); - goto exit; - } - if (PyUnicode_READY(args[0]) == -1) { - goto exit; - } - path = args[0]; - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - flags = _PyLong_AsInt(args[1]); - if (flags == -1 && PyErr_Occurred()) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - mode = _PyLong_AsInt(args[2]); - if (mode == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: - _return_value = _posixshmem_shm_open_impl(module, path, flags, mode); - if ((_return_value == -1) && PyErr_Occurred()) { - goto exit; - } - return_value = PyLong_FromLong((long)_return_value); - -exit: - return return_value; -} - -#endif /* defined(HAVE_SHM_OPEN) */ - -#if defined(HAVE_SHM_UNLINK) - -PyDoc_STRVAR(_posixshmem_shm_unlink__doc__, -"shm_unlink($module, /, path)\n" -"--\n" -"\n" -"Remove a shared memory object (similar to unlink()).\n" -"\n" -"Remove a shared memory object name, and, once all processes have unmapped\n" -"the object, de-allocates and destroys the contents of the associated memory\n" -"region."); - -#define _POSIXSHMEM_SHM_UNLINK_METHODDEF \ - {"shm_unlink", (PyCFunction)(void(*)(void))_posixshmem_shm_unlink, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__}, - -static PyObject * -_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path); - -static PyObject * -_posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"path", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "shm_unlink", 0}; - PyObject *argsbuf[1]; - PyObject *path; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]); - goto exit; - } - if (PyUnicode_READY(args[0]) == -1) { - goto exit; - } - path = args[0]; - return_value = _posixshmem_shm_unlink_impl(module, path); - -exit: - return return_value; -} - -#endif /* defined(HAVE_SHM_UNLINK) */ - -#ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF - #define _POSIXSHMEM_SHM_OPEN_METHODDEF -#endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */ - -#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF - #define _POSIXSHMEM_SHM_UNLINK_METHODDEF -#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */ -/*[clinic end generated code: output=9132861c61d8c2d8 input=a9049054013a1b77]*/ +/*[clinic input] +preserve +[clinic start generated code]*/ + +#if defined(HAVE_SHM_OPEN) + +PyDoc_STRVAR(_posixshmem_shm_open__doc__, +"shm_open($module, /, path, flags, mode=511)\n" +"--\n" +"\n" +"Open a shared memory object. Returns a file descriptor (integer)."); + +#define _POSIXSHMEM_SHM_OPEN_METHODDEF \ + {"shm_open", (PyCFunction)(void(*)(void))_posixshmem_shm_open, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__}, + +static int +_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags, + int mode); + +static PyObject * +_posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"path", "flags", "mode", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "shm_open", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; + PyObject *path; + int flags; + int mode = 511; + int _return_value; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + path = args[0]; + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[1]); + if (flags == -1 && PyErr_Occurred()) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(args[2]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: + _return_value = _posixshmem_shm_open_impl(module, path, flags, mode); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromLong((long)_return_value); + +exit: + return return_value; +} + +#endif /* defined(HAVE_SHM_OPEN) */ + +#if defined(HAVE_SHM_UNLINK) + +PyDoc_STRVAR(_posixshmem_shm_unlink__doc__, +"shm_unlink($module, /, path)\n" +"--\n" +"\n" +"Remove a shared memory object (similar to unlink()).\n" +"\n" +"Remove a shared memory object name, and, once all processes have unmapped\n" +"the object, de-allocates and destroys the contents of the associated memory\n" +"region."); + +#define _POSIXSHMEM_SHM_UNLINK_METHODDEF \ + {"shm_unlink", (PyCFunction)(void(*)(void))_posixshmem_shm_unlink, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__}, + +static PyObject * +_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path); + +static PyObject * +_posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"path", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "shm_unlink", 0}; + PyObject *argsbuf[1]; + PyObject *path; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + path = args[0]; + return_value = _posixshmem_shm_unlink_impl(module, path); + +exit: + return return_value; +} + +#endif /* defined(HAVE_SHM_UNLINK) */ + +#ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF + #define _POSIXSHMEM_SHM_OPEN_METHODDEF +#endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */ + +#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF + #define _POSIXSHMEM_SHM_UNLINK_METHODDEF +#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */ +/*[clinic end generated code: output=9132861c61d8c2d8 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Modules/_multiprocessing/posixshmem.c b/contrib/tools/python3/src/Modules/_multiprocessing/posixshmem.c index 584e98f173..436ac6d6b3 100644 --- a/contrib/tools/python3/src/Modules/_multiprocessing/posixshmem.c +++ b/contrib/tools/python3/src/Modules/_multiprocessing/posixshmem.c @@ -1,130 +1,130 @@ -/* -posixshmem - A Python extension that provides shm_open() and shm_unlink() -*/ - -#define PY_SSIZE_T_CLEAN - -#include <Python.h> - -// for shm_open() and shm_unlink() -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif - -/*[clinic input] -module _posixshmem -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a416734e49164bf8]*/ - -/* - * - * Module-level functions & meta stuff - * - */ - -#ifdef HAVE_SHM_OPEN -/*[clinic input] -_posixshmem.shm_open -> int - path: unicode - flags: int - mode: int = 0o777 - -# "shm_open(path, flags, mode=0o777)\n\n\ - -Open a shared memory object. Returns a file descriptor (integer). - -[clinic start generated code]*/ - -static int -_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags, - int mode) -/*[clinic end generated code: output=8d110171a4fa20df input=e83b58fa802fac25]*/ -{ - int fd; - int async_err = 0; - const char *name = PyUnicode_AsUTF8(path); - if (name == NULL) { - return -1; - } - do { - Py_BEGIN_ALLOW_THREADS - fd = shm_open(name, flags, mode); - Py_END_ALLOW_THREADS - } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); - - if (fd < 0) { - if (!async_err) - PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); - return -1; - } - - return fd; -} -#endif /* HAVE_SHM_OPEN */ - -#ifdef HAVE_SHM_UNLINK -/*[clinic input] -_posixshmem.shm_unlink - path: unicode - -Remove a shared memory object (similar to unlink()). - -Remove a shared memory object name, and, once all processes have unmapped -the object, de-allocates and destroys the contents of the associated memory -region. - -[clinic start generated code]*/ - -static PyObject * -_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path) -/*[clinic end generated code: output=42f8b23d134b9ff5 input=8dc0f87143e3b300]*/ -{ - int rv; - int async_err = 0; - const char *name = PyUnicode_AsUTF8(path); - if (name == NULL) { - return NULL; - } - do { - Py_BEGIN_ALLOW_THREADS - rv = shm_unlink(name); - Py_END_ALLOW_THREADS - } while (rv < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); - - if (rv < 0) { - if (!async_err) - PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); - return NULL; - } - - Py_RETURN_NONE; -} -#endif /* HAVE_SHM_UNLINK */ - -#include "clinic/posixshmem.c.h" - -static PyMethodDef module_methods[ ] = { - _POSIXSHMEM_SHM_OPEN_METHODDEF - _POSIXSHMEM_SHM_UNLINK_METHODDEF - {NULL} /* Sentinel */ -}; - - -static struct PyModuleDef this_module = { - PyModuleDef_HEAD_INIT, // m_base - "_posixshmem", // m_name - "POSIX shared memory module", // m_doc - -1, // m_size (space allocated for module globals) - module_methods, // m_methods -}; - -/* Module init function */ -PyMODINIT_FUNC -PyInit__posixshmem(void) { - PyObject *module; - module = PyModule_Create(&this_module); - if (!module) { - return NULL; - } - return module; -} +/* +posixshmem - A Python extension that provides shm_open() and shm_unlink() +*/ + +#define PY_SSIZE_T_CLEAN + +#include <Python.h> + +// for shm_open() and shm_unlink() +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif + +/*[clinic input] +module _posixshmem +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a416734e49164bf8]*/ + +/* + * + * Module-level functions & meta stuff + * + */ + +#ifdef HAVE_SHM_OPEN +/*[clinic input] +_posixshmem.shm_open -> int + path: unicode + flags: int + mode: int = 0o777 + +# "shm_open(path, flags, mode=0o777)\n\n\ + +Open a shared memory object. Returns a file descriptor (integer). + +[clinic start generated code]*/ + +static int +_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags, + int mode) +/*[clinic end generated code: output=8d110171a4fa20df input=e83b58fa802fac25]*/ +{ + int fd; + int async_err = 0; + const char *name = PyUnicode_AsUTF8(path); + if (name == NULL) { + return -1; + } + do { + Py_BEGIN_ALLOW_THREADS + fd = shm_open(name, flags, mode); + Py_END_ALLOW_THREADS + } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); + + if (fd < 0) { + if (!async_err) + PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); + return -1; + } + + return fd; +} +#endif /* HAVE_SHM_OPEN */ + +#ifdef HAVE_SHM_UNLINK +/*[clinic input] +_posixshmem.shm_unlink + path: unicode + +Remove a shared memory object (similar to unlink()). + +Remove a shared memory object name, and, once all processes have unmapped +the object, de-allocates and destroys the contents of the associated memory +region. + +[clinic start generated code]*/ + +static PyObject * +_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path) +/*[clinic end generated code: output=42f8b23d134b9ff5 input=8dc0f87143e3b300]*/ +{ + int rv; + int async_err = 0; + const char *name = PyUnicode_AsUTF8(path); + if (name == NULL) { + return NULL; + } + do { + Py_BEGIN_ALLOW_THREADS + rv = shm_unlink(name); + Py_END_ALLOW_THREADS + } while (rv < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); + + if (rv < 0) { + if (!async_err) + PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); + return NULL; + } + + Py_RETURN_NONE; +} +#endif /* HAVE_SHM_UNLINK */ + +#include "clinic/posixshmem.c.h" + +static PyMethodDef module_methods[ ] = { + _POSIXSHMEM_SHM_OPEN_METHODDEF + _POSIXSHMEM_SHM_UNLINK_METHODDEF + {NULL} /* Sentinel */ +}; + + +static struct PyModuleDef this_module = { + PyModuleDef_HEAD_INIT, // m_base + "_posixshmem", // m_name + "POSIX shared memory module", // m_doc + -1, // m_size (space allocated for module globals) + module_methods, // m_methods +}; + +/* Module init function */ +PyMODINIT_FUNC +PyInit__posixshmem(void) { + PyObject *module; + module = PyModule_Create(&this_module); + if (!module) { + return NULL; + } + return module; +} diff --git a/contrib/tools/python3/src/Modules/_multiprocessing/semaphore.c b/contrib/tools/python3/src/Modules/_multiprocessing/semaphore.c index 19b4209a55..ee490256d2 100644 --- a/contrib/tools/python3/src/Modules/_multiprocessing/semaphore.c +++ b/contrib/tools/python3/src/Modules/_multiprocessing/semaphore.c @@ -141,7 +141,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds) default: PyErr_Format(PyExc_RuntimeError, "WaitForSingleObject() or " "WaitForMultipleObjects() gave unrecognized " - "value %u", res); + "value %u", res); return NULL; } } @@ -282,23 +282,23 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds) Py_RETURN_TRUE; } - int use_deadline = (timeout_obj != Py_None); - if (use_deadline) { - double timeout = PyFloat_AsDouble(timeout_obj); - if (PyErr_Occurred()) { + int use_deadline = (timeout_obj != Py_None); + if (use_deadline) { + double timeout = PyFloat_AsDouble(timeout_obj); + if (PyErr_Occurred()) { return NULL; - } - if (timeout < 0.0) { + } + if (timeout < 0.0) { timeout = 0.0; - } + } - struct timeval now; + struct timeval now; if (gettimeofday(&now, NULL) < 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } - long sec = (long) timeout; - long nsec = (long) (1e9 * (timeout - sec) + 0.5); + long sec = (long) timeout; + long nsec = (long) (1e9 * (timeout - sec) + 0.5); deadline.tv_sec = now.tv_sec + sec; deadline.tv_nsec = now.tv_usec * 1000 + nsec; deadline.tv_sec += (deadline.tv_nsec / 1000000000); @@ -316,7 +316,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds) /* Couldn't acquire immediately, need to block */ do { Py_BEGIN_ALLOW_THREADS - if (!use_deadline) { + if (!use_deadline) { res = sem_wait(self->handle); } else { @@ -522,20 +522,20 @@ semlock_dealloc(SemLockObject* self) } static PyObject * -semlock_count(SemLockObject *self, PyObject *Py_UNUSED(ignored)) +semlock_count(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong((long)self->count); } static PyObject * -semlock_ismine(SemLockObject *self, PyObject *Py_UNUSED(ignored)) +semlock_ismine(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { /* only makes sense for a lock */ return PyBool_FromLong(ISMINE(self)); } static PyObject * -semlock_getvalue(SemLockObject *self, PyObject *Py_UNUSED(ignored)) +semlock_getvalue(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { #ifdef HAVE_BROKEN_SEM_GETVALUE PyErr_SetNone(PyExc_NotImplementedError); @@ -553,7 +553,7 @@ semlock_getvalue(SemLockObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject * -semlock_iszero(SemLockObject *self, PyObject *Py_UNUSED(ignored)) +semlock_iszero(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { #ifdef HAVE_BROKEN_SEM_GETVALUE if (sem_trywait(self->handle) < 0) { @@ -574,7 +574,7 @@ semlock_iszero(SemLockObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject * -semlock_afterfork(SemLockObject *self, PyObject *Py_UNUSED(ignored)) +semlock_afterfork(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { self->count = 0; Py_RETURN_NONE; @@ -585,11 +585,11 @@ semlock_afterfork(SemLockObject *self, PyObject *Py_UNUSED(ignored)) */ static PyMethodDef semlock_methods[] = { - {"acquire", (PyCFunction)(void(*)(void))semlock_acquire, METH_VARARGS | METH_KEYWORDS, + {"acquire", (PyCFunction)(void(*)(void))semlock_acquire, METH_VARARGS | METH_KEYWORDS, "acquire the semaphore/lock"}, {"release", (PyCFunction)semlock_release, METH_NOARGS, "release the semaphore/lock"}, - {"__enter__", (PyCFunction)(void(*)(void))semlock_acquire, METH_VARARGS | METH_KEYWORDS, + {"__enter__", (PyCFunction)(void(*)(void))semlock_acquire, METH_VARARGS | METH_KEYWORDS, "enter the semaphore/lock"}, {"__exit__", (PyCFunction)semlock_release, METH_VARARGS, "exit the semaphore/lock"}, @@ -634,10 +634,10 @@ PyTypeObject _PyMp_SemLockType = { /* tp_basicsize */ sizeof(SemLockObject), /* tp_itemsize */ 0, /* tp_dealloc */ (destructor)semlock_dealloc, - /* tp_vectorcall_offset */ 0, + /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, - /* tp_as_async */ 0, + /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, |