Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-103510: Support os.mkfifo on Windows #129420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -12523,7 +12523,7 @@ os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
}
#endif /* HAVE_SPLICE*/

#ifdef HAVE_MKFIFO
#if defined(HAVE_MKFIFO) || defined(MS_WINDOWS)
/*[clinic input]
os.mkfifo

Expand All @@ -12544,6 +12544,21 @@ static PyObject *
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
/*[clinic end generated code: output=ce41cfad0e68c940 input=73032e98a36e0e19]*/
{
#ifdef MS_WINDOWS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should raise an error if dir_fd is used.

You should document that the mode is ignored on Windows.

HANDLE h;
int fd;
Py_BEGIN_ALLOW_THREADS
h = CreateNamedPipeW(path->wide,
PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1, 1024, 1024, 0, NULL
);
Py_END_ALLOW_THREADS
if (INVALID_HANDLE_VALUE == h)
return win32_error_object("CreateNamedPipeW", path->object);
fd = _Py_open_osfhandle(h, _O_RDWR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_Py_open_osfhandle() can return -1: see the Windows implementation of os.pipe().

return PyLong_FromLong(fd);
#else
int result;
int async_err = 0;
#ifdef HAVE_MKFIFOAT
Expand Down Expand Up @@ -12578,7 +12593,8 @@ os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
if (result != 0)
return (!async_err) ? posix_error() : NULL;

Py_RETURN_NONE;
return Py_NewRef(path->object);
#endif
}
#endif /* HAVE_MKFIFO */

Expand Down
Loading