Skip to content

Commit

Permalink
bpo-35381 Remove all static state from posixmodule (GH-15892)
Browse files Browse the repository at this point in the history
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque.

The original PR that got messed up a rebase: #10854. All the issues in that commit have now been addressed since #11661 got committed.

This change also removes any state from the data segment and onto the module state itself.


https://bugs.python.org/issue35381



Automerge-Triggered-By: @encukou
  • Loading branch information
eduardo-elizondo authored and miss-islington committed Nov 5, 2019
1 parent 5e01a65 commit b396663
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 226 deletions.
30 changes: 30 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3638,6 +3638,24 @@ def test_os_all(self):
self.assertIn('walk', os.__all__)


class TestDirEntry(unittest.TestCase):
def setUp(self):
self.path = os.path.realpath(support.TESTFN)
self.addCleanup(support.rmtree, self.path)
os.mkdir(self.path)

def test_uninstantiable(self):
self.assertRaises(TypeError, os.DirEntry)

def test_unpickable(self):
filename = create_file(os.path.join(self.path, "file.txt"), b'python')
entry = [entry for entry in os.scandir(self.path)].pop()
self.assertIsInstance(entry, os.DirEntry)
self.assertEqual(entry.name, "file.txt")
import pickle
self.assertRaises(TypeError, pickle.dumps, entry, filename)


class TestScandir(unittest.TestCase):
check_no_resource_warning = support.check_no_resource_warning

Expand Down Expand Up @@ -3672,6 +3690,18 @@ def assert_stat_equal(self, stat1, stat2, skip_fields):
else:
self.assertEqual(stat1, stat2)

def test_uninstantiable(self):
scandir_iter = os.scandir(self.path)
self.assertRaises(TypeError, type(scandir_iter))
scandir_iter.close()

def test_unpickable(self):
filename = self.create_file("file.txt")
scandir_iter = os.scandir(self.path)
import pickle
self.assertRaises(TypeError, pickle.dumps, scandir_iter, filename)
scandir_iter.close()

def check_entry(self, entry, name, is_dir, is_file, is_symlink):
self.assertIsInstance(entry, os.DirEntry)
self.assertEqual(entry.name, name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Convert posixmodule.c statically allocated types ``DirEntryType`` and
``ScandirIteratorType`` to heap-allocated types.
4 changes: 2 additions & 2 deletions Modules/clinic/posixmodule.c.h

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

Loading

0 comments on commit b396663

Please sign in to comment.