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)?;
|
||||
let py_obj_id: u64 = self.helper.id_fn.call1(py, (pyty,))?.extract(py)?;
|
||||
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())
|
||||
};
|
||||
if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
||||
|
@ -607,11 +610,13 @@ impl InnerResolver {
|
|||
let pyid_to_def = self.pyid_to_def.read();
|
||||
let constructor_ty = pyid_to_def.get(&py_obj_id).and_then(|def_id| {
|
||||
defs.iter().find_map(|def| {
|
||||
if let Some(rear_guard) = def.try_read(){
|
||||
if let TopLevelDef::Class {
|
||||
object_id, methods, constructor, ..
|
||||
} = &*rear_guard {
|
||||
if object_id == def_id && constructor.is_some() && methods.iter().any(|(s, _, _)| s == &"__init__".into()) {
|
||||
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 { object_id, methods, constructor, .. } = &*rear_guard
|
||||
{
|
||||
if object_id == def_id
|
||||
&& constructor.is_some()
|
||||
&& methods.iter().any(|(s, _, _)| s == &"__init__".into())
|
||||
{
|
||||
return *constructor;
|
||||
}
|
||||
}
|
||||
|
@ -1138,7 +1143,7 @@ impl InnerResolver {
|
|||
let val: bool = obj.extract()?;
|
||||
Ok(SymbolValue::Bool(val))
|
||||
} else if ty_id == self.primitive_ids.string {
|
||||
let val:String = obj.extract()?;
|
||||
let val: String = obj.extract()?;
|
||||
Ok(SymbolValue::Str(val))
|
||||
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
||||
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.