Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
protect accesses to cnst->cnst_light_
[simgrid.git] / src / kernel / lmm / maxmin.cpp
index 25a5f24..1cc6c4e 100644 (file)
@@ -151,7 +151,7 @@ System::~System()
   Constraint* cnst;
 
   while ((var = extract_variable())) {
-    auto demangled = simgrid::xbt::demangle(typeid(*var->id_).name());
+    auto demangled = simgrid::xbt::demangle(var->id_ ? typeid(*var->id_).name() : "(unidentified)");
     XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(),
              var->rank_);
     var_free(var);
@@ -169,7 +169,7 @@ void System::cnst_free(Constraint* cnst)
   delete cnst;
 }
 
-Constraint::Constraint(void* id_value, double bound_value) : bound_(bound_value), id_(id_value)
+Constraint::Constraint(resource::Resource* id_value, double bound_value) : bound_(bound_value), id_(id_value)
 {
   rank_ = next_rank_++;
 
@@ -185,7 +185,7 @@ Constraint::Constraint(void* id_value, double bound_value) : bound_(bound_value)
   cnst_light_ = nullptr;
 }
 
-Constraint* System::constraint_new(void* id, double bound_value)
+Constraint* System::constraint_new(resource::Resource* id, double bound_value)
 {
   Constraint* cnst = new Constraint(id, bound_value);
   insert_constraint(cnst);
@@ -224,6 +224,13 @@ void System::variable_free(Variable* var)
   var_free(var);
 }
 
+void System::variable_free_all()
+{
+  Variable* var;
+  while ((var = extract_variable()))
+    variable_free(var);
+}
+
 void System::expand(Constraint* cnst, Variable* var, double consumption_weight)
 {
   modified_ = true;
@@ -610,7 +617,9 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
               cnst->cnst_light_ = nullptr;
             }
           } else {
-            cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
+            if (cnst->cnst_light_) {
+              cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
+            }
           }
           elem.make_inactive();
         } else {
@@ -639,10 +648,12 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
               cnst->cnst_light_ = nullptr;
             }
           } else {
-            cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
-            xbt_assert(not cnst->active_element_set_.empty(),
-                       "Should not keep a maximum constraint that has no active"
-                       " element! You want to check the maxmin precision and possible rounding effects.");
+            if (cnst->cnst_light_) {
+              cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
+              xbt_assert(not cnst->active_element_set_.empty(),
+                         "Should not keep a maximum constraint that has no active"
+                         " element! You want to check the maxmin precision and possible rounding effects.");
+            }
           }
         }
       }