Skip to content

Commit 60bec8a

Browse files
rework weakref (RustPython#6916)
* Replace WeakListInner with inline atomic weakref list and stripe locks Remove heap-allocated WeakListInner (OncePtr<PyMutex<WeakListInner>>). WeakRefList now holds two inline atomic pointers (head, generic). PyWeak.parent replaced with wr_object pointing directly to referent. Add weakref_lock module with AtomicU8 spinlock array for thread safety. Rewrite upgrade/clear/drop_inner/count/get_weak_references with stripe lock. Make Pointers methods public in linked_list.rs. Remove expectedFailure from test_subclass_refs_dont_replace_standard_refs. * Auto-format: cargo fmt --all --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3e62928 commit 60bec8a

File tree

5 files changed

+279
-163
lines changed

5 files changed

+279
-163
lines changed

.cspell.dict/cpython.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ venvwlauncher
192192
venvwlaunchert
193193
wbits
194194
weakreflist
195+
weakrefobject
195196
webpki
196197
withitem
197198
withs

Lib/test/test_weakref.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ def __call__(self):
10791079
self.assertIsNone(mr())
10801080
self.assertTrue(mr.called)
10811081

1082-
@unittest.expectedFailure # TODO: RUSTPYTHON
10831082
def test_subclass_refs_dont_replace_standard_refs(self):
10841083
class MyRef(weakref.ref):
10851084
pass

crates/common/src/linked_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,15 @@ impl<T> Pointers<T> {
333333
}
334334
}
335335

336-
const fn get_prev(&self) -> Option<NonNull<T>> {
336+
pub const fn get_prev(&self) -> Option<NonNull<T>> {
337337
// SAFETY: prev is the first field in PointersInner, which is #[repr(C)].
338338
unsafe {
339339
let inner = self.inner.get();
340340
let prev = inner as *const Option<NonNull<T>>;
341341
ptr::read(prev)
342342
}
343343
}
344-
const fn get_next(&self) -> Option<NonNull<T>> {
344+
pub const fn get_next(&self) -> Option<NonNull<T>> {
345345
// SAFETY: next is the second field in PointersInner, which is #[repr(C)].
346346
unsafe {
347347
let inner = self.inner.get();
@@ -351,15 +351,15 @@ impl<T> Pointers<T> {
351351
}
352352
}
353353

354-
const fn set_prev(&mut self, value: Option<NonNull<T>>) {
354+
pub const fn set_prev(&mut self, value: Option<NonNull<T>>) {
355355
// SAFETY: prev is the first field in PointersInner, which is #[repr(C)].
356356
unsafe {
357357
let inner = self.inner.get();
358358
let prev = inner as *mut Option<NonNull<T>>;
359359
ptr::write(prev, value);
360360
}
361361
}
362-
const fn set_next(&mut self, value: Option<NonNull<T>>) {
362+
pub const fn set_next(&mut self, value: Option<NonNull<T>>) {
363363
// SAFETY: next is the second field in PointersInner, which is #[repr(C)].
364364
unsafe {
365365
let inner = self.inner.get();

0 commit comments

Comments
 (0)