FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Separate WeakRefList from ObjExt prefix by youknowone · Pull Request #7365 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rs  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 14 additions & 4 deletions crates/vm/src/builtins/type.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ impl PyType {
slots.flags |= PyTypeFlags::HAS_DICT
}

// Inherit HAS_WEAKREF from any base in MRO that has it
// Inherit HAS_WEAKREF/MANAGED_WEAKREF from any base in MRO that has it
if mro
.iter()
.any(|b| b.slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF))
{
slots.flags |= PyTypeFlags::HAS_WEAKREF
slots.flags |= PyTypeFlags::HAS_WEAKREF | PyTypeFlags::MANAGED_WEAKREF
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

// Inherit SEQUENCE and MAPPING flags from base classes
Expand All @@ -605,6 +605,11 @@ impl PyType {

Self::inherit_readonly_slots(&mut slots, &base);

// Normalize: any type with HAS_WEAKREF gets MANAGED_WEAKREF
if slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF) {
slots.flags |= PyTypeFlags::MANAGED_WEAKREF;
}

if let Some(qualname) = attrs.get(identifier!(ctx, __qualname__))
&& !qualname.fast_isinstance(ctx.types.str_type)
{
Expand Down Expand Up @@ -655,7 +660,7 @@ impl PyType {
slots.flags |= PyTypeFlags::HAS_DICT
}
if base.slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF) {
slots.flags |= PyTypeFlags::HAS_WEAKREF
slots.flags |= PyTypeFlags::HAS_WEAKREF | PyTypeFlags::MANAGED_WEAKREF
}

// Inherit SEQUENCE and MAPPING flags from base class
Expand All @@ -668,6 +673,11 @@ impl PyType {

Self::inherit_readonly_slots(&mut slots, &base);

// Normalize: any type with HAS_WEAKREF gets MANAGED_WEAKREF
if slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF) {
slots.flags |= PyTypeFlags::MANAGED_WEAKREF;
}

let bases = PyRwLock::new(vec![base.clone()]);
let mro = base.mro_map_collect(|x| x.to_owned());

Expand Down Expand Up @@ -1976,7 +1986,7 @@ impl Constructor for PyType {
// 2. __weakref__ is in __slots__
let may_add_weakref = !base.slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF);
if (heaptype_slots.is_none() && may_add_weakref) || add_weakref {
flags |= PyTypeFlags::HAS_WEAKREF;
flags |= PyTypeFlags::HAS_WEAKREF | PyTypeFlags::MANAGED_WEAKREF;
}

let (slots, heaptype_ext) = {
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL