Created
June 24, 2020 22:32
-
-
Save colesbury/76ad12a895449883b97a730deefb1e6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h | |
| index 45697f2..027a717 100644 | |
| --- a/include/pybind11/detail/class.h | |
| +++ b/include/pybind11/detail/class.h | |
| @@ -216,19 +216,24 @@ inline void traverse_offset_bases(void *valueptr, const detail::type_info *tinfo | |
| } | |
| inline bool register_instance_impl(void *ptr, instance *self) { | |
| - get_internals().registered_instances.emplace(ptr, self); | |
| + with_internals([&](internals &internals) { | |
| + internals.registered_instances.emplace(ptr, self); | |
| + }); | |
| return true; // unused, but gives the same signature as the deregister func | |
| } | |
| inline bool deregister_instance_impl(void *ptr, instance *self) { | |
| - auto ®istered_instances = get_internals().registered_instances; | |
| - auto range = registered_instances.equal_range(ptr); | |
| - for (auto it = range.first; it != range.second; ++it) { | |
| - if (Py_TYPE(self) == Py_TYPE(it->second)) { | |
| - registered_instances.erase(it); | |
| - return true; | |
| + bool ret = false; | |
| + with_internals([&](internals &internals) { | |
| + auto ®istered_instances = internals.registered_instances; | |
| + auto range = registered_instances.equal_range(ptr); | |
| + for (auto it = range.first; it != range.second; ++it) { | |
| + if (Py_TYPE(self) == Py_TYPE(it->second)) { | |
| + registered_instances.erase(it); | |
| + ret = true; | |
| + } | |
| } | |
| - } | |
| - return false; | |
| + }); | |
| + return ret; | |
| } | |
| inline void register_instance(instance *self, void *valptr, const type_info *tinfo) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment