Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
daafdd5b
Commit
daafdd5b
authored
May 29, 2011
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12196: Add pipe2() to the os module.
parent
04a90b46
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
13 deletions
+71
-13
Doc/library/os.rst
Doc/library/os.rst
+13
-0
Lib/test/test_posix.py
Lib/test/test_posix.py
+25
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/posixmodule.c
Modules/posixmodule.c
+28
-0
configure
configure
+1
-9
configure.in
configure.in
+1
-3
pyconfig.h.in
pyconfig.h.in
+1
-1
No files found.
Doc/library/os.rst
View file @
daafdd5b
...
...
@@ -1019,6 +1019,19 @@ as internal buffering of data.
Availability: Unix, Windows.
.. function:: pipe2(flags=0)
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`.
Return a pair of file descriptors ``(r, w)`` usable for reading and writing,
respectively.
Availability: some flavors of Unix.
.. versionadded:: 3.3
.. function:: posix_fallocate(fd, offset, len)
Ensures that enough disk space is allocated for the file specified by *fd*
...
...
Lib/test/test_posix.py
View file @
daafdd5b
...
...
@@ -478,6 +478,31 @@ class PosixTester(unittest.TestCase):
os
.
close
(
reader
)
os
.
close
(
writer
)
@
unittest
.
skipUnless
(
hasattr
(
os
,
'pipe2'
),
"test needs os.pipe2()"
)
def
test_pipe2
(
self
):
self
.
assertRaises
(
TypeError
,
os
.
pipe2
,
'DEADBEEF'
)
self
.
assertRaises
(
TypeError
,
os
.
pipe2
,
0
,
0
)
# try calling without flag, like os.pipe()
r
,
w
=
os
.
pipe2
()
os
.
close
(
r
)
os
.
close
(
w
)
# test flags
r
,
w
=
os
.
pipe2
(
os
.
O_CLOEXEC
|
os
.
O_NONBLOCK
)
self
.
addCleanup
(
os
.
close
,
r
)
self
.
addCleanup
(
os
.
close
,
w
)
self
.
assertTrue
(
fcntl
.
fcntl
(
r
,
fcntl
.
F_GETFD
)
&
fcntl
.
FD_CLOEXEC
)
self
.
assertTrue
(
fcntl
.
fcntl
(
w
,
fcntl
.
F_GETFD
)
&
fcntl
.
FD_CLOEXEC
)
# try reading from an empty pipe: this should fail, not block
self
.
assertRaises
(
OSError
,
os
.
read
,
r
,
1
)
# try a write big enough to fill-up the pipe: this should either
# fail or perform a partial write, not block
try
:
os
.
write
(
w
,
b'x'
*
support
.
PIPE_MAX_SIZE
)
except
OSError
:
pass
def
test_utime
(
self
):
if
hasattr
(
posix
,
'utime'
):
now
=
time
.
time
()
...
...
Misc/NEWS
View file @
daafdd5b
...
...
@@ -175,6 +175,8 @@ Core and Builtins
Library
-------
- Issue #12196: Add pipe2() to the os module.
- Issue #985064: Make plistlib more resilient to faulty input plists.
Patch by Mher Movsisyan.
...
...
Modules/posixmodule.c
View file @
daafdd5b
...
...
@@ -6547,6 +6547,31 @@ posix_pipe(PyObject *self, PyObject *noargs)
}
#endif
/* HAVE_PIPE */
#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
\
"
);
static
PyObject
*
posix_pipe2
(
PyObject
*
self
,
PyObject
*
args
)
{
int
flags
=
0
;
int
fds
[
2
];
int
res
;
if
(
!
PyArg_ParseTuple
(
args
,
"|i:pipe2"
,
&
flags
))
return
NULL
;
res
=
pipe2
(
fds
,
flags
);
if
(
res
!=
0
)
return
posix_error
();
return
Py_BuildValue
(
"(ii)"
,
fds
[
0
],
fds
[
1
]);
}
#endif
/* HAVE_PIPE2 */
#ifdef HAVE_WRITEV
PyDoc_STRVAR
(
posix_writev__doc__
,
"writev(fd, buffers) -> byteswritten
\n\n
\
...
...
@@ -9441,6 +9466,9 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_PIPE
{
"pipe"
,
posix_pipe
,
METH_NOARGS
,
posix_pipe__doc__
},
#endif
#ifdef HAVE_PIPE2
{
"pipe2"
,
posix_pipe2
,
METH_VARARGS
,
posix_pipe2__doc__
},
#endif
#ifdef HAVE_MKFIFO
{
"mkfifo"
,
posix_mkfifo
,
METH_VARARGS
,
posix_mkfifo__doc__
},
#endif
...
...
configure
View file @
daafdd5b
...
...
@@ -9307,7 +9307,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd
\
if_nameindex
\
initgroups
kill
killpg lchmod lchown lockf linkat lstat lutimes mbrtowc mkdirat
mkfifo
\
mkfifoat
mknod
mknodat mktime mremap
nice
openat pathconf pause plock poll
\
mkfifoat
mknod
mknodat mktime mremap
nice
openat pathconf pause p
ipe2 p
lock poll
\
posix_fallocate posix_fadvise pread
\
pthread_init pthread_kill putenv pwrite
readlink
readlinkat readv
realpath
renameat
\
select
sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid
\
...
...
@@ -13824,14 +13824,6 @@ $as_echo "#define HAVE_BROKEN_PIPE_BUF 1" >>confdefs.h
esac
ac_fn_c_check_func
"
$LINENO
"
"pipe2"
"ac_cv_func_pipe2"
if
test
"x
$ac_cv_func_pipe2
"
=
x
""
yes
;
then
:
$as_echo
"#define HAVE_PIPE2 1"
>>
confdefs.h
fi
for
h
in
`
(
cd
$srcdir
;
echo
Python/thread_
*
.h
)
`
...
...
configure.in
View file @
daafdd5b
...
...
@@ -2531,7 +2531,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
if_nameindex \
initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mbrtowc mkdirat mkfifo \
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause p
ipe2 p
lock poll \
posix_fallocate posix_fadvise pread \
pthread_init pthread_kill putenv pwrite readlink readlinkat readv realpath renameat \
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
...
...
@@ -4244,8 +4244,6 @@ AIX*)
esac
AC_CHECK_FUNC(pipe2, AC_DEFINE(HAVE_PIPE2, 1, [Define if the OS supports pipe2()]), )
AC_SUBST(THREADHEADERS)
for h in `(cd $srcdir;echo Python/thread_*.h)`
...
...
pyconfig.h.in
View file @
daafdd5b
...
...
@@ -560,7 +560,7 @@
/* Define to 1 if you have the `pause' function. */
#undef HAVE_PAUSE
/* Define
if the OS supports pipe2()
*/
/* Define
to 1 if you have the `pipe2' function.
*/
#undef HAVE_PIPE2
/* Define to 1 if you have the `plock' function. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment