File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ inline void try_translate_exceptions() {
50
50
- delegate translation to the next translator by throwing a new type of exception.
51
51
*/
52
52
53
- bool handled = with_internals ([&](internals &internals) {
53
+ bool handled = with_internals_for_exception_translator ([&](internals &internals) {
54
54
auto &local_exception_translators = get_local_internals ().registered_exception_translators ;
55
55
if (detail::apply_exception_translators (local_exception_translators)) {
56
56
return true ;
Original file line number Diff line number Diff line change @@ -177,6 +177,7 @@ static_assert(sizeof(instance_map_shard) % 64 == 0,
177
177
struct internals {
178
178
#ifdef Py_GIL_DISABLED
179
179
pymutex mutex;
180
+ pymutex exception_translator_mutex;
180
181
#endif
181
182
// std::type_index -> pybind11's type information
182
183
type_map<type_info *> registered_types_cpp;
@@ -641,6 +642,15 @@ inline auto with_internals(const F &cb) -> decltype(cb(get_internals())) {
641
642
return cb (internals);
642
643
}
643
644
645
+ template <typename F>
646
+ inline auto with_internals_for_exception_translator (const F &cb) -> decltype(cb(get_internals())) {
647
+ auto &internals = get_internals ();
648
+ #ifdef Py_GIL_DISABLED
649
+ std::unique_lock<pymutex> lock ((internals).exception_translator_mutex );
650
+ #endif
651
+ return cb (internals);
652
+ }
653
+
644
654
inline std::uint64_t mix64 (std::uint64_t z) {
645
655
// David Stafford's variant 13 of the MurmurHash3 finalizer popularized
646
656
// by the SplitMix PRNG.
Original file line number Diff line number Diff line change @@ -2573,7 +2573,7 @@ void implicitly_convertible() {
2573
2573
}
2574
2574
2575
2575
inline void register_exception_translator (ExceptionTranslator &&translator) {
2576
- detail::with_internals ([&](detail::internals &internals) {
2576
+ detail::with_internals_for_exception_translator ([&](detail::internals &internals) {
2577
2577
internals.registered_exception_translators .push_front (
2578
2578
std::forward<ExceptionTranslator>(translator));
2579
2579
});
@@ -2586,7 +2586,7 @@ inline void register_exception_translator(ExceptionTranslator &&translator) {
2586
2586
* the exception.
2587
2587
*/
2588
2588
inline void register_local_exception_translator (ExceptionTranslator &&translator) {
2589
- detail::with_internals ([&](detail::internals &internals) {
2589
+ detail::with_internals_for_exception_translator ([&](detail::internals &internals) {
2590
2590
(void ) internals;
2591
2591
detail::get_local_internals ().registered_exception_translators .push_front (
2592
2592
std::forward<ExceptionTranslator>(translator));
You can’t perform that action at this time.
0 commit comments