• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     if (PyFloat_Check(args[1])) {
46         PyErr_SetString(PyExc_TypeError,
47                         "integer argument expected, got float" );
48         goto exit;
49     }
50     flags = _PyLong_AsInt(args[1]);
51     if (flags == -1 && PyErr_Occurred()) {
52         goto exit;
53     }
54     if (!noptargs) {
55         goto skip_optional_pos;
56     }
57     if (PyFloat_Check(args[2])) {
58         PyErr_SetString(PyExc_TypeError,
59                         "integer argument expected, got float" );
60         goto exit;
61     }
62     mode = _PyLong_AsInt(args[2]);
63     if (mode == -1 && PyErr_Occurred()) {
64         goto exit;
65     }
66 skip_optional_pos:
67     _return_value = _posixshmem_shm_open_impl(module, path, flags, mode);
68     if ((_return_value == -1) && PyErr_Occurred()) {
69         goto exit;
70     }
71     return_value = PyLong_FromLong((long)_return_value);
72 
73 exit:
74     return return_value;
75 }
76 
77 #endif /* defined(HAVE_SHM_OPEN) */
78 
79 #if defined(HAVE_SHM_UNLINK)
80 
81 PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,
82 "shm_unlink($module, /, path)\n"
83 "--\n"
84 "\n"
85 "Remove a shared memory object (similar to unlink()).\n"
86 "\n"
87 "Remove a shared memory object name, and, once all processes  have  unmapped\n"
88 "the object, de-allocates and destroys the contents of the associated memory\n"
89 "region.");
90 
91 #define _POSIXSHMEM_SHM_UNLINK_METHODDEF    \
92     {"shm_unlink", (PyCFunction)(void(*)(void))_posixshmem_shm_unlink, METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},
93 
94 static PyObject *
95 _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);
96 
97 static PyObject *
_posixshmem_shm_unlink(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)98 _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
99 {
100     PyObject *return_value = NULL;
101     static const char * const _keywords[] = {"path", NULL};
102     static _PyArg_Parser _parser = {NULL, _keywords, "shm_unlink", 0};
103     PyObject *argsbuf[1];
104     PyObject *path;
105 
106     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
107     if (!args) {
108         goto exit;
109     }
110     if (!PyUnicode_Check(args[0])) {
111         _PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
112         goto exit;
113     }
114     if (PyUnicode_READY(args[0]) == -1) {
115         goto exit;
116     }
117     path = args[0];
118     return_value = _posixshmem_shm_unlink_impl(module, path);
119 
120 exit:
121     return return_value;
122 }
123 
124 #endif /* defined(HAVE_SHM_UNLINK) */
125 
126 #ifndef _POSIXSHMEM_SHM_OPEN_METHODDEF
127     #define _POSIXSHMEM_SHM_OPEN_METHODDEF
128 #endif /* !defined(_POSIXSHMEM_SHM_OPEN_METHODDEF) */
129 
130 #ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
131     #define _POSIXSHMEM_SHM_UNLINK_METHODDEF
132 #endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
133 /*[clinic end generated code: output=9132861c61d8c2d8 input=a9049054013a1b77]*/
134