WIP: support_string_class_attr #415
|
@ -304,7 +304,10 @@ impl InnerResolver {
|
||||||
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (pyty,))?,))?.extract(py)?;
|
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (pyty,))?,))?.extract(py)?;
|
||||||
let py_obj_id: u64 = self.helper.id_fn.call1(py, (pyty,))?.extract(py)?;
|
let py_obj_id: u64 = self.helper.id_fn.call1(py, (pyty,))?.extract(py)?;
|
||||||
let get_def_id = || {
|
let get_def_id = || {
|
||||||
|
|||||||
self.pyid_to_def.read().get(&ty_id).copied()
|
self.pyid_to_def
|
||||||
|
.read()
|
||||||
|
.get(&ty_id)
|
||||||
|
.copied()
|
||||||
.or_else(|| self.pyid_to_def.read().get(&py_obj_id).copied())
|
.or_else(|| self.pyid_to_def.read().get(&py_obj_id).copied())
|
||||||
};
|
};
|
||||||
if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
||||||
|
@ -318,7 +321,7 @@ impl InnerResolver {
|
||||||
} else if ty_id == self.primitive_ids.bool {
|
} else if ty_id == self.primitive_ids.bool {
|
||||||
Ok(Ok((primitives.bool, true)))
|
Ok(Ok((primitives.bool, true)))
|
||||||
} else if ty_id == self.primitive_ids.string {
|
} else if ty_id == self.primitive_ids.string {
|
||||||
Ok(Ok((primitives.str, true)))
|
Ok(Ok((primitives.str, true)))
|
||||||
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
||||||
Ok(Ok((primitives.float, true)))
|
Ok(Ok((primitives.float, true)))
|
||||||
} else if ty_id == self.primitive_ids.exception {
|
} else if ty_id == self.primitive_ids.exception {
|
||||||
|
@ -607,11 +610,13 @@ impl InnerResolver {
|
||||||
let pyid_to_def = self.pyid_to_def.read();
|
let pyid_to_def = self.pyid_to_def.read();
|
||||||
let constructor_ty = pyid_to_def.get(&py_obj_id).and_then(|def_id| {
|
let constructor_ty = pyid_to_def.get(&py_obj_id).and_then(|def_id| {
|
||||||
defs.iter().find_map(|def| {
|
defs.iter().find_map(|def| {
|
||||||
if let Some(rear_guard) = def.try_read(){
|
if let Some(rear_guard) = def.try_read() {
|
||||||
sb10q
commented
rear_guard ? rear_guard ?
abdul124
commented
The previous code entered deadlock since the last element inside the def was locked (not sure about the reason for this), so to avoid that, I replaced the read() function with try_read to prevent the blocking behavior. The previous code entered deadlock since the last element inside the def was locked (not sure about the reason for this), so to avoid that, I replaced the _read()_ function with _try_read_ to prevent the blocking behavior.
sb10q
commented
Sounds like the code would then fail randomly instead of deadlocking, then? Sounds like the code would then fail randomly instead of deadlocking, then?
abdul124
commented
From what I have tested, only the last element inside the class definitions was locked. I was unable to see what it corresponded to in the class, but methods including the constructor were already processed. I think avoiding deadlock here should be more important as the code after it can give more meaningful error messages. I will further look into the reason for this blocking and update here. From what I have tested, only the last element inside the class definitions was locked. I was unable to see what it corresponded to in the class, but methods including the constructor were already processed. I think avoiding deadlock here should be more important as the code after it can give more meaningful error messages. I will further look into the reason for this blocking and update here.
sb10q
commented
Please break it into another PR while you investigate it. Please break it into another PR while you investigate it.
|
|||||||
if let TopLevelDef::Class {
|
if let TopLevelDef::Class { object_id, methods, constructor, .. } = &*rear_guard
|
||||||
object_id, methods, constructor, ..
|
{
|
||||||
} = &*rear_guard {
|
if object_id == def_id
|
||||||
if object_id == def_id && constructor.is_some() && methods.iter().any(|(s, _, _)| s == &"__init__".into()) {
|
&& constructor.is_some()
|
||||||
|
&& methods.iter().any(|(s, _, _)| s == &"__init__".into())
|
||||||
|
{
|
||||||
return *constructor;
|
return *constructor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -633,8 +638,8 @@ impl InnerResolver {
|
||||||
self.primitive_ids.generic_alias.0,
|
self.primitive_ids.generic_alias.0,
|
||||||
self.primitive_ids.generic_alias.1,
|
self.primitive_ids.generic_alias.1,
|
||||||
]
|
]
|
||||||
.contains(&self.helper.id_fn.call1(py, (ty.clone(),))?.extract::<u64>(py)?)
|
.contains(&self.helper.id_fn.call1(py, (ty.clone(),))?.extract::<u64>(py)?)
|
||||||
|| self.pyid_to_def.read().contains_key(&py_obj_id)
|
|| self.pyid_to_def.read().contains_key(&py_obj_id)
|
||||||
{
|
{
|
||||||
obj
|
obj
|
||||||
} else {
|
} else {
|
||||||
|
@ -1138,7 +1143,7 @@ impl InnerResolver {
|
||||||
let val: bool = obj.extract()?;
|
let val: bool = obj.extract()?;
|
||||||
Ok(SymbolValue::Bool(val))
|
Ok(SymbolValue::Bool(val))
|
||||||
} else if ty_id == self.primitive_ids.string {
|
} else if ty_id == self.primitive_ids.string {
|
||||||
let val:String = obj.extract()?;
|
let val: String = obj.extract()?;
|
||||||
Ok(SymbolValue::Str(val))
|
Ok(SymbolValue::Str(val))
|
||||||
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
||||||
let val: f64 = obj.extract()?;
|
let val: f64 = obj.extract()?;
|
||||||
|
|
This is only used once. Worth defining?
Added this at the top for clarity in if condition, but yes since it is used only once, will rewrite this and move it with the calling condition.