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

Delta Between Two Patch Sets: Modules/fcntlmodule.c

Issue 23001: Accept mutable bytes-like objects
Left Patch Set: Created 5 years ago
Right Patch Set: Created 4 years, 8 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 unsigned int int_arg = 0; 63 unsigned int int_arg = 0;
64 int ret; 64 int ret;
65 Py_buffer view; 65 Py_buffer view;
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
72 if (PyArg_Parse(arg, "s*", &view)) { 72 if (PyArg_Parse(arg, "s*", &view)) {
73 if ((size_t)view.len > sizeof buf) { 73 if ((size_t)view.len > sizeof buf) {
Martin Panter 2015/03/20 02:41:08 Probably should release the buffer in this case
storchaka 2015/03/20 07:47:34 Done.
74 PyErr_SetString(PyExc_ValueError, 74 PyErr_SetString(PyExc_ValueError,
75 "fcntl string arg too long"); 75 "fcntl string arg too long");
76 return NULL; 76 return NULL;
77 } 77 }
78 len = view.len; 78 len = view.len;
79 memcpy(buf, view.buf, len); 79 memcpy(buf, view.buf, len);
Martin Panter 2015/03/20 02:41:08 An argument could be made for passing the buffer d
storchaka 2015/03/20 07:47:34 Agree with you, this is not easy issue. I'll left
80 PyBuffer_Release(&view); 80 PyBuffer_Release(&view);
81 Py_BEGIN_ALLOW_THREADS 81 Py_BEGIN_ALLOW_THREADS
82 ret = fcntl(fd, code, buf); 82 ret = fcntl(fd, code, buf);
83 Py_END_ALLOW_THREADS 83 Py_END_ALLOW_THREADS
84 if (ret < 0) { 84 if (ret < 0) {
85 PyErr_SetFromErrno(PyExc_IOError); 85 PyErr_SetFromErrno(PyExc_IOError);
86 return NULL; 86 return NULL;
87 } 87 }
88 return PyBytes_FromStringAndSize(buf, len); 88 return PyBytes_FromStringAndSize(buf, len);
89 } 89 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 If the arg given is an integer or if none is specified, the result value is 147 If the arg given is an integer or if none is specified, the result value is
148 an integer corresponding to the return value of the ioctl call in the C 148 an integer corresponding to the return value of the ioctl call in the C
149 code. 149 code.
150 [clinic start generated code]*/ 150 [clinic start generated code]*/
151 151
152 static PyObject * 152 static PyObject *
153 fcntl_ioctl_impl(PyModuleDef *module, int fd, unsigned int code, PyObject *ob_ar g, int mutate_arg) 153 fcntl_ioctl_impl(PyModuleDef *module, int fd, unsigned int code, PyObject *ob_ar g, int mutate_arg)
154 /*[clinic end generated code: output=ad47738c118622bf input=a55a6ee8e494c449]*/ 154 /*[clinic end generated code: output=ad47738c118622bf input=a55a6ee8e494c449]*/
155 { 155 {
156 #define IOCTL_BUFSZ 1024 156 #define IOCTL_BUFSZ 1024
157 /* We use the unsigned non-checked 'I' 157 /* We use the unsigned non-checked 'I' format for the 'code' parameter
158 format for the 'code' parameter because Python turns 0x8000000 158 because the system expects it to be a 32bit bit field value
159 into either a large positive number (PyLong or PyInt on 64-bit
160 platforms) or a negative number on others (32-bit PyInt)
161 whereas the system expects it to be a 32bit bit field value
162 regardless of it being passed as an int or unsigned long on 159 regardless of it being passed as an int or unsigned long on
163 various platforms. See the termios.TIOCSWINSZ constant across 160 various platforms. See the termios.TIOCSWINSZ constant across
164 platforms for an example of this. 161 platforms for an example of this.
165 162
166 If any of the 64bit platforms ever decide to use more than 32bits 163 If any of the 64bit platforms ever decide to use more than 32bits
167 in their unsigned long ioctl codes this will break and need 164 in their unsigned long ioctl codes this will break and need
168 special casing based on the platform being built on. 165 special casing based on the platform being built on.
169 */ 166 */
170 int arg = 0; 167 int arg = 0;
171 int ret; 168 int ret;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 m = PyModule_Create(&fcntlmodule); 639 m = PyModule_Create(&fcntlmodule);
643 if (m == NULL) 640 if (m == NULL)
644 return NULL; 641 return NULL;
645 642
646 /* Add some symbolic constants to the module */ 643 /* Add some symbolic constants to the module */
647 if (all_ins(m) < 0) 644 if (all_ins(m) < 0)
648 return NULL; 645 return NULL;
649 646
650 return m; 647 return m;
651 } 648 }
LEFTRIGHT

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