@@ -40,21 +40,19 @@ as constants in the fcntl module, using the same names as used in
40
40
the relevant C header files. The argument arg is optional, and
41
41
defaults to 0; it may be an int or a string. If arg is given as a string,
42
42
the return value of fcntl is a string of that length, containing the
43
- resulting value put in the arg buffer by the operating system. The length
44
- of the arg string is not allowed to exceed 1024 bytes. If the arg given
43
+ resulting value put in the arg buffer by the operating system. If the arg given
45
44
is an integer or if none is specified, the result value is an integer
46
45
corresponding to the return value of the fcntl call in the C code.
47
46
[clinic start generated code]*/
48
47
49
48
static PyObject *
50
49
fcntl_fcntl_impl (PyObject * module , int fd , int code , PyObject * arg )
51
- /*[clinic end generated code: output=888fc93b51c295bd input=7955340198e5f334 ]*/
50
+ /*[clinic end generated code: output=888fc93b51c295bd input=eed7ab9999c13350 ]*/
52
51
{
53
52
unsigned int int_arg = 0 ;
54
53
int ret ;
55
54
char * str ;
56
55
Py_ssize_t len ;
57
- char buf [1024 ];
58
56
int async_err = 0 ;
59
57
60
58
if (PySys_Audit ("fcntl.fcntl" , "iiO" , fd , code , arg ? arg : Py_None ) < 0 ) {
@@ -65,21 +63,23 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
65
63
int parse_result ;
66
64
67
65
if (PyArg_Parse (arg , "s#" , & str , & len )) {
68
- if (( size_t ) len > sizeof buf ) {
69
- PyErr_SetString ( PyExc_ValueError ,
70
- "fcntl string arg too long" );
66
+ PyObject * buf_ret = PyBytes_FromStringAndSize ( NULL , len );
67
+ if ( buf_ret == NULL ) {
68
+ PyErr_NoMemory ( );
71
69
return NULL ;
72
70
}
71
+ char * buf = PyBytes_AS_STRING (buf_ret );
73
72
memcpy (buf , str , len );
74
73
do {
75
74
Py_BEGIN_ALLOW_THREADS
76
75
ret = fcntl (fd , code , buf );
77
76
Py_END_ALLOW_THREADS
78
77
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
79
78
if (ret < 0 ) {
79
+ Py_DECREF (buf_ret );
80
80
return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
81
81
}
82
- return PyBytes_FromStringAndSize ( buf , len ) ;
82
+ return buf_ret ;
83
83
}
84
84
85
85
PyErr_Clear ();
0 commit comments