Skip to content

Commit 3cafd46

Browse files
committed
gh-103510: Support os.mkfifo on Windows
Make os.mkfifo return an open fd on Windows and the original path object on Unix. The user would then pass the return value into open, which accepts both path and fd as file.
1 parent 7d27561 commit 3cafd46

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Modules/clinic/posixmodule.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12523,7 +12523,7 @@ os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
1252312523
}
1252412524
#endif /* HAVE_SPLICE*/
1252512525

12526-
#ifdef HAVE_MKFIFO
12526+
#if defined(HAVE_MKFIFO) || defined(MS_WINDOWS)
1252712527
/*[clinic input]
1252812528
os.mkfifo
1252912529
@@ -12544,6 +12544,21 @@ static PyObject *
1254412544
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
1254512545
/*[clinic end generated code: output=ce41cfad0e68c940 input=73032e98a36e0e19]*/
1254612546
{
12547+
#ifdef MS_WINDOWS
12548+
HANDLE h;
12549+
int fd;
12550+
Py_BEGIN_ALLOW_THREADS
12551+
h = CreateNamedPipeW(path->wide,
12552+
PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
12553+
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
12554+
1, 1024, 1024, 0, NULL
12555+
);
12556+
Py_END_ALLOW_THREADS
12557+
if (INVALID_HANDLE_VALUE == h)
12558+
return win32_error_object("CreateNamedPipeW", path->object);
12559+
fd = _Py_open_osfhandle(h, _O_RDWR);
12560+
return PyLong_FromLong(fd);
12561+
#else
1254712562
int result;
1254812563
int async_err = 0;
1254912564
#ifdef HAVE_MKFIFOAT
@@ -12578,7 +12593,8 @@ os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
1257812593
if (result != 0)
1257912594
return (!async_err) ? posix_error() : NULL;
1258012595

12581-
Py_RETURN_NONE;
12596+
return Py_NewRef(path->object);
12597+
#endif
1258212598
}
1258312599
#endif /* HAVE_MKFIFO */
1258412600

0 commit comments

Comments
 (0)