Skip to content

Commit a53451b

Browse files
authored
Merge pull request #3386 from coolreader18/no-arc
Big overhaul part 1 - replace PyRc with manual RefCount + WeakRefList
2 parents b8624c6 + 790090d commit a53451b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1526
-533
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_weakrefset.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ def _remove(item, selfref=ref(self)):
5151
self.update(data)
5252

5353
def _commit_removals(self):
54-
l = self._pending_removals
54+
pop = self._pending_removals.pop
5555
discard = self.data.discard
56-
while l:
57-
discard(l.pop())
56+
while True:
57+
try:
58+
item = pop()
59+
except IndexError:
60+
return
61+
discard(item)
5862

5963
def __iter__(self):
6064
with _IterationGuard(self):

Lib/test/test_copy.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -826,18 +826,12 @@ class C(object):
826826
v[x] = y
827827
self.assertNotIn(x, u)
828828

829-
# TODO: RUSTPYTHON
830-
@unittest.expectedFailure
831829
def test_copy_weakkeydict(self):
832830
self._check_copy_weakdict(weakref.WeakKeyDictionary)
833831

834-
# TODO: RUSTPYTHON
835-
@unittest.expectedFailure
836832
def test_copy_weakvaluedict(self):
837833
self._check_copy_weakdict(weakref.WeakValueDictionary)
838834

839-
# TODO: RUSTPYTHON
840-
@unittest.expectedFailure
841835
def test_deepcopy_weakkeydict(self):
842836
class C(object):
843837
def __init__(self, i):
@@ -857,8 +851,6 @@ def __init__(self, i):
857851
del c
858852
self.assertEqual(len(v), 1)
859853

860-
# TODO: RUSTPYTHON
861-
@unittest.expectedFailure
862854
def test_deepcopy_weakvaluedict(self):
863855
class C(object):
864856
def __init__(self, i):

Lib/test/test_functools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,6 @@ class A(object):
500500

501501
a = A()
502502

503-
# TODO: RUSTPYTHON
504-
@unittest.expectedFailure
505503
def test_arg_combinations(self):
506504
self.assertEqual(self.a.nothing(), ((self.a,), {}))
507505
self.assertEqual(self.a.nothing(5), ((self.a, 5), {}))

Lib/test/test_memoryview.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,6 @@ def test_hash_writable(self):
343343
m = self._view(b)
344344
self.assertRaises(ValueError, hash, m)
345345

346-
# TODO: RUSTPYTHON
347-
@unittest.expectedFailure
348346
def test_weakref(self):
349347
# Check memoryviews are weakrefable
350348
for tp in self._types:

Lib/test/test_positional_only_arg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ def g(x2,/,y2):
318318
with self.assertRaisesRegex(TypeError, r"g\(\) takes 2 positional arguments but 3 were given"):
319319
f(1,2)(3,4,5)
320320

321-
# TODO: RUSTPYTHON
322-
@unittest.expectedFailure
323321
def test_same_keyword_as_positional_with_kwargs(self):
324322
def f(something,/,**kwargs):
325323
return (something, kwargs)

Lib/test/test_tempfile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,6 @@ def generator():
14541454
self.assertNotIn("Exception ", err)
14551455
self.assertIn("ResourceWarning: Implicitly cleaning up", err)
14561456

1457-
# TODO: RUSTPYTHON
1458-
@unittest.expectedFailure
14591457
def test_warnings_on_cleanup(self):
14601458
# ResourceWarning will be triggered by __del__
14611459
with self.do_create() as dir:

Lib/test/test_typing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,8 +3739,6 @@ def test_basics_keywords_syntax(self):
37393739
self.assertEqual(Emp.__annotations__, {'name': str, 'id': int})
37403740
self.assertEqual(Emp.__total__, True)
37413741

3742-
# TODO: RUSTPYTHON
3743-
@unittest.expectedFailure
37443742
def test_typeddict_special_keyword_names(self):
37453743
TD = TypedDict("TD", cls=type, self=object, typename=str, _typename=int, fields=list, _fields=dict)
37463744
self.assertEqual(TD.__name__, 'TD')

Lib/test/test_weakref.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ def test_basic_ref(self):
113113
del o
114114
repr(wr)
115115

116-
# TODO: RUSTPYTHON
117-
@unittest.expectedFailure
118116
def test_basic_callback(self):
119117
self.check_basic_callback(C)
120118
self.check_basic_callback(create_function)
@@ -132,8 +130,6 @@ def test_cfunction(self):
132130
self.check_basic_ref(create_cfunction)
133131
self.check_basic_callback(create_cfunction)
134132

135-
# TODO: RUSTPYTHON
136-
@unittest.expectedFailure
137133
def test_multiple_callbacks(self):
138134
o = C()
139135
ref1 = weakref.ref(o, self.callback)
@@ -166,7 +162,8 @@ def test_constructor_kwargs(self):
166162
c = C()
167163
self.assertRaises(TypeError, weakref.ref, c, callback=None)
168164

169-
@unittest.skip("TODO: RUSTPYTHON, thread 'main' panicked at 'Passed a callback to weakproxy, but weakproxy does not yet support proxies.'")
165+
# TODO: RUSTPYTHON
166+
@unittest.expectedFailure
170167
def test_proxy_ref(self):
171168
o = C()
172169
o.bar = 1
@@ -201,8 +198,6 @@ def check_basic_callback(self, factory):
201198
self.assertIsNone(ref(),
202199
"ref2 should be dead after deleting object reference")
203200

204-
# TODO: RUSTPYTHON
205-
@unittest.expectedFailure
206201
def test_ref_reuse(self):
207202
o = C()
208203
ref1 = weakref.ref(o)
@@ -332,7 +327,8 @@ def __imatmul__(self, other):
332327
def test_shared_ref_without_callback(self):
333328
self.check_shared_without_callback(weakref.ref)
334329

335-
@unittest.skip("TODO: RUSTPYTHON, thread 'main' panicked at 'Passed a callback to weakproxy, but weakproxy does not yet support proxies.'")
330+
# TODO: RUSTPYTHON
331+
@unittest.expectedFailure
336332
def test_shared_proxy_without_callback(self):
337333
self.check_shared_without_callback(weakref.proxy)
338334

@@ -439,7 +435,6 @@ def __iter__(self):
439435
# can be killed in the middle of the call
440436
"blech" in p
441437

442-
@unittest.skip("TODO: RUSTPYTHON, thread 'main' panicked at 'Passed a callback to weakproxy, but weakproxy does not yet support proxies.'")
443438
def test_getweakrefcount(self):
444439
o = C()
445440
ref1 = weakref.ref(o)
@@ -461,8 +456,6 @@ def test_getweakrefcount(self):
461456
self.assertEqual(weakref.getweakrefcount(1), 0,
462457
"got wrong number of weak reference objects for int")
463458

464-
# TODO: RUSTPYTHON
465-
@unittest.expectedFailure
466459
def test_getweakrefs(self):
467460
o = C()
468461
ref1 = weakref.ref(o, self.callback)
@@ -828,8 +821,6 @@ def test_init(self):
828821
# No exception should be raised here
829822
gc.collect()
830823

831-
# TODO: RUSTPYTHON
832-
@unittest.expectedFailure
833824
def test_classes(self):
834825
# Check that classes are weakrefable.
835826
class A(object):
@@ -1003,8 +994,6 @@ class MyRef(weakref.ref):
1003994
self.assertIn(r1, refs[1:])
1004995
self.assertIn(r3, refs[1:])
1005996

1006-
# TODO: RUSTPYTHON
1007-
@unittest.expectedFailure
1008997
def test_subclass_refs_dont_conflate_callbacks(self):
1009998
class MyRef(weakref.ref):
1010999
pass
@@ -1107,8 +1096,6 @@ def test_method_dead(self):
11071096
gc.collect()
11081097
self.assertIs(r(), None)
11091098

1110-
# TODO: RUSTPYTHON
1111-
@unittest.expectedFailure
11121099
def test_callback_when_object_dead(self):
11131100
# Test callback behaviour when object dies first.
11141101
C = self._subclass()
@@ -1125,8 +1112,6 @@ def cb(arg):
11251112
gc.collect()
11261113
self.assertEqual(calls, [r])
11271114

1128-
# TODO: RUSTPYTHON
1129-
@unittest.expectedFailure
11301115
def test_callback_when_method_dead(self):
11311116
# Test callback behaviour when method dies first.
11321117
C = self._subclass()
@@ -1154,8 +1139,6 @@ def cb(_):
11541139
del r
11551140
self.assertIs(wr(), None)
11561141

1157-
# TODO: RUSTPYTHON
1158-
@unittest.expectedFailure
11591142
def test_equality(self):
11601143
def _eq(a, b):
11611144
self.assertTrue(a == b)
@@ -1282,8 +1265,6 @@ def test_weak_keyed_len_race(self):
12821265
def test_weak_valued_len_race(self):
12831266
self.check_len_race(weakref.WeakValueDictionary, lambda k: (1, k))
12841267

1285-
# TODO: RUSTPYTHON
1286-
@unittest.expectedFailure
12871268
def test_weak_values(self):
12881269
#
12891270
# This exercises d.copy(), d.items(), d[], del d[], len(d).
@@ -1313,8 +1294,6 @@ def test_weak_values(self):
13131294
dict[2] = C()
13141295
self.assertRaises(KeyError, dict.__getitem__, 2)
13151296

1316-
# TODO: RUSTPYTHON
1317-
@unittest.expectedFailure
13181297
def test_weak_keys(self):
13191298
#
13201299
# This exercises d.copy(), d.items(), d[] = v, d[], del d[],
@@ -1492,8 +1471,6 @@ def check_weak_del_and_len_while_iterating(self, dict, testcontext):
14921471
self.assertEqual(len(dict), 0)
14931472
self.assertEqual(len(dict), 0)
14941473

1495-
# TODO: RUSTPYTHON
1496-
@unittest.expectedFailure
14971474
def test_weak_keys_destroy_while_iterating(self):
14981475
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
14991476
dict, objects = self.make_weak_keyed_dict()
@@ -1520,8 +1497,6 @@ def testcontext():
15201497
dict, objects = self.make_weak_keyed_dict()
15211498
self.check_weak_del_and_len_while_iterating(dict, testcontext)
15221499

1523-
# TODO: RUSTPYTHON
1524-
@unittest.expectedFailure
15251500
def test_weak_values_destroy_while_iterating(self):
15261501
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
15271502
dict, objects = self.make_weak_valued_dict()
@@ -1724,8 +1699,6 @@ def test_weak_keyed_bad_delitem(self):
17241699
self.assertRaises(TypeError, d.__getitem__, 13)
17251700
self.assertRaises(TypeError, d.__setitem__, 13, 13)
17261701

1727-
# TODO: RUSTPYTHON
1728-
@unittest.expectedFailure
17291702
def test_weak_keyed_cascading_deletes(self):
17301703
# SF bug 742860. For some reason, before 2.3 __delitem__ iterated
17311704
# over the keys via self.data.iterkeys(). If things vanished from
@@ -1921,8 +1894,6 @@ def _collect_if_necessary(self):
19211894
if sys.implementation.name != 'cpython':
19221895
support.gc_collect()
19231896

1924-
# TODO: RUSTPYTHON
1925-
@unittest.expectedFailure
19261897
def test_finalize(self):
19271898
def add(x,y,z):
19281899
res.append(x + y + z)
@@ -1995,8 +1966,6 @@ def fin(*args, **kwargs):
19951966
self.assertRaises(TypeError, weakref.finalize, a)
19961967
self.assertRaises(TypeError, weakref.finalize)
19971968

1998-
# TODO: RUSTPYTHON
1999-
@unittest.expectedFailure
20001969
def test_order(self):
20011970
a = self.A()
20021971
res = []
@@ -2036,8 +2005,6 @@ def test_order(self):
20362005
expected = ['A', 'f3', 'B', 'C', 'f4', 'f2', 'f1', 'D']
20372006
self.assertEqual(res, expected)
20382007

2039-
# TODO: RUSTPYTHON
2040-
@unittest.expectedFailure
20412008
def test_all_freed(self):
20422009
# we want a weakrefable subclass of weakref.finalize
20432010
class MyFinalizer(weakref.finalize):

Lib/test/test_weakset.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def test_methods(self):
4343
def test_new_or_init(self):
4444
self.assertRaises(TypeError, WeakSet, [], 2)
4545

46-
# TODO: RUSTPYTHON
47-
@unittest.expectedFailure
4846
def test_len(self):
4947
self.assertEqual(len(self.s), len(self.d))
5048
self.assertEqual(len(self.fs), 1)
@@ -60,8 +58,6 @@ def test_contains(self):
6058
del self.obj
6159
self.assertNotIn(ustr('F'), self.fs)
6260

63-
# TODO: RUSTPYTHON
64-
@unittest.expectedFailure
6561
def test_union(self):
6662
u = self.s.union(self.items2)
6763
for c in self.letters:
@@ -84,8 +80,6 @@ def test_or(self):
8480
self.assertEqual(self.s | set(self.items2), i)
8581
self.assertEqual(self.s | frozenset(self.items2), i)
8682

87-
# TODO: RUSTPYTHON
88-
@unittest.expectedFailure
8983
def test_intersection(self):
9084
s = WeakSet(self.letters)
9185
i = s.intersection(self.items2)
@@ -123,8 +117,6 @@ def test_sub(self):
123117
self.assertEqual(self.s - set(self.items2), i)
124118
self.assertEqual(self.s - frozenset(self.items2), i)
125119

126-
# TODO: RUSTPYTHON
127-
@unittest.expectedFailure
128120
def test_symmetric_difference(self):
129121
i = self.s.symmetric_difference(self.items2)
130122
for c in self.letters:
@@ -215,8 +207,6 @@ def test_copy(self):
215207
self.assertEqual(self.s, dup)
216208
self.assertNotEqual(id(self.s), id(dup))
217209

218-
# TODO: RUSTPYTHON
219-
@unittest.expectedFailure
220210
def test_add(self):
221211
x = ustr('Q')
222212
self.s.add(x)
@@ -352,8 +342,6 @@ def test_ne(self):
352342
s2 = WeakSet()
353343
self.assertFalse(s1 != s2)
354344

355-
# TODO: RUSTPYTHON
356-
@unittest.expectedFailure
357345
def test_weak_destroy_while_iterating(self):
358346
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
359347
# Create new items to be sure no-one else holds a reference
@@ -370,8 +358,6 @@ def test_weak_destroy_while_iterating(self):
370358
# The removal has been committed
371359
self.assertEqual(len(s), len(items))
372360

373-
# TODO: RUSTPYTHON
374-
@unittest.expectedFailure
375361
def test_weak_destroy_and_mutate_while_iterating(self):
376362
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
377363
items = [ustr(c) for c in string.ascii_letters]

0 commit comments

Comments
 (0)