File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -2626,15 +2626,12 @@ void print(Args &&...args) {
2626
2626
}
2627
2627
2628
2628
inline error_already_set::~error_already_set () {
2629
- auto e = m_fetched_error;
2630
- if (!(e.m_type || e.m_value || e.m_trace )) {
2629
+ if (!m_fetched_error.has_py_object_references ()) {
2631
2630
return ; // Avoid gil and scope overhead if there is nothing to release.
2632
2631
}
2633
2632
gil_scoped_acquire gil;
2634
2633
error_scope scope;
2635
- e.m_type .release ().dec_ref ();
2636
- e.m_value .release ().dec_ref ();
2637
- e.m_trace .release ().dec_ref ();
2634
+ m_fetched_error.release_py_object_references ();
2638
2635
}
2639
2636
2640
2637
inline error_already_set::error_already_set (const error_already_set &other)
Original file line number Diff line number Diff line change @@ -531,6 +531,14 @@ struct error_fetch_and_normalize {
531
531
return (PyErr_GivenExceptionMatches (m_type.ptr (), exc.ptr ()) != 0 );
532
532
}
533
533
534
+ bool has_py_object_references () const { return m_type || m_value || m_trace; }
535
+
536
+ void release_py_object_references () {
537
+ m_type.release ().dec_ref ();
538
+ m_value.release ().dec_ref ();
539
+ m_trace.release ().dec_ref ();
540
+ }
541
+
534
542
object m_type, m_value, m_trace;
535
543
mutable std::string m_lazy_error_string;
536
544
mutable bool m_lazy_error_string_completed = false ;
You can’t perform that action at this time.
0 commit comments