Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 62989) +++ Modules/posixmodule.c (working copy) @@ -1740,9 +1740,13 @@ static PyObject * posix_fchmod(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, mode, res; - if (!PyArg_ParseTuple(args, "ii:fchmod", &fd, &mode)) + if (!PyArg_ParseTuple(args, "Oi:fchmod", &fdobj, &mode)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS res = fchmod(fd, mode); Py_END_ALLOW_THREADS @@ -1907,10 +1911,14 @@ static PyObject * posix_fchown(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, uid, gid; int res; - if (!PyArg_ParseTuple(args, "iii:chown", &fd, &uid, &gid)) + if (!PyArg_ParseTuple(args, "Oii:chown", &fdobj, &uid, &gid)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS res = fchown(fd, (uid_t) uid, (gid_t) gid); Py_END_ALLOW_THREADS @@ -6087,9 +6095,13 @@ static PyObject * posix_tcsetpgrp(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, pgid; - if (!PyArg_ParseTuple(args, "ii:tcsetpgrp", &fd, &pgid)) + if (!PyArg_ParseTuple(args, "ii:tcsetpgrp", &fdobj, &pgid)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ if (tcsetpgrp(fd, pgid) < 0) return posix_error(); Py_INCREF(Py_None); @@ -6152,9 +6164,13 @@ static PyObject * posix_close(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, res; - if (!PyArg_ParseTuple(args, "i:close", &fd)) + if (!PyArg_ParseTuple(args, "O:close", &fdobj)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS res = close(fd); Py_END_ALLOW_THREADS @@ -6190,9 +6206,13 @@ static PyObject * posix_dup(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd; - if (!PyArg_ParseTuple(args, "i:dup", &fd)) + if (!PyArg_ParseTuple(args, "O:dup", &fdobj)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS fd = dup(fd); Py_END_ALLOW_THREADS @@ -6235,9 +6255,13 @@ #else off_t pos, res; #endif + PyObject *fdobj; PyObject *posobj; - if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how)) + if (!PyArg_ParseTuple(args, "OOi:lseek", &fdobj, &posobj, &how)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ #ifdef SEEK_SET /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ switch (how) { @@ -6281,10 +6305,14 @@ static PyObject * posix_read(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, size, n; PyObject *buffer; - if (!PyArg_ParseTuple(args, "ii:read", &fd, &size)) + if (!PyArg_ParseTuple(args, "Oi:read", &fdobj, &size)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ if (size < 0) { errno = EINVAL; return posix_error(); @@ -6312,12 +6340,16 @@ static PyObject * posix_write(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd; Py_ssize_t size; char *buffer; - if (!PyArg_ParseTuple(args, "is#:write", &fd, &buffer, &size)) + if (!PyArg_ParseTuple(args, "Os#:write", &fdobj, &buffer, &size)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS size = write(fd, buffer, (size_t)size); Py_END_ALLOW_THREADS @@ -6334,11 +6366,15 @@ static PyObject * posix_fstat(PyObject *self, PyObject *args) { - int fd; + PyObject *fdobj; STRUCT_STAT st; int res; - if (!PyArg_ParseTuple(args, "i:fstat", &fd)) + int fd; + if (!PyArg_ParseTuple(args, "O:fstat", &fdobj)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ #ifdef __VMS /* on OpenVMS we must ensure that all bytes are written to the file */ fsync(fd); @@ -6578,13 +6614,17 @@ static PyObject * posix_ftruncate(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd; off_t length; int res; PyObject *lenobj; - if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj)) + if (!PyArg_ParseTuple(args, "OO:ftruncate", &fdobj, &lenobj)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ #if !defined(HAVE_LARGEFILE_SUPPORT) length = PyInt_AsLong(lenobj); @@ -6938,11 +6978,15 @@ static PyObject * posix_fstatvfs(PyObject *self, PyObject *args) { + PyObject *fdobj; int fd, res; struct statvfs st; - if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd)) + if (!PyArg_ParseTuple(args, "O:fstatvfs", &fdobj)) return NULL; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ Py_BEGIN_ALLOW_THREADS res = fstatvfs(fd, &st); Py_END_ALLOW_THREADS @@ -7197,10 +7241,15 @@ posix_fpathconf(PyObject *self, PyObject *args) { PyObject *result = NULL; + PyObject *fdobj; int name, fd; - if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd, + if (PyArg_ParseTuple(args, "OO&:fpathconf", &fdobj, conv_path_confname, &name)) { + + fd = PyObject_AsFileDescriptor(fdobj); + if (fd == -1) + return NULL; /* Rely on AsFileDescriptor's error handling */ long limit; errno = 0;