Skip to content

Commit 9975cc5

Browse files
bpo-41985: Add _PyLong_FileDescriptor_Converter and AC converter for "fildes". (pythonGH-22620)
1 parent b2c0a43 commit 9975cc5

File tree

10 files changed

+61
-94
lines changed

10 files changed

+61
-94
lines changed

Include/cpython/fileobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ typedef PyObject * (*Py_OpenCodeHookFunction)(PyObject *, void *);
2222
PyAPI_FUNC(PyObject *) PyFile_OpenCode(const char *utf8path);
2323
PyAPI_FUNC(PyObject *) PyFile_OpenCodeObject(PyObject *path);
2424
PyAPI_FUNC(int) PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData);
25+
26+
PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);

Modules/clinic/fcntlmodule.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/posixmodule.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/selectmodule.c.h

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/fcntlmodule.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,12 @@ module fcntl
2020
[clinic start generated code]*/
2121
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=124b58387c158179]*/
2222

23-
static int
24-
conv_descriptor(PyObject *object, int *target)
25-
{
26-
int fd = PyObject_AsFileDescriptor(object);
27-
28-
if (fd < 0)
29-
return 0;
30-
*target = fd;
31-
return 1;
32-
}
33-
34-
/* Must come after conv_descriptor definition. */
3523
#include "clinic/fcntlmodule.c.h"
3624

3725
/*[clinic input]
3826
fcntl.fcntl
3927
40-
fd: object(type='int', converter='conv_descriptor')
28+
fd: fildes
4129
cmd as code: int
4230
arg: object(c_default='NULL') = 0
4331
/
@@ -57,7 +45,7 @@ corresponding to the return value of the fcntl call in the C code.
5745

5846
static PyObject *
5947
fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
60-
/*[clinic end generated code: output=888fc93b51c295bd input=8cefbe59b29efbe2]*/
48+
/*[clinic end generated code: output=888fc93b51c295bd input=7955340198e5f334]*/
6149
{
6250
unsigned int int_arg = 0;
6351
int ret;
@@ -116,7 +104,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
116104
/*[clinic input]
117105
fcntl.ioctl
118106
119-
fd: object(type='int', converter='conv_descriptor')
107+
fd: fildes
120108
request as code: unsigned_int(bitwise=True)
121109
arg as ob_arg: object(c_default='NULL') = 0
122110
mutate_flag as mutate_arg: bool = True
@@ -155,7 +143,7 @@ code.
155143
static PyObject *
156144
fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
157145
PyObject *ob_arg, int mutate_arg)
158-
/*[clinic end generated code: output=7f7f5840c65991be input=ede70c433cccbbb2]*/
146+
/*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/
159147
{
160148
#define IOCTL_BUFSZ 1024
161149
/* We use the unsigned non-checked 'I' format for the 'code' parameter
@@ -280,7 +268,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
280268
/*[clinic input]
281269
fcntl.flock
282270
283-
fd: object(type='int', converter='conv_descriptor')
271+
fd: fildes
284272
operation as code: int
285273
/
286274
@@ -292,7 +280,7 @@ function is emulated using fcntl()).
292280

293281
static PyObject *
294282
fcntl_flock_impl(PyObject *module, int fd, int code)
295-
/*[clinic end generated code: output=84059e2b37d2fc64 input=b70a0a41ca22a8a0]*/
283+
/*[clinic end generated code: output=84059e2b37d2fc64 input=0bfc00f795953452]*/
296284
{
297285
int ret;
298286
int async_err = 0;
@@ -346,7 +334,7 @@ fcntl_flock_impl(PyObject *module, int fd, int code)
346334
/*[clinic input]
347335
fcntl.lockf
348336
349-
fd: object(type='int', converter='conv_descriptor')
337+
fd: fildes
350338
cmd as code: int
351339
len as lenobj: object(c_default='NULL') = 0
352340
start as startobj: object(c_default='NULL') = 0
@@ -380,7 +368,7 @@ starts. `whence` is as with fileobj.seek(), specifically:
380368
static PyObject *
381369
fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
382370
PyObject *startobj, int whence)
383-
/*[clinic end generated code: output=4985e7a172e7461a input=3a5dc01b04371f1a]*/
371+
/*[clinic end generated code: output=4985e7a172e7461a input=5480479fc63a04b8]*/
384372
{
385373
int ret;
386374
int async_err = 0;

Modules/posixmodule.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,18 +1634,6 @@ path_error2(path_t *path, path_t *path2)
16341634

16351635
/* POSIX generic methods */
16361636

1637-
static int
1638-
fildes_converter(PyObject *o, void *p)
1639-
{
1640-
int fd;
1641-
int *pointer = (int *)p;
1642-
fd = PyObject_AsFileDescriptor(o);
1643-
if (fd < 0)
1644-
return 0;
1645-
*pointer = fd;
1646-
return 1;
1647-
}
1648-
16491637
static PyObject *
16501638
posix_fildes_fd(int fd, int (*func)(int))
16511639
{
@@ -2642,10 +2630,6 @@ class dir_fd_converter(CConverter):
26422630
else:
26432631
self.converter = 'dir_fd_converter'
26442632
2645-
class fildes_converter(CConverter):
2646-
type = 'int'
2647-
converter = 'fildes_converter'
2648-
26492633
class uid_t_converter(CConverter):
26502634
type = "uid_t"
26512635
converter = '_Py_Uid_Converter'
@@ -2708,7 +2692,7 @@ class sysconf_confname_converter(path_confname_converter):
27082692
converter="conv_sysconf_confname"
27092693
27102694
[python start generated code]*/
2711-
/*[python end generated code: output=da39a3ee5e6b4b0d input=f1c8ae8d744f6c8b]*/
2695+
/*[python end generated code: output=da39a3ee5e6b4b0d input=3338733161aa7879]*/
27122696

27132697
/*[clinic input]
27142698

Modules/selectmodule.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ class select.kqueue "kqueue_queue_Object *" "_selectstate_global->kqueue_queue_T
8888
[clinic start generated code]*/
8989
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=41071028e0ede093]*/
9090

91-
static int
92-
fildes_converter(PyObject *o, void *p)
93-
{
94-
int fd;
95-
int *pointer = (int *)p;
96-
fd = PyObject_AsFileDescriptor(o);
97-
if (fd == -1)
98-
return 0;
99-
*pointer = fd;
100-
return 1;
101-
}
102-
103-
/*[python input]
104-
class fildes_converter(CConverter):
105-
type = 'int'
106-
converter = 'fildes_converter'
107-
[python start generated code]*/
108-
/*[python end generated code: output=da39a3ee5e6b4b0d input=ca54eb5aa476e20a]*/
109-
11091
/* list of Python objects and their file descriptor */
11192
typedef struct {
11293
PyObject *obj; /* owned reference */

0 commit comments

Comments
 (0)