1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(HAVE_SHM_OPEN)
6
7 PyDoc_STRVAR(_posixshmem_shm_open__doc__,
8 "shm_open($module, /, path, flags, mode=511)\n"
9 "--\n"
10 "\n"
11 "Open a shared memory object. Returns a file descriptor (integer).");
12
13 #define _POSIXSHMEM_SHM_OPEN_METHODDEF \
14 {"shm_open", (PyCFunction)(void(*)(void))_posixshmem_shm_open, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__},
15
16 static int
17 _posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
18 int mode);
19
20 static PyObject *
_posixshmem_shm_open(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)21 _posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
22 {
23 PyObject *return_value = NULL;
24 static const char * const _keywords[] = {"path", "flags", "mode", NULL};
25 static _PyArg_Parser _parser = {NULL, _keywords, "shm_open", 0};
26 PyObject *argsbuf[3];
27 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
28 PyObject *path;
29 int flags;
30 int mode = 511;
31 int _return_value;
32
33 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
34 if (!args) {
35 goto exit;
36 }
37 if (!PyUnicode_Check(args[0])) {
38 _PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);
39 goto exit;
40 }
41 if (PyUnicode_READY(args[0]) == -1) {
42 goto exit;
43 }
44 path = args[0];
45 flags = _PyLong_AsInt(args[1]);
46 if (flags == -1 && PyErr_Occurred()) {
47 goto exit;
48 }
49 if (!noptargs) {
50 goto skip_optional_pos;
51 }
52 mode = _PyLong_AsInt(args[2]);
53 if (mode == -1 && PyErr_Occurred()) {
54 goto exit;
55 }
56 skip_optional_pos:
57 _return_value = _posixshmem_shm_open_impl(module, path, flags, mode);
58 if ((_return_value == -1) && PyErr_Occurred()) {
59 goto exit;
60 }
61 return_value = PyLong_FromLong((long)_return_value);
62
63 exit:
64 return return_value;
65 }
66
67 #endif /* defined(HAVE_SHM_OPEN) */
68
69 #if defined(HAVE_SHM_UNLINK)
70
71 PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,
72 "shm_unlink($module, /, path)\n"
73 "--\n"
74 "\n"
75 "Remove a shared memory object (similar to unlink()).\n"
76 "\n"
77 "Remove a shared memory object name, and, once all processes have unmapped\n"
78 "the object, de-allocates and destroys the contents of the associated memory\n"
79 "region.");
80
81 #define _POSIXSHMEM_SHM_UNLINK_METHODDEF \
82 {"shm_unlink", (PyCFunction)(void(*)(void))_posixshmem_shm_unlink, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},
83
84 static PyObject *
85 _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);
86
87 static PyObject *
_posixshmem_shm_unlink(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)88 _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
89 {
90 PyObject *return_value = NULL;
91 static const char * const _keywords[] = {"path", NULL};
92 static _PyArg_Parser _parser = {NULL, _keywords, "shm_unlink", 0};
93 PyObject *argsbuf[1];
94 PyObject *path;
95
96 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
97 if (!args) {
98 goto exit;
99 }
100 if (!PyUnicode_Check(args[0])) {
101 _PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
102 goto exit;
103 }
104 if (PyUnicode_READY(args[0]) == -1) {
105 goto exit;
106 }
107 path = args[0];
108 return_value = _posixshmem_shm_unlink_impl(module, path);
109
110 exit:
111 return return_value;
112 }
113
114 #endif /* defined(HAVE_SHM_UNLINK) */
115
116 #ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF
117 #define _POSIXSHMEM_SHM_OPEN_METHODDEF
118 #endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */
119
120 #ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
121 #define _POSIXSHMEM_SHM_UNLINK_METHODDEF
122 #endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
123 /*[clinic end generated code: output=bca8e78d0f43ef1a input=a9049054013a1b77]*/
124