Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_multiprocessing/clinic/posixshmem.c.h
12 views
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
# include "pycore_gc.h" // PyGC_Head
7
# include "pycore_runtime.h" // _Py_ID()
8
#endif
9
10
11
#if defined(HAVE_SHM_OPEN)
12
13
PyDoc_STRVAR(_posixshmem_shm_open__doc__,
14
"shm_open($module, /, path, flags, mode=511)\n"
15
"--\n"
16
"\n"
17
"Open a shared memory object. Returns a file descriptor (integer).");
18
19
#define _POSIXSHMEM_SHM_OPEN_METHODDEF \
20
{"shm_open", _PyCFunction_CAST(_posixshmem_shm_open), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__},
21
22
static int
23
_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
24
int mode);
25
26
static PyObject *
27
_posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
28
{
29
PyObject *return_value = NULL;
30
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
31
32
#define NUM_KEYWORDS 3
33
static struct {
34
PyGC_Head _this_is_not_used;
35
PyObject_VAR_HEAD
36
PyObject *ob_item[NUM_KEYWORDS];
37
} _kwtuple = {
38
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
39
.ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), },
40
};
41
#undef NUM_KEYWORDS
42
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
43
44
#else // !Py_BUILD_CORE
45
# define KWTUPLE NULL
46
#endif // !Py_BUILD_CORE
47
48
static const char * const _keywords[] = {"path", "flags", "mode", NULL};
49
static _PyArg_Parser _parser = {
50
.keywords = _keywords,
51
.fname = "shm_open",
52
.kwtuple = KWTUPLE,
53
};
54
#undef KWTUPLE
55
PyObject *argsbuf[3];
56
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
57
PyObject *path;
58
int flags;
59
int mode = 511;
60
int _return_value;
61
62
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
63
if (!args) {
64
goto exit;
65
}
66
if (!PyUnicode_Check(args[0])) {
67
_PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);
68
goto exit;
69
}
70
path = args[0];
71
flags = _PyLong_AsInt(args[1]);
72
if (flags == -1 && PyErr_Occurred()) {
73
goto exit;
74
}
75
if (!noptargs) {
76
goto skip_optional_pos;
77
}
78
mode = _PyLong_AsInt(args[2]);
79
if (mode == -1 && PyErr_Occurred()) {
80
goto exit;
81
}
82
skip_optional_pos:
83
_return_value = _posixshmem_shm_open_impl(module, path, flags, mode);
84
if ((_return_value == -1) && PyErr_Occurred()) {
85
goto exit;
86
}
87
return_value = PyLong_FromLong((long)_return_value);
88
89
exit:
90
return return_value;
91
}
92
93
#endif /* defined(HAVE_SHM_OPEN) */
94
95
#if defined(HAVE_SHM_UNLINK)
96
97
PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,
98
"shm_unlink($module, /, path)\n"
99
"--\n"
100
"\n"
101
"Remove a shared memory object (similar to unlink()).\n"
102
"\n"
103
"Remove a shared memory object name, and, once all processes have unmapped\n"
104
"the object, de-allocates and destroys the contents of the associated memory\n"
105
"region.");
106
107
#define _POSIXSHMEM_SHM_UNLINK_METHODDEF \
108
{"shm_unlink", _PyCFunction_CAST(_posixshmem_shm_unlink), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},
109
110
static PyObject *
111
_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);
112
113
static PyObject *
114
_posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
115
{
116
PyObject *return_value = NULL;
117
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
118
119
#define NUM_KEYWORDS 1
120
static struct {
121
PyGC_Head _this_is_not_used;
122
PyObject_VAR_HEAD
123
PyObject *ob_item[NUM_KEYWORDS];
124
} _kwtuple = {
125
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
126
.ob_item = { &_Py_ID(path), },
127
};
128
#undef NUM_KEYWORDS
129
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
130
131
#else // !Py_BUILD_CORE
132
# define KWTUPLE NULL
133
#endif // !Py_BUILD_CORE
134
135
static const char * const _keywords[] = {"path", NULL};
136
static _PyArg_Parser _parser = {
137
.keywords = _keywords,
138
.fname = "shm_unlink",
139
.kwtuple = KWTUPLE,
140
};
141
#undef KWTUPLE
142
PyObject *argsbuf[1];
143
PyObject *path;
144
145
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
146
if (!args) {
147
goto exit;
148
}
149
if (!PyUnicode_Check(args[0])) {
150
_PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
151
goto exit;
152
}
153
path = args[0];
154
return_value = _posixshmem_shm_unlink_impl(module, path);
155
156
exit:
157
return return_value;
158
}
159
160
#endif /* defined(HAVE_SHM_UNLINK) */
161
162
#ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF
163
#define _POSIXSHMEM_SHM_OPEN_METHODDEF
164
#endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */
165
166
#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
167
#define _POSIXSHMEM_SHM_UNLINK_METHODDEF
168
#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
169
/*[clinic end generated code: output=9b67f98885757bc4 input=a9049054013a1b77]*/
170
171