8000 Убрать fcntl_fcntl_impl оставив fcntl_ioctl_impl · arhadthedev/cpython@d5d5746 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5d5746

Browse files
committed
Убрать fcntl_fcntl_impl оставив fcntl_ioctl_impl
Пулл-реквест pythongh-95429 внёс по сути те же изменения, так что фокусируемся на отсутствующем там fcntl_ioctl_impl.
1 parent 8fbddd5 commit d5d5746

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Modules/fcntlmodule.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ as constants in the fcntl module, using the same names as used in
4040
the relevant C header files. The argument arg is optional, and
4141
defaults to 0; it may be an int or a string. If arg is given as a string,
4242
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. If the arg
44-
given is an integer or if none is specified, the result value is an integer
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
45+
is an integer or if none is specified, the result value is an integer
4546
corresponding to the return value of the fcntl call in the C code.
4647
[clinic start generated code]*/
4748

@@ -53,6 +54,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
5354
int ret;
5455
char *str;
5556
Py_ssize_t len;
57+
//char buf[1024];
5658
int async_err = 0;
5759

5860
if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) {
@@ -63,11 +65,22 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
6365
int parse_result;
6466

6567
if (PyArg_Parse(arg, "s#", &str, &len)) {
66-
PyObject *o = PyBytes_FromStringAndSize(NULL, len);
68+
/*if ((size_t)len > sizeof buf) {
69+
PyErr_SetString(PyExc_ValueError,
70+
"fcntl string arg too long");
71+
return NULL;
72+
}*/
73+
char* buf = malloc((size_t)len);
74+
PyObject* buf_ret;
75+
if(buf == NULL) {
76+
PyErr_NoMemory();
77+
return NULL;
78+
}
79+
/*PyObject *o = PyBytes_FromStringAndSize(NULL, len);
6780
if (o == NULL) {
6881
return NULL;
6982
}
70-
char *buf = PyBytes_AS_STRING(o);
83+
char *buf = PyBytes_AS_STRING(o);*/
7184

7285
memcpy(buf, str, len);
7386
do {
@@ -76,9 +89,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
7689
Py_END_ALLOW_THREADS
7790
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
7891
if (ret < 0) {
92+
free(buf);
7993
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
8094
}
81-
return PyBytes_FromStringAndSize(buf, len);
95+
//return PyBytes_FromStringAndSize(buf, len);
96+
buf_ret = PyBytes_FromStringAndSize(buf, len);
97+
free(buf);
98+
return(buf_ret);
8299
}
83100

84101
PyErr_Clear();

0 commit comments

Comments
 (0)
0