Skip to content

Commit 2fdfeae

Browse files
committed
OSC one off, maybe due to open following pending merge tag?
1 parent 12aabaf commit 2fdfeae

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

Lib/test/test_regions/test_clean.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ def test_try_close_sub_region(self):
2828
# Cleaning a dirty parent region should clean the child as well
2929
region.clean()
3030

31-
# The region should now be clean
31+
# The regions should now be clean
3232
self.assertFalse(sub.is_dirty)
33+
self.assertEqual(sub._lrc, 1, "The local should be the only known reference")
34+
self.assertEqual(sub._osc, 0, "No subregions should be present")
35+
self.assertEqual(region._osc, 1)
36+
37+
# Removing the reference into sub, should close it and inform the parent
38+
sub = None
39+
self.assertEqual(region._osc, 0)
40+
3341

3442
def test_clean_removes_unreachable(self):
3543
region = Region()

Lib/test/test_regions/test_core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ def test_instance_dict_is_owned(self):
4747
self.assertTrue(r.owns(r.__dict__))
4848

4949

50+
class TestRegionCounts(unittest.TestCase):
51+
def test_osc_1(self):
52+
r = Region()
53+
r.sub = Region()
54+
55+
# Pre-condition
56+
self.assertEqual(r._osc, 0, "The sub region should be closed")
57+
58+
# This should open the sub-region
59+
sub = r.sub
60+
61+
# Post-condition
62+
self.assertEqual(r._osc, 1, "The sub region should be open now")
63+
64+
5065
class ImplicitFreezingForImmortal(unittest.TestCase):
5166
def test_implicit_freeze_importal(self):
5267
# This would ideally check that the immortal objects

Python/region.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ static int regiondata_set_parent(Py_region_t region, Py_region_t new_parent) {
862862
return 1;
863863
}
864864

865+
// TODO(regions): xFrednet: This is probably wrong? At least cleaning
866+
// (a region and sub region) seems to have a off-by-one counting a OSC of 2
865867
if (regiondata_dec_osc(old_parent)) {
866868
// Undo the inc_osc from above.
867869
regiondata_dec_osc(new_parent);
@@ -1462,7 +1464,6 @@ int regiondata_clean(PyObject* bridge) {
14621464
Py_region_t item_region = _PyRegion_Get(item);
14631465

14641466
assert(regiondata_is_bridge(item_region, item));
1465-
// TODO: Account in LRC for reference from owner, if present.
14661467

14671468
// Store metadata for the new region
14681469
assert(HAS_DATA(item_region));
@@ -1491,17 +1492,16 @@ int regiondata_clean(PyObject* bridge) {
14911492
}
14921493
staged_ref_commit(staged_ref);
14931494

1495+
// TODO: Account in LRC for reference from owner, if present.
1496+
1497+
14941498
// TODO(regions): xFrednet: This doesn't account for region union...
14951499
//
1496-
// `stage_objects` accounts for a reference from a contained object to
1497-
// the added object, mening that the LRC is missing a count of 1 here.
1498-
// We increment the LRC if it doesn't have a owner.
1499-
if (owner == 0) {
1500-
SUCCEEDS(regiondata_inc_lrc(clean_region));
1501-
// FIXME(regions): xFrednet: The hack currently marks the region as
1502-
// dirty when the LRC is increased. the following function should
1503-
// no longer be used when all barriers are in place
1504-
SUCCEEDS(regiondata_mark_as_clean(clean_region));
1500+
// `stage_objects` doesn't know about the reference from the owner and
1501+
// counts it as a local reference. Meaning the LRC counts one more
1502+
// reference than present.
1503+
if (owner != 0) {
1504+
SUCCEEDS(regiondata_dec_lrc(clean_region));
15051505
}
15061506

15071507
// The region should now be marked as clean

0 commit comments

Comments
 (0)