File tree 1 file changed +13
-9
lines changed
1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -388,15 +388,19 @@ inline void clear_patients(PyObject *self) {
388
388
auto *instance = reinterpret_cast <detail::instance *>(self);
389
389
auto &internals = get_internals ();
390
390
auto pos = internals.patients .find (self);
391
- assert (pos != internals.patients .end ());
392
- // Clearing the patients can cause more Python code to run, which
393
- // can invalidate the iterator. Extract the vector of patients
394
- // from the unordered_map first.
395
- auto patients = std::move (pos->second );
396
- internals.patients .erase (pos);
397
- instance->has_patients = false ;
398
- for (PyObject *&patient : patients) {
399
- Py_CLEAR (patient);
391
+
392
+ if (pos != internals.patients .end ()) {
393
+ // Clearing the patients can cause more Python code to run, which
394
+ // can invalidate the iterator. Extract the vector of patients
395
+ // from the unordered_map first.
396
+ auto patients = std::move (pos->second );
397
+ internals.patients .erase (pos);
398
+ instance->has_patients = false ;
399
+ for (PyObject *&patient : patients) {
400
+ Py_CLEAR (patient);
401
+ }
402
+ } else {
403
+ assert (pos != internals.patients .end ());
400
404
}
401
405
}
402
406
You can’t perform that action at this time.
0 commit comments