Branch data Line data Source code
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 : 0 : _posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
28 : : {
29 : 0 : 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 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
57 : : PyObject *path;
58 : : int flags;
59 : 0 : int mode = 511;
60 : : int _return_value;
61 : :
62 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
# # # # ]
63 [ # # ]: 0 : if (!args) {
64 : 0 : goto exit;
65 : : }
66 [ # # ]: 0 : if (!PyUnicode_Check(args[0])) {
67 : 0 : _PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);
68 : 0 : goto exit;
69 : : }
70 [ # # ]: 0 : if (PyUnicode_READY(args[0]) == -1) {
71 : 0 : goto exit;
72 : : }
73 : 0 : path = args[0];
74 : 0 : flags = _PyLong_AsInt(args[1]);
75 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
76 : 0 : goto exit;
77 : : }
78 [ # # ]: 0 : if (!noptargs) {
79 : 0 : goto skip_optional_pos;
80 : : }
81 : 0 : mode = _PyLong_AsInt(args[2]);
82 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
83 : 0 : goto exit;
84 : : }
85 : 0 : skip_optional_pos:
86 : 0 : _return_value = _posixshmem_shm_open_impl(module, path, flags, mode);
87 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
88 : 0 : goto exit;
89 : : }
90 : 0 : return_value = PyLong_FromLong((long)_return_value);
91 : :
92 : 0 : exit:
93 : 0 : return return_value;
94 : : }
95 : :
96 : : #endif /* defined(HAVE_SHM_OPEN) */
97 : :
98 : : #if defined(HAVE_SHM_UNLINK)
99 : :
100 : : PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,
101 : : "shm_unlink($module, /, path)\n"
102 : : "--\n"
103 : : "\n"
104 : : "Remove a shared memory object (similar to unlink()).\n"
105 : : "\n"
106 : : "Remove a shared memory object name, and, once all processes have unmapped\n"
107 : : "the object, de-allocates and destroys the contents of the associated memory\n"
108 : : "region.");
109 : :
110 : : #define _POSIXSHMEM_SHM_UNLINK_METHODDEF \
111 : : {"shm_unlink", _PyCFunction_CAST(_posixshmem_shm_unlink), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},
112 : :
113 : : static PyObject *
114 : : _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);
115 : :
116 : : static PyObject *
117 : 0 : _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
118 : : {
119 : 0 : PyObject *return_value = NULL;
120 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
121 : :
122 : : #define NUM_KEYWORDS 1
123 : : static struct {
124 : : PyGC_Head _this_is_not_used;
125 : : PyObject_VAR_HEAD
126 : : PyObject *ob_item[NUM_KEYWORDS];
127 : : } _kwtuple = {
128 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
129 : : .ob_item = { &_Py_ID(path), },
130 : : };
131 : : #undef NUM_KEYWORDS
132 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
133 : :
134 : : #else // !Py_BUILD_CORE
135 : : # define KWTUPLE NULL
136 : : #endif // !Py_BUILD_CORE
137 : :
138 : : static const char * const _keywords[] = {"path", NULL};
139 : : static _PyArg_Parser _parser = {
140 : : .keywords = _keywords,
141 : : .fname = "shm_unlink",
142 : : .kwtuple = KWTUPLE,
143 : : };
144 : : #undef KWTUPLE
145 : : PyObject *argsbuf[1];
146 : : PyObject *path;
147 : :
148 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
149 [ # # ]: 0 : if (!args) {
150 : 0 : goto exit;
151 : : }
152 [ # # ]: 0 : if (!PyUnicode_Check(args[0])) {
153 : 0 : _PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
154 : 0 : goto exit;
155 : : }
156 [ # # ]: 0 : if (PyUnicode_READY(args[0]) == -1) {
157 : 0 : goto exit;
158 : : }
159 : 0 : path = args[0];
160 : 0 : return_value = _posixshmem_shm_unlink_impl(module, path);
161 : :
162 : 0 : exit:
163 : 0 : return return_value;
164 : : }
165 : :
166 : : #endif /* defined(HAVE_SHM_UNLINK) */
167 : :
168 : : #ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF
169 : : #define _POSIXSHMEM_SHM_OPEN_METHODDEF
170 : : #endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */
171 : :
172 : : #ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
173 : : #define _POSIXSHMEM_SHM_UNLINK_METHODDEF
174 : : #endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
175 : : /*[clinic end generated code: output=3f6fee283d5fd0e9 input=a9049054013a1b77]*/
|