mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-26836: Add os.memfd_create() (#13567)
* bpo-26836: Add os.memfd_create() * Use the glibc wrapper for memfd_create() Co-Authored-By: Christian Heimes <christian@python.org> * Fix deletions caused by autoreconf. * Use MFD_CLOEXEC as the default value for *flags*. * Add memset_s to configure.ac. * Revert memset_s changes. * Apply the requested changes. * Tweak the docs.
This commit is contained in:
parent
0c2f930564
commit
43fdbd2729
10 changed files with 259 additions and 12 deletions
|
@ -3122,6 +3122,22 @@ class TermsizeTests(unittest.TestCase):
|
|||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'memfd_create'), 'requires os.memfd_create')
|
||||
class MemfdCreateTests(unittest.TestCase):
|
||||
def test_memfd_create(self):
|
||||
fd = os.memfd_create("Hi", os.MFD_CLOEXEC)
|
||||
self.assertNotEqual(fd, -1)
|
||||
self.addCleanup(os.close, fd)
|
||||
self.assertFalse(os.get_inheritable(fd))
|
||||
with open(fd, "wb", closefd=False) as f:
|
||||
f.write(b'memfd_create')
|
||||
self.assertEqual(f.tell(), 12)
|
||||
|
||||
fd2 = os.memfd_create("Hi")
|
||||
self.addCleanup(os.close, fd2)
|
||||
self.assertFalse(os.get_inheritable(fd2))
|
||||
|
||||
|
||||
class OSErrorTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
class Str(str):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue