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:
Zackery Spytz 2019-05-29 13:57:07 -06:00 committed by Christian Heimes
parent 0c2f930564
commit 43fdbd2729
10 changed files with 259 additions and 12 deletions

View file

@ -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):