Skip to content

Commit 2499e1c

Browse files
committed
Remove PyBoundMethod freelist to fix refcount/weakref test failures
Non-Option PyObjectRef fields retain references in freelist, causing weakref and refcount assertions to fail in test_unittest, test_multiprocessing, and test_socket.
1 parent 0c966c3 commit 2499e1c

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

crates/vm/src/builtins/function.rs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use crate::{
2020
Callable, Comparable, Constructor, GetAttr, GetDescriptor, PyComparisonOp, Representable,
2121
},
2222
};
23-
use core::cell::Cell;
24-
use core::ptr::NonNull;
2523
use core::sync::atomic::{AtomicU32, Ordering::Relaxed};
2624
use itertools::Itertools;
2725
#[cfg(feature = "jit")]
@@ -1081,7 +1079,7 @@ impl Constructor for PyFunction {
10811079
}
10821080
}
10831081

1084-
#[pyclass(module = false, name = "method", traverse, clear = false)]
1082+
#[pyclass(module = false, name = "method", traverse)]
10851083
#[derive(Debug)]
10861084
pub struct PyBoundMethod {
10871085
object: PyObjectRef,
@@ -1194,49 +1192,11 @@ impl PyBoundMethod {
11941192
}
11951193
}
11961194

1197-
// spell-checker:ignore MAXFREELIST
1198-
thread_local! {
1199-
static BOUND_METHOD_FREELIST: Cell<crate::object::FreeList<PyBoundMethod>> = const { Cell::new(crate::object::FreeList::new()) };
1200-
}
1201-
12021195
impl PyPayload for PyBoundMethod {
1203-
const MAX_FREELIST: usize = 20;
1204-
const HAS_FREELIST: bool = true;
1205-
12061196
#[inline]
12071197
fn class(ctx: &Context) -> &'static Py<PyType> {
12081198
ctx.types.bound_method_type
12091199
}
1210-
1211-
#[inline]
1212-
unsafe fn freelist_push(obj: *mut PyObject) -> bool {
1213-
BOUND_METHOD_FREELIST
1214-
.try_with(|fl| {
1215-
let mut list = fl.take();
1216-
let stored = if list.len() < Self::MAX_FREELIST {
1217-
list.push(obj);
1218-
true
1219-
} else {
1220-
false
1221-
};
1222-
fl.set(list);
1223-
stored
1224-
})
1225-
.unwrap_or(false)
1226-
}
1227-
1228-
#[inline]
1229-
unsafe fn freelist_pop() -> Option<NonNull<PyObject>> {
1230-
BOUND_METHOD_FREELIST
1231-
.try_with(|fl| {
1232-
let mut list = fl.take();
1233-
let result = list.pop().map(|p| unsafe { NonNull::new_unchecked(p) });
1234-
fl.set(list);
1235-
result
1236-
})
1237-
.ok()
1238-
.flatten()
1239-
}
12401200
}
12411201

12421202
impl Representable for PyBoundMethod {

0 commit comments

Comments
 (0)