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

Side by Side Diff: Modules/fcntlmodule.c

Issue 23001: Accept mutable bytes-like objects
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:
View unified diff | Download patch
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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=4850c13a41e86930]*/
62 { 62 {
63 unsigned int int_arg = 0; 63 unsigned int int_arg = 0;
64 int ret; 64 int ret;
65 char *str; 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#", &str, &len)) { 72 if (PyArg_Parse(arg, "s*", &view)) {
73 if ((size_t)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 memcpy(buf, str, len); 78 len = view.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);
79 Py_BEGIN_ALLOW_THREADS 81 Py_BEGIN_ALLOW_THREADS
80 ret = fcntl(fd, code, buf); 82 ret = fcntl(fd, code, buf);
81 Py_END_ALLOW_THREADS 83 Py_END_ALLOW_THREADS
82 if (ret < 0) { 84 if (ret < 0) {
83 PyErr_SetFromErrno(PyExc_IOError); 85 PyErr_SetFromErrno(PyExc_IOError);
84 return NULL; 86 return NULL;
85 } 87 }
86 return PyBytes_FromStringAndSize(buf, len); 88 return PyBytes_FromStringAndSize(buf, len);
87 } 89 }
88 90
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 m = PyModule_Create(&fcntlmodule); 639 m = PyModule_Create(&fcntlmodule);
638 if (m == NULL) 640 if (m == NULL)
639 return NULL; 641 return NULL;
640 642
641 /* Add some symbolic constants to the module */ 643 /* Add some symbolic constants to the module */
642 if (all_ins(m) < 0) 644 if (all_ins(m) < 0)
643 return NULL; 645 return NULL;
644 646
645 return m; 647 return m;
646 } 648 }
OLDNEW
« Doc/library/socket.rst ('K') | « Modules/_codecsmodule.c ('k') | Modules/mmapmodule.c » ('j') | no next file with comments »

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