@@ -541,8 +541,6 @@ struct error_fetch_and_normalize {
541
541
return (PyErr_GivenExceptionMatches (m_type.ptr (), exc.ptr ()) != 0 );
542
542
}
543
543
544
- bool has_py_object_references () const { return m_type || m_value || m_trace; }
545
-
546
544
void release_py_object_references () {
547
545
m_type.release ().dec_ref ();
548
546
m_value.release ().dec_ref ();
@@ -580,20 +578,8 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::exception {
580
578
// / Fetches the current Python exception (using PyErr_Fetch()), which will clear the
581
579
// / current Python error indicator.
582
580
error_already_set ()
583
- : m_fetched_error{
584
- std::make_shared<detail::error_fetch_and_normalize>(" pybind11::error_already_set" )} {}
585
-
586
- // / WARNING: This destructor needs to acquire the Python GIL. This can lead to
587
- // / crashes (undefined behavior) if the Python interpreter is finalizing.
588
- ~error_already_set () override ;
589
-
590
- // This copy ctor does not need the GIL because it simply increments a shared_ptr use_count.
591
- error_already_set (const error_already_set &) noexcept = default ;
592
-
593
- // This move ctor cannot easily be deleted (some compilers need it).
594
- // It is the responsibility of the caller to not use the moved-from object.
595
- // For simplicity, guarding ifs are omitted.
596
- error_already_set (error_already_set &&) noexcept = default ;
581
+ : m_fetched_error{new detail::error_fetch_and_normalize (" pybind11::error_already_set" ),
582
+ m_fetched_error_deleter} {}
597
583
598
584
// / The what() result is built lazily on demand.
599
585
// / WARNING: This member function needs to acquire the Python GIL. This can lead to
@@ -637,6 +623,10 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::exception {
637
623
638
624
private:
639
625
std::shared_ptr<detail::error_fetch_and_normalize> m_fetched_error;
626
+
627
+ // / WARNING: This custom deleter needs to acquire the Python GIL. This can lead to
628
+ // / crashes (undefined behavior) if the Python interpreter is finalizing.
629
+ static void m_fetched_error_deleter (detail::error_fetch_and_normalize *raw_ptr);
640
630
};
641
631
#if defined(_MSC_VER)
642
632
# pragma warning(pop)
0 commit comments