Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix slot call deadlock #3792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,12 @@ impl GetAttr for PyType {

if let Some(ref attr) = mcl_attr {
let attr_class = attr.class();
if attr_class
let has_descr_set = attr_class
.mro_find_map(|cls| cls.slots.descr_set.load())
.is_some()
{
if let Some(descr_get) = attr_class.mro_find_map(|cls| cls.slots.descr_get.load()) {
.is_some();
if has_descr_set {
let descr_get = attr_class.mro_find_map(|cls| cls.slots.descr_get.load());
if let Some(descr_get) = descr_get {
let mcl = mcl.into_owned().into();
return descr_get(attr.clone(), Some(zelf.to_owned().into()), Some(mcl), vm);
}
Expand All @@ -681,7 +682,8 @@ impl GetAttr for PyType {
let zelf_attr = zelf.get_attr(name);

if let Some(ref attr) = zelf_attr {
if let Some(descr_get) = attr.class().mro_find_map(|cls| cls.slots.descr_get.load()) {
let descr_get = attr.class().mro_find_map(|cls| cls.slots.descr_get.load());
if let Some(descr_get) = descr_get {
drop(mcl);
return descr_get(attr.clone(), None, Some(zelf.to_owned().into()), vm);
}
Expand Down Expand Up @@ -745,7 +747,8 @@ impl Callable for PyType {
return Ok(obj);
}

if let Some(init_method) = obj.class().mro_find_map(|cls| cls.slots.init.load()) {
let init = obj.class().mro_find_map(|cls| cls.slots.init.load());
if let Some(init_method) = init {
init_method(obj.clone(), args, vm)?;
}
Ok(obj)
Expand Down
8 changes: 4 additions & 4 deletions vm/src/function/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ where
T: TryFromObject,
{
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
let iterfn;
{
let iterfn = {
let cls = obj.class();
iterfn = cls.mro_find_map(|x| x.slots.iter.load());
let iterfn = cls.mro_find_map(|x| x.slots.iter.load());
if iterfn.is_none() && !cls.has_attr(identifier!(vm, __getitem__)) {
return Err(vm.new_type_error(format!("'{}' object is not iterable", cls.name())));
}
}
iterfn
};
Ok(Self {
iterable: obj,
iterfn,
Expand Down
3 changes: 2 additions & 1 deletion vm/src/object/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,8 @@ impl PyObject {
}

// CPython-compatible drop implementation
if let Some(slot_del) = self.class().mro_find_map(|cls| cls.slots.del.load()) {
let del = self.class().mro_find_map(|cls| cls.slots.del.load());
if let Some(slot_del) = del {
call_slot_del(self, slot_del)?;
}
if let Some(wrl) = self.weak_ref_list() {
Expand Down
3 changes: 2 additions & 1 deletion vm/src/protocol/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ impl PyBuffer {
impl TryFromBorrowedObject for PyBuffer {
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Self> {
let cls = obj.class();
if let Some(f) = cls.mro_find_map(|cls| cls.slots.as_buffer) {
let as_buffer = cls.mro_find_map(|cls| cls.slots.as_buffer);
if let Some(f) = as_buffer {
return f(obj, vm);
}
Err(vm.new_type_error(format!(
Expand Down
7 changes: 2 additions & 5 deletions vm/src/protocol/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,8 @@ impl PyMapping<'_> {
}

pub fn find_methods(obj: &PyObject, vm: &VirtualMachine) -> Option<&'static PyMappingMethods> {
if let Some(f) = obj.class().mro_find_map(|cls| cls.slots.as_mapping.load()) {
Some(f(obj, vm))
} else {
None
}
let as_mapping = obj.class().mro_find_map(|cls| cls.slots.as_mapping.load());
as_mapping.map(|f| f(obj, vm))
}

pub fn length_opt(&self, vm: &VirtualMachine) -> Option<PyResult<usize>> {
Expand Down
5 changes: 2 additions & 3 deletions vm/src/protocol/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ impl<'a> PyNumber<'a> {

impl PyNumber<'_> {
pub fn find_methods(obj: &PyObject, vm: &VirtualMachine) -> Option<&'static PyNumberMethods> {
obj.class()
.mro_find_map(|x| x.slots.as_number.load())
.map(|f| f(obj, vm))
let as_number = obj.class().mro_find_map(|x| x.slots.as_number.load());
as_number.map(|f| f(obj, vm))
}

pub fn methods(&self) -> &'static PyNumberMethods {
Expand Down
3 changes: 2 additions & 1 deletion vm/src/protocol/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ impl PySequence<'_> {
pub fn find_methods(obj: &PyObject, vm: &VirtualMachine) -> Option<&'static PySequenceMethods> {
let cls = obj.class();
if !cls.is(vm.ctx.types.dict_type) {
if let Some(f) = cls.mro_find_map(|x| x.slots.as_sequence.load()) {
let as_sequence = cls.mro_find_map(|x| x.slots.as_sequence.load());
if let Some(f) = as_sequence {
return Some(f(obj, vm));
}
}
Expand Down