Skip to content
Merged
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
7 changes: 7 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,13 @@ features:
Compose a raw device number from the major and minor device numbers.


.. data:: NODEV

Non-existent device.

.. versionadded:: next


.. function:: pathconf(path, name)

Return system configuration information relevant to a named file. *name*
Expand Down
22 changes: 20 additions & 2 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,30 @@ def test_makedev(self):
self.assertRaises((ValueError, OverflowError), posix.makedev, x, minor)
self.assertRaises((ValueError, OverflowError), posix.makedev, major, x)

if sys.platform == 'linux' and not support.linked_to_musl():
NODEV = -1
# The following tests are needed to test functions accepting or
# returning the special value NODEV (if it is defined). major(), minor()
# and makefile() are the only easily reproducible examples, but that
# behavior is platform specific -- on some platforms their code has
# a special case for NODEV, on others this is just an implementation
# artifact.
if (hasattr(posix, 'NODEV') and
sys.platform.startswith(('linux', 'macos', 'freebsd', 'dragonfly',
'sunos'))):
NODEV = posix.NODEV
Copy link
Member

Choose a reason for hiding this comment

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

Is this code path still skipped on Alpine Linux (musl)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is skipped if NODEV is not defined in musl. But if it is defined, the following tests will fail, so we will need to add an additional condition.

self.assertEqual(posix.major(NODEV), NODEV)
self.assertEqual(posix.minor(NODEV), NODEV)
self.assertEqual(posix.makedev(NODEV, NODEV), NODEV)

def test_nodev(self):
# NODEV is not a part of Posix, but is defined on many systems.
if (not hasattr(posix, 'NODEV')
and (not sys.platform.startswith(('linux', 'macos', 'freebsd',
'dragonfly', 'netbsd', 'openbsd',
'sunos'))
or support.linked_to_musl())):
self.skipTest('not defined on this platform')
self.assertHasAttr(posix, 'NODEV')

def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""
def check_stat(uid, gid):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :const:`os.NODEV`.
4 changes: 4 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17861,6 +17861,10 @@ all_ins(PyObject *m)
#endif
#endif /* HAVE_EVENTFD && EFD_CLOEXEC */

#ifdef NODEV
if (PyModule_Add(m, "NODEV", _PyLong_FromDev(NODEV))) return -1;
#endif

#if defined(__APPLE__)
if (PyModule_AddIntConstant(m, "_COPYFILE_DATA", COPYFILE_DATA)) return -1;
if (PyModule_AddIntConstant(m, "_COPYFILE_STAT", COPYFILE_STAT)) return -1;
Expand Down
Loading