Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170126)

Side by Side Diff: Modules/fcntlmodule.c

Issue 22832: Tweak parameter names for fcntl module
Patch Set: Created 4 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Modules/clinic/fcntlmodule.c.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* fcntl module */ 2 /* fcntl module */
3 3
4 #define PY_SSIZE_T_CLEAN 4 #define PY_SSIZE_T_CLEAN
5 5
6 #include "Python.h" 6 #include "Python.h"
7 7
8 #ifdef HAVE_SYS_FILE_H 8 #ifdef HAVE_SYS_FILE_H
9 #include <sys/file.h> 9 #include <sys/file.h>
10 #endif 10 #endif
(...skipping 21 matching lines...) Expand all
32 return 1; 32 return 1;
33 } 33 }
34 34
35 /* Must come after conv_descriptor definition. */ 35 /* Must come after conv_descriptor definition. */
36 #include "clinic/fcntlmodule.c.h" 36 #include "clinic/fcntlmodule.c.h"
37 37
38 /*[clinic input] 38 /*[clinic input]
39 fcntl.fcntl 39 fcntl.fcntl
40 40
41 fd: object(type='int', converter='conv_descriptor') 41 fd: object(type='int', converter='conv_descriptor')
42 code: int 42 cmd as code: int
43 arg: object = NULL 43 arg: object = NULL
Martin Panter 2015/03/20 03:24:07 I’m not familiar with this Clinic stuff, but is th
storchaka 2015/03/20 09:02:40 Yes, it is possible and it would be good.
ashkop 2015/03/20 12:24:49 Done.
44 / 44 /
45 45
46 Perform the operation `code` on file descriptor fd. 46 Perform the operation `cmd` on file descriptor fd.
47 47
48 The values used for `code` are operating system dependent, and are available 48 The values used for `cmd` are operating system dependent, and are available
49 as constants in the fcntl module, using the same names as used in 49 as constants in the fcntl module, using the same names as used in
50 the relevant C header files. The argument arg is optional, and 50 the relevant C header files. The argument arg is optional, and
51 defaults to 0; it may be an int or a string. If arg is given as a string, 51 defaults to 0; it may be an int or a string. If arg is given as a string,
52 the return value of fcntl is a string of that length, containing the 52 the return value of fcntl is a string of that length, containing the
53 resulting value put in the arg buffer by the operating system. The length 53 resulting value put in the arg buffer by the operating system. The length
54 of the arg string is not allowed to exceed 1024 bytes. If the arg given 54 of the arg string is not allowed to exceed 1024 bytes. If the arg given
55 is an integer or if none is specified, the result value is an integer 55 is an integer or if none is specified, the result value is an integer
56 corresponding to the return value of the fcntl call in the C code. 56 corresponding to the return value of the fcntl call in the C code.
57 [clinic start generated code]*/ 57 [clinic start generated code]*/
58 58
59 static PyObject * 59 static PyObject *
60 fcntl_fcntl_impl(PyModuleDef *module, int fd, int code, PyObject *arg) 60 fcntl_fcntl_impl(PyModuleDef *module, int fd, int code, PyObject *arg)
61 /*[clinic end generated code: output=afc5bfa74a03ef0d input=4850c13a41e86930]*/ 61 /*[clinic end generated code: output=afc5bfa74a03ef0d input=8c75114d221393db]*/
62 { 62 {
63 unsigned int int_arg = 0; 63 unsigned int int_arg = 0;
64 int ret; 64 int ret;
65 char *str; 65 char *str;
66 Py_ssize_t len; 66 Py_ssize_t len;
67 char buf[1024]; 67 char buf[1024];
68 68
69 if (arg != NULL) { 69 if (arg != NULL) {
70 int parse_result; 70 int parse_result;
71 71
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return NULL; 104 return NULL;
105 } 105 }
106 return PyLong_FromLong((long)ret); 106 return PyLong_FromLong((long)ret);
107 } 107 }
108 108
109 109
110 /*[clinic input] 110 /*[clinic input]
111 fcntl.ioctl 111 fcntl.ioctl
112 112
113 fd: object(type='int', converter='conv_descriptor') 113 fd: object(type='int', converter='conv_descriptor')
114 op as code: unsigned_int(bitwise=True) 114 request as code: unsigned_int(bitwise=True)
115 arg as ob_arg: object = NULL 115 arg as ob_arg: object = NULL
Martin Panter 2015/03/20 03:24:07 Would be nice to change this to arg=0 by default t
ashkop 2015/03/20 12:24:49 Done.
116 mutate_flag as mutate_arg: bool = True 116 mutate_flag as mutate_arg: bool = True
117 / 117 /
118 118
119 Perform the operation op on file descriptor fd. 119 Perform the operation `request` on file descriptor `fd`.
120 120
121 The values used for op are operating system dependent, and are available as 121 The values used for `request` are operating system dependent, and are available
122 constants in the fcntl or termios library modules, using the same names as 122 as constants in the fcntl or termios library modules, using the same names as
123 used in the relevant C header files. 123 used in the relevant C header files.
124 124
125 The argument `arg` is optional, and defaults to 0; it may be an int or a 125 The argument `arg` is optional, and defaults to 0; it may be an int or a
126 buffer containing character data (most likely a string or an array). 126 buffer containing character data (most likely a string or an array).
127 127
128 If the argument is a mutable buffer (such as an array) and if the 128 If the argument is a mutable buffer (such as an array) and if the
129 mutate_flag argument (which is only allowed in this case) is true then the 129 mutate_flag argument (which is only allowed in this case) is true then the
130 buffer is (in effect) passed to the operating system and changes made by 130 buffer is (in effect) passed to the operating system and changes made by
131 the OS will be reflected in the contents of the buffer after the call has 131 the OS will be reflected in the contents of the buffer after the call has
132 returned. The return value is the integer returned by the ioctl system 132 returned. The return value is the integer returned by the ioctl system
133 call. 133 call.
134 134
135 If the argument is a mutable buffer and the mutable_flag argument is not 135 If the argument is a mutable buffer and the mutable_flag argument is false,
136 passed or is false, the behavior is as if a string had been passed. This 136 the behavior is as if a string had been passed.
137 behavior will change in future releases of Python.
138 137
139 If the argument is an immutable buffer (most likely a string) then a copy 138 If the argument is an immutable buffer (most likely a string) then a copy
140 of the buffer is passed to the operating system and the return value is a 139 of the buffer is passed to the operating system and the return value is a
141 string of the same length containing whatever the operating system put in 140 string of the same length containing whatever the operating system put in
142 the buffer. The length of the arg buffer in this case is not allowed to 141 the buffer. The length of the arg buffer in this case is not allowed to
143 exceed 1024 bytes. 142 exceed 1024 bytes.
144 143
145 If the arg given is an integer or if none is specified, the result value is 144 If the arg given is an integer or if none is specified, the result value is
146 an integer corresponding to the return value of the ioctl call in the C 145 an integer corresponding to the return value of the ioctl call in the C
147 code. 146 code.
148 [clinic start generated code]*/ 147 [clinic start generated code]*/
149 148
150 static PyObject * 149 static PyObject *
151 fcntl_ioctl_impl(PyModuleDef *module, int fd, unsigned int code, PyObject *ob_ar g, int mutate_arg) 150 fcntl_ioctl_impl(PyModuleDef *module, int fd, unsigned int code, PyObject *ob_ar g, int mutate_arg)
152 /*[clinic end generated code: output=ad47738c118622bf input=a55a6ee8e494c449]*/ 151 /*[clinic end generated code: output=ad47738c118622bf input=9b4e9df45cea4448]*/
153 { 152 {
154 #define IOCTL_BUFSZ 1024 153 #define IOCTL_BUFSZ 1024
155 /* We use the unsigned non-checked 'I' format for the 'code' parameter 154 /* We use the unsigned non-checked 'I' format for the 'code' parameter
156 because the system expects it to be a 32bit bit field value 155 because the system expects it to be a 32bit bit field value
157 regardless of it being passed as an int or unsigned long on 156 regardless of it being passed as an int or unsigned long on
158 various platforms. See the termios.TIOCSWINSZ constant across 157 various platforms. See the termios.TIOCSWINSZ constant across
159 platforms for an example of this. 158 platforms for an example of this.
160 159
161 If any of the 64bit platforms ever decide to use more than 32bits 160 If any of the 64bit platforms ever decide to use more than 32bits
162 in their unsigned long ioctl codes this will break and need 161 in their unsigned long ioctl codes this will break and need
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return NULL; 262 return NULL;
264 } 263 }
265 return PyLong_FromLong((long)ret); 264 return PyLong_FromLong((long)ret);
266 #undef IOCTL_BUFSZ 265 #undef IOCTL_BUFSZ
267 } 266 }
268 267
269 /*[clinic input] 268 /*[clinic input]
270 fcntl.flock 269 fcntl.flock
271 270
272 fd: object(type='int', converter='conv_descriptor') 271 fd: object(type='int', converter='conv_descriptor')
273 code: int 272 operation as code: int
274 / 273 /
275 274
276 Perform the lock operation op on file descriptor fd. 275 Perform the lock operation `operation` on file descriptor `fd`.
277 276
278 See the Unix manual page for flock(2) for details (On some systems, this 277 See the Unix manual page for flock(2) for details (On some systems, this
279 function is emulated using fcntl()). 278 function is emulated using fcntl()).
280 [clinic start generated code]*/ 279 [clinic start generated code]*/
281 280
282 static PyObject * 281 static PyObject *
283 fcntl_flock_impl(PyModuleDef *module, int fd, int code) 282 fcntl_flock_impl(PyModuleDef *module, int fd, int code)
284 /*[clinic end generated code: output=c9035133a7dbfc96 input=b762aa9448d05e43]*/ 283 /*[clinic end generated code: output=c9035133a7dbfc96 input=b70a0a41ca22a8a0]*/
285 { 284 {
286 int ret; 285 int ret;
287 286
288 #ifdef HAVE_FLOCK 287 #ifdef HAVE_FLOCK
289 Py_BEGIN_ALLOW_THREADS 288 Py_BEGIN_ALLOW_THREADS
290 ret = flock(fd, code); 289 ret = flock(fd, code);
291 Py_END_ALLOW_THREADS 290 Py_END_ALLOW_THREADS
292 #else 291 #else
293 292
294 #ifndef LOCK_SH 293 #ifndef LOCK_SH
(...skipping 26 matching lines...) Expand all
321 return NULL; 320 return NULL;
322 } 321 }
323 Py_RETURN_NONE; 322 Py_RETURN_NONE;
324 } 323 }
325 324
326 325
327 /*[clinic input] 326 /*[clinic input]
328 fcntl.lockf 327 fcntl.lockf
329 328
330 fd: object(type='int', converter='conv_descriptor') 329 fd: object(type='int', converter='conv_descriptor')
331 code: int 330 cmd as code: int
332 lenobj: object = NULL 331 len as lenobj: object = NULL
333 startobj: object = NULL 332 start as startobj: object = NULL
Martin Panter 2015/03/20 03:24:07 Again the comment about len and start being docume
ashkop 2015/03/20 12:24:49 Done.
334 whence: int = 0 333 whence: int = 0
335 / 334 /
336 335
337 A wrapper around the fcntl() locking calls. 336 A wrapper around the fcntl() locking calls.
338 337
339 fd is the file descriptor of the file to lock or unlock, and operation is one 338 `fd` is the file descriptor of the file to lock or unlock, and operation is one
340 of the following values: 339 of the following values:
341 340
342 LOCK_UN - unlock 341 LOCK_UN - unlock
343 LOCK_SH - acquire a shared lock 342 LOCK_SH - acquire a shared lock
344 LOCK_EX - acquire an exclusive lock 343 LOCK_EX - acquire an exclusive lock
345 344
346 When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with 345 When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with
347 LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the 346 LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the
348 lock cannot be acquired, an IOError will be raised and the exception will 347 lock cannot be acquired, an IOError will be raised and the exception will
349 have an errno attribute set to EACCES or EAGAIN (depending on the operating 348 have an errno attribute set to EACCES or EAGAIN (depending on the operating
350 system -- for portability, check for either value). 349 system -- for portability, check for either value).
351 350
352 length is the number of bytes to lock, with the default meaning to lock to 351 `len` is the number of bytes to lock, with the default meaning to lock to
353 EOF. start is the byte offset, relative to whence, to that the lock 352 EOF. `start` is the byte offset, relative to `whence`, to that the lock
354 starts. whence is as with fileobj.seek(), specifically: 353 starts. `whence` is as with fileobj.seek(), specifically:
355 354
356 0 - relative to the start of the file (SEEK_SET) 355 0 - relative to the start of the file (SEEK_SET)
357 1 - relative to the current buffer position (SEEK_CUR) 356 1 - relative to the current buffer position (SEEK_CUR)
358 2 - relative to the end of the file (SEEK_END) 357 2 - relative to the end of the file (SEEK_END)
359 [clinic start generated code]*/ 358 [clinic start generated code]*/
360 359
361 static PyObject * 360 static PyObject *
362 fcntl_lockf_impl(PyModuleDef *module, int fd, int code, PyObject *lenobj, PyObje ct *startobj, int whence) 361 fcntl_lockf_impl(PyModuleDef *module, int fd, int code, PyObject *lenobj, PyObje ct *startobj, int whence)
363 /*[clinic end generated code: output=5536df2892bf3ce9 input=44856fa06db36184]*/ 362 /*[clinic end generated code: output=5536df2892bf3ce9 input=e002aa06b1478295]*/
364 { 363 {
365 int ret; 364 int ret;
366 365
367 #ifndef LOCK_SH 366 #ifndef LOCK_SH
368 #define LOCK_SH 1 /* shared lock */ 367 #define LOCK_SH 1 /* shared lock */
369 #define LOCK_EX 2 /* exclusive lock */ 368 #define LOCK_EX 2 /* exclusive lock */
370 #define LOCK_NB 4 /* don't block when locking */ 369 #define LOCK_NB 4 /* don't block when locking */
371 #define LOCK_UN 8 /* unlock */ 370 #define LOCK_UN 8 /* unlock */
372 #endif /* LOCK_SH */ 371 #endif /* LOCK_SH */
373 { 372 {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 m = PyModule_Create(&fcntlmodule); 636 m = PyModule_Create(&fcntlmodule);
638 if (m == NULL) 637 if (m == NULL)
639 return NULL; 638 return NULL;
640 639
641 /* Add some symbolic constants to the module */ 640 /* Add some symbolic constants to the module */
642 if (all_ins(m) < 0) 641 if (all_ins(m) < 0)
643 return NULL; 642 return NULL;
644 643
645 return m; 644 return m;
646 } 645 }
OLDNEW
« no previous file with comments | « Modules/clinic/fcntlmodule.c.h ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+