Path: blob/main/Modules/_multiprocessing/clinic/posixshmem.c.h
12 views
/*[clinic input]1preserve2[clinic start generated code]*/34#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)5# include "pycore_gc.h" // PyGC_Head6# include "pycore_runtime.h" // _Py_ID()7#endif8910#if defined(HAVE_SHM_OPEN)1112PyDoc_STRVAR(_posixshmem_shm_open__doc__,13"shm_open($module, /, path, flags, mode=511)\n"14"--\n"15"\n"16"Open a shared memory object. Returns a file descriptor (integer).");1718#define _POSIXSHMEM_SHM_OPEN_METHODDEF \19{"shm_open", _PyCFunction_CAST(_posixshmem_shm_open), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__},2021static int22_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,23int mode);2425static PyObject *26_posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)27{28PyObject *return_value = NULL;29#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)3031#define NUM_KEYWORDS 332static struct {33PyGC_Head _this_is_not_used;34PyObject_VAR_HEAD35PyObject *ob_item[NUM_KEYWORDS];36} _kwtuple = {37.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)38.ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), },39};40#undef NUM_KEYWORDS41#define KWTUPLE (&_kwtuple.ob_base.ob_base)4243#else // !Py_BUILD_CORE44# define KWTUPLE NULL45#endif // !Py_BUILD_CORE4647static const char * const _keywords[] = {"path", "flags", "mode", NULL};48static _PyArg_Parser _parser = {49.keywords = _keywords,50.fname = "shm_open",51.kwtuple = KWTUPLE,52};53#undef KWTUPLE54PyObject *argsbuf[3];55Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;56PyObject *path;57int flags;58int mode = 511;59int _return_value;6061args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);62if (!args) {63goto exit;64}65if (!PyUnicode_Check(args[0])) {66_PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);67goto exit;68}69path = args[0];70flags = _PyLong_AsInt(args[1]);71if (flags == -1 && PyErr_Occurred()) {72goto exit;73}74if (!noptargs) {75goto skip_optional_pos;76}77mode = _PyLong_AsInt(args[2]);78if (mode == -1 && PyErr_Occurred()) {79goto exit;80}81skip_optional_pos:82_return_value = _posixshmem_shm_open_impl(module, path, flags, mode);83if ((_return_value == -1) && PyErr_Occurred()) {84goto exit;85}86return_value = PyLong_FromLong((long)_return_value);8788exit:89return return_value;90}9192#endif /* defined(HAVE_SHM_OPEN) */9394#if defined(HAVE_SHM_UNLINK)9596PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,97"shm_unlink($module, /, path)\n"98"--\n"99"\n"100"Remove a shared memory object (similar to unlink()).\n"101"\n"102"Remove a shared memory object name, and, once all processes have unmapped\n"103"the object, de-allocates and destroys the contents of the associated memory\n"104"region.");105106#define _POSIXSHMEM_SHM_UNLINK_METHODDEF \107{"shm_unlink", _PyCFunction_CAST(_posixshmem_shm_unlink), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},108109static PyObject *110_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);111112static PyObject *113_posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)114{115PyObject *return_value = NULL;116#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)117118#define NUM_KEYWORDS 1119static struct {120PyGC_Head _this_is_not_used;121PyObject_VAR_HEAD122PyObject *ob_item[NUM_KEYWORDS];123} _kwtuple = {124.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)125.ob_item = { &_Py_ID(path), },126};127#undef NUM_KEYWORDS128#define KWTUPLE (&_kwtuple.ob_base.ob_base)129130#else // !Py_BUILD_CORE131# define KWTUPLE NULL132#endif // !Py_BUILD_CORE133134static const char * const _keywords[] = {"path", NULL};135static _PyArg_Parser _parser = {136.keywords = _keywords,137.fname = "shm_unlink",138.kwtuple = KWTUPLE,139};140#undef KWTUPLE141PyObject *argsbuf[1];142PyObject *path;143144args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);145if (!args) {146goto exit;147}148if (!PyUnicode_Check(args[0])) {149_PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);150goto exit;151}152path = args[0];153return_value = _posixshmem_shm_unlink_impl(module, path);154155exit:156return return_value;157}158159#endif /* defined(HAVE_SHM_UNLINK) */160161#ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF162#define _POSIXSHMEM_SHM_OPEN_METHODDEF163#endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */164165#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF166#define _POSIXSHMEM_SHM_UNLINK_METHODDEF167#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */168/*[clinic end generated code: output=9b67f98885757bc4 input=a9049054013a1b77]*/169170171