From: Victor Stinner Date: Tue, 30 Sep 2014 10:35:58 +0000 (+0200) Subject: (Merge 3.4) Issue #22396: On 32-bit AIX platform, don't expose X-Git-Tag: v3.5.0a1~818 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec39e26881e2d8811ffbe868d4f0c640ecb4f68d;p=python (Merge 3.4) Issue #22396: On 32-bit AIX platform, don't expose os.posix_fadvise() nor os.posix_fallocate() because their prototypes in system headers are wrong. --- ec39e26881e2d8811ffbe868d4f0c640ecb4f68d diff --cc Modules/posixmodule.c index 473fefaa34,8bea76eccc..aa2d63ac4a --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@@ -12694,164 -8769,94 +12694,173 @@@ os_truncate_impl(PyModuleDef *module, p Py_BEGIN_ALLOW_THREADS #ifdef HAVE_FTRUNCATE - if (path.fd != -1) - res = ftruncate(path.fd, length); + if (path->fd != -1) + result = ftruncate(path->fd, length); else #endif - res = truncate(path.narrow, length); + result = truncate(path->narrow, length); Py_END_ALLOW_THREADS - if (res < 0) - result = path_error(&path); - else { - Py_INCREF(Py_None); - result = Py_None; - } - path_cleanup(&path); - return result; + if (result < 0) + return path_error(path); + + Py_RETURN_NONE; } -#endif +#endif /* HAVE_TRUNCATE */ + - #ifdef HAVE_POSIX_FALLOCATE + /* Issue #22396: On 32-bit AIX platform, the prototypes of os.posix_fadvise() + and os.posix_fallocate() in system headers are wrong if _LARGE_FILES is + defined, which is the case in Python on AIX. AIX bug report: + http://www-01.ibm.com/support/docview.wss?uid=isg1IV56170 */ + #if defined(_AIX) && defined(_LARGE_FILES) && !defined(__64BIT__) + # define POSIX_FADVISE_AIX_BUG + #endif + ++ + #if defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) -PyDoc_STRVAR(posix_posix_fallocate__doc__, -"posix_fallocate(fd, offset, len)\n\n\ -Ensures that enough disk space is allocated for the file specified by fd\n\ -starting from offset and continuing for len bytes."); +/*[clinic input] +os.posix_fallocate + + fd: int + offset: Py_off_t + length: Py_off_t + / + +Ensure a file has allocated at least a particular number of bytes on disk. + +Ensure that the file specified by fd encompasses a range of bytes +starting at offset bytes from the beginning and continuing for length bytes. +[clinic start generated code]*/ + +PyDoc_STRVAR(os_posix_fallocate__doc__, +"posix_fallocate($module, fd, offset, length, /)\n" +"--\n" +"\n" +"Ensure a file has allocated at least a particular number of bytes on disk.\n" +"\n" +"Ensure that the file specified by fd encompasses a range of bytes\n" +"starting at offset bytes from the beginning and continuing for length bytes."); + +#define OS_POSIX_FALLOCATE_METHODDEF \ + {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__}, + +static PyObject * +os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length); static PyObject * -posix_posix_fallocate(PyObject *self, PyObject *args) +os_posix_fallocate(PyModuleDef *module, PyObject *args) { - off_t len, offset; - int res, fd; + PyObject *return_value = NULL; + int fd; + Py_off_t offset; + Py_off_t length; - if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate", - &fd, _parse_off_t, &offset, _parse_off_t, &len)) - return NULL; + if (!PyArg_ParseTuple(args, + "iO&O&:posix_fallocate", + &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) + goto exit; + return_value = os_posix_fallocate_impl(module, fd, offset, length); + +exit: + return return_value; +} + +static PyObject * +os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length) +/*[clinic end generated code: output=0cd702d2065c79db input=d7a2ef0ab2ca52fb]*/ +{ + int result; Py_BEGIN_ALLOW_THREADS - res = posix_fallocate(fd, offset, len); + result = posix_fallocate(fd, offset, length); Py_END_ALLOW_THREADS - if (res != 0) { - errno = res; + if (result != 0) { + errno = result; return posix_error(); } Py_RETURN_NONE; } - #endif /* HAVE_POSIX_FALLOCATE */ -#endif ++#endif /* HAVE_POSIX_FALLOCATE) && !POSIX_FADVISE_AIX_BUG */ + - #ifdef HAVE_POSIX_FADVISE + #if defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG) -PyDoc_STRVAR(posix_posix_fadvise__doc__, -"posix_fadvise(fd, offset, len, advice)\n\n\ -Announces an intention to access data in a specific pattern thus allowing\n\ -the kernel to make optimizations.\n\ -The advice applies to the region of the file specified by fd starting at\n\ -offset and continuing for len bytes.\n\ -advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n\ -POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or\n\ -POSIX_FADV_DONTNEED."); +/*[clinic input] +os.posix_fadvise + + fd: int + offset: Py_off_t + length: Py_off_t + advice: int + / + +Announce an intention to access data in a specific pattern. + +Announce an intention to access data in a specific pattern, thus allowing +the kernel to make optimizations. +The advice applies to the region of the file specified by fd starting at +offset and continuing for length bytes. +advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, +POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or +POSIX_FADV_DONTNEED. +[clinic start generated code]*/ + +PyDoc_STRVAR(os_posix_fadvise__doc__, +"posix_fadvise($module, fd, offset, length, advice, /)\n" +"--\n" +"\n" +"Announce an intention to access data in a specific pattern.\n" +"\n" +"Announce an intention to access data in a specific pattern, thus allowing\n" +"the kernel to make optimizations.\n" +"The advice applies to the region of the file specified by fd starting at\n" +"offset and continuing for length bytes.\n" +"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" +"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" +"POSIX_FADV_DONTNEED."); + +#define OS_POSIX_FADVISE_METHODDEF \ + {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__}, static PyObject * -posix_posix_fadvise(PyObject *self, PyObject *args) +os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice); + +static PyObject * +os_posix_fadvise(PyModuleDef *module, PyObject *args) { - off_t len, offset; - int res, fd, advice; + PyObject *return_value = NULL; + int fd; + Py_off_t offset; + Py_off_t length; + int advice; - if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise", - &fd, _parse_off_t, &offset, _parse_off_t, &len, &advice)) - return NULL; + if (!PyArg_ParseTuple(args, + "iO&O&i:posix_fadvise", + &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) + goto exit; + return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); + +exit: + return return_value; +} + +static PyObject * +os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice) +/*[clinic end generated code: output=dad93f32c04dd4f7 input=0fbe554edc2f04b5]*/ +{ + int result; Py_BEGIN_ALLOW_THREADS - res = posix_fadvise(fd, offset, len, advice); + result = posix_fadvise(fd, offset, length, advice); Py_END_ALLOW_THREADS - if (res != 0) { - errno = res; + if (result != 0) { + errno = result; return posix_error(); } Py_RETURN_NONE; } - #endif /* HAVE_POSIX_FADVISE */ -#endif ++#endif /* HAVE_POSIX_FADVISE && !POSIX_FADVISE_AIX_BUG */ #ifdef HAVE_PUTENV -PyDoc_STRVAR(posix_putenv__doc__, -"putenv(key, value)\n\n\ -Change or add an environment variable."); /* Save putenv() parameters as values here, so we can collect them when they * get re-set with another call for the same key. */