PyAPI_FUNC(PyObject *) PyFile_OpenCode(const char *utf8path);
PyAPI_FUNC(PyObject *) PyFile_OpenCodeObject(PyObject *path);
PyAPI_FUNC(int) PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData);
+
+PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);
if (!_PyArg_CheckPositional("fcntl", nargs, 2, 3)) {
goto exit;
}
- if (!conv_descriptor(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
code = _PyLong_AsInt(args[1]);
if (!_PyArg_CheckPositional("ioctl", nargs, 2, 4)) {
goto exit;
}
- if (!conv_descriptor(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
code = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
if (!_PyArg_CheckPositional("flock", nargs, 2, 2)) {
goto exit;
}
- if (!conv_descriptor(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
code = _PyLong_AsInt(args[1]);
if (!_PyArg_CheckPositional("lockf", nargs, 2, 5)) {
goto exit;
}
- if (!conv_descriptor(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
code = _PyLong_AsInt(args[1]);
exit:
return return_value;
}
-/*[clinic end generated code: output=91c2295402509595 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8ea34bd0f7cf25ec input=a9049054013a1b77]*/
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
return_value = os_fchdir_impl(module, fd);
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
return_value = os_fsync_impl(module, fd);
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
return_value = os_fdatasync_impl(module, fd);
if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (!conv_path_confname(args[1], &name)) {
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=a0fbdea47249ee0c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=936f33448cd66ccb input=a9049054013a1b77]*/
if (!_PyArg_CheckPositional("register", nargs, 1, 2)) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (nargs < 2) {
if (!_PyArg_CheckPositional("modify", nargs, 2, 2)) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) {
PyObject *return_value = NULL;
int fd;
- if (!fildes_converter(arg, &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(arg, &fd)) {
goto exit;
}
return_value = select_poll_unregister_impl(self, fd);
if (!_PyArg_CheckPositional("register", nargs, 1, 2)) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (nargs < 2) {
if (!_PyArg_CheckPositional("modify", nargs, 1, 2)) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (nargs < 2) {
PyObject *return_value = NULL;
int fd;
- if (!fildes_converter(arg, &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(arg, &fd)) {
goto exit;
}
return_value = select_devpoll_unregister_impl(self, fd);
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
if (!noptargs) {
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
eventmask = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
if (!args) {
goto exit;
}
- if (!fildes_converter(args[0], &fd)) {
+ if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
goto exit;
}
return_value = select_epoll_unregister_impl(self, fd);
#ifndef SELECT_KQUEUE_CONTROL_METHODDEF
#define SELECT_KQUEUE_CONTROL_METHODDEF
#endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
-/*[clinic end generated code: output=7144233c42e18279 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=162f4f4efa850416 input=a9049054013a1b77]*/
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=124b58387c158179]*/
-static int
-conv_descriptor(PyObject *object, int *target)
-{
- int fd = PyObject_AsFileDescriptor(object);
-
- if (fd < 0)
- return 0;
- *target = fd;
- return 1;
-}
-
-/* Must come after conv_descriptor definition. */
#include "clinic/fcntlmodule.c.h"
/*[clinic input]
fcntl.fcntl
- fd: object(type='int', converter='conv_descriptor')
+ fd: fildes
cmd as code: int
arg: object(c_default='NULL') = 0
/
static PyObject *
fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
-/*[clinic end generated code: output=888fc93b51c295bd input=8cefbe59b29efbe2]*/
+/*[clinic end generated code: output=888fc93b51c295bd input=7955340198e5f334]*/
{
unsigned int int_arg = 0;
int ret;
/*[clinic input]
fcntl.ioctl
- fd: object(type='int', converter='conv_descriptor')
+ fd: fildes
request as code: unsigned_int(bitwise=True)
arg as ob_arg: object(c_default='NULL') = 0
mutate_flag as mutate_arg: bool = True
static PyObject *
fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
PyObject *ob_arg, int mutate_arg)
-/*[clinic end generated code: output=7f7f5840c65991be input=ede70c433cccbbb2]*/
+/*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/
{
#define IOCTL_BUFSZ 1024
/* We use the unsigned non-checked 'I' format for the 'code' parameter
/*[clinic input]
fcntl.flock
- fd: object(type='int', converter='conv_descriptor')
+ fd: fildes
operation as code: int
/
static PyObject *
fcntl_flock_impl(PyObject *module, int fd, int code)
-/*[clinic end generated code: output=84059e2b37d2fc64 input=b70a0a41ca22a8a0]*/
+/*[clinic end generated code: output=84059e2b37d2fc64 input=0bfc00f795953452]*/
{
int ret;
int async_err = 0;
/*[clinic input]
fcntl.lockf
- fd: object(type='int', converter='conv_descriptor')
+ fd: fildes
cmd as code: int
len as lenobj: object(c_default='NULL') = 0
start as startobj: object(c_default='NULL') = 0
static PyObject *
fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
PyObject *startobj, int whence)
-/*[clinic end generated code: output=4985e7a172e7461a input=3a5dc01b04371f1a]*/
+/*[clinic end generated code: output=4985e7a172e7461a input=5480479fc63a04b8]*/
{
int ret;
int async_err = 0;
/* POSIX generic methods */
-static int
-fildes_converter(PyObject *o, void *p)
-{
- int fd;
- int *pointer = (int *)p;
- fd = PyObject_AsFileDescriptor(o);
- if (fd < 0)
- return 0;
- *pointer = fd;
- return 1;
-}
-
static PyObject *
posix_fildes_fd(int fd, int (*func)(int))
{
else:
self.converter = 'dir_fd_converter'
-class fildes_converter(CConverter):
- type = 'int'
- converter = 'fildes_converter'
-
class uid_t_converter(CConverter):
type = "uid_t"
converter = '_Py_Uid_Converter'
converter="conv_sysconf_confname"
[python start generated code]*/
-/*[python end generated code: output=da39a3ee5e6b4b0d input=f1c8ae8d744f6c8b]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=3338733161aa7879]*/
/*[clinic input]
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=41071028e0ede093]*/
-static int
-fildes_converter(PyObject *o, void *p)
-{
- int fd;
- int *pointer = (int *)p;
- fd = PyObject_AsFileDescriptor(o);
- if (fd == -1)
- return 0;
- *pointer = fd;
- return 1;
-}
-
-/*[python input]
-class fildes_converter(CConverter):
- type = 'int'
- converter = 'fildes_converter'
-[python start generated code]*/
-/*[python end generated code: output=da39a3ee5e6b4b0d input=ca54eb5aa476e20a]*/
-
/* list of Python objects and their file descriptor */
typedef struct {
PyObject *obj; /* owned reference */
return (termiosmodulestate *)state;
}
-static int fdconv(PyObject* obj, void* p)
-{
- int fd;
-
- fd = PyObject_AsFileDescriptor(obj);
- if (fd >= 0) {
- *(int*)p = fd;
- return 1;
- }
- return 0;
-}
-
static struct PyModuleDef termiosmodule;
PyDoc_STRVAR(termios_tcgetattr__doc__,
{
int fd;
if (!PyArg_ParseTuple(args, "O&:tcgetattr",
- fdconv, (void*)&fd)) {
+ _PyLong_FileDescriptor_Converter, (void*)&fd)) {
return NULL;
}
int fd, when;
PyObject *term;
if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
- fdconv, &fd, &when, &term)) {
+ _PyLong_FileDescriptor_Converter, &fd, &when, &term)) {
return NULL;
}
{
int fd, duration;
if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
- fdconv, &fd, &duration)) {
+ _PyLong_FileDescriptor_Converter, &fd, &duration)) {
return NULL;
}
{
int fd;
if (!PyArg_ParseTuple(args, "O&:tcdrain",
- fdconv, &fd)) {
+ _PyLong_FileDescriptor_Converter, &fd)) {
return NULL;
}
{
int fd, queue;
if (!PyArg_ParseTuple(args, "O&i:tcflush",
- fdconv, &fd, &queue)) {
+ _PyLong_FileDescriptor_Converter, &fd, &queue)) {
return NULL;
}
{
int fd, action;
if (!PyArg_ParseTuple(args, "O&i:tcflow",
- fdconv, &fd, &action)) {
+ _PyLong_FileDescriptor_Converter, &fd, &action)) {
return NULL;
}
return fd;
}
+int
+_PyLong_FileDescriptor_Converter(PyObject *o, void *ptr)
+{
+ int fd = PyObject_AsFileDescriptor(o);
+ if (fd == -1) {
+ return 0;
+ }
+ *(int *)ptr = fd;
+ return 1;
+}
+
/*
** Py_UniversalNewlineFgets is an fgets variation that understands
** all of \r, \n and \r\n conventions.
return super().parse_arg(argname, displayname)
+class fildes_converter(CConverter):
+ type = 'int'
+ converter = '_PyLong_FileDescriptor_Converter'
+
+ def _parse_arg(self, argname, displayname):
+ return """
+ {paramname} = PyObject_AsFileDescriptor({argname});
+ if ({paramname} == -1) {{{{
+ goto exit;
+ }}}}
+ """.format(argname=argname, paramname=self.name)
+
+
class float_converter(CConverter):
type = 'float'
default_type = float