[Python-checkins] cpython: Issue #12196: Make os.pipe2() flags argument mandatory.

charles-francois.natali python-checkins at python.org
Mon Jun 6 19:50:00 CEST 2011


http://hg.python.org/cpython/rev/ba975c7c33d3
changeset:   70692:ba975c7c33d3
user:        Charles-François Natali <neologix at free.fr>
date:        Mon Jun 06 19:49:47 2011 +0200
summary:
  Issue #12196: Make os.pipe2() flags argument mandatory.

files:
  Doc/library/os.rst     |   6 +++---
  Lib/test/test_posix.py |   4 ++--
  Modules/posixmodule.c  |  19 ++++++++++---------
  3 files changed, 15 insertions(+), 14 deletions(-)


diff --git a/Doc/library/os.rst b/Doc/library/os.rst
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1019,11 +1019,11 @@
    Availability: Unix, Windows.
 
 
-.. function:: pipe2(flags=0)
+.. function:: pipe2(flags)
 
    Create a pipe with *flags* set atomically.
-   *flags* is optional and can be constructed by ORing together zero or more of
-   these values: :data:`O_NONBLOCK`, :data:`O_CLOEXEC`.
+   *flags* can be constructed by ORing together one or more of these values:
+   :data:`O_NONBLOCK`, :data:`O_CLOEXEC`.
    Return a pair of file descriptors ``(r, w)`` usable for reading and writing,
    respectively.
 
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -481,8 +481,8 @@
         self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
         self.assertRaises(TypeError, os.pipe2, 0, 0)
 
-        # try calling without flag, like os.pipe()
-        r, w = os.pipe2()
+        # try calling with flags = 0, like os.pipe()
+        r, w = os.pipe2(0)
         os.close(r)
         os.close(w)
 
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6549,20 +6549,21 @@
 
 #ifdef HAVE_PIPE2
 PyDoc_STRVAR(posix_pipe2__doc__,
-"pipe2(flags=0) -> (read_end, write_end)\n\n\
-Create a pipe with flags set atomically.\
-flags is optional and can be constructed by ORing together zero or more\n\
-of these values: O_NONBLOCK, O_CLOEXEC.\n\
+"pipe2(flags) -> (read_end, write_end)\n\n\
+Create a pipe with flags set atomically.\n\
+flags can be constructed by ORing together one or more of these values:\n\
+O_NONBLOCK, O_CLOEXEC.\n\
 ");
 
 static PyObject *
-posix_pipe2(PyObject *self, PyObject *args)
-{
-    int flags = 0;
+posix_pipe2(PyObject *self, PyObject *arg)
+{
+    int flags;
     int fds[2];
     int res;
 
-    if (!PyArg_ParseTuple(args, "|i:pipe2", &flags))
+    flags = PyLong_AsLong(arg);
+    if (flags == -1 && PyErr_Occurred())
         return NULL;
 
     res = pipe2(fds, flags);
@@ -9467,7 +9468,7 @@
     {"pipe",            posix_pipe, METH_NOARGS, posix_pipe__doc__},
 #endif
 #ifdef HAVE_PIPE2
-    {"pipe2",           posix_pipe2, METH_VARARGS, posix_pipe2__doc__},
+    {"pipe2",           posix_pipe2, METH_O, posix_pipe2__doc__},
 #endif
 #ifdef HAVE_MKFIFO
     {"mkfifo",          posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list