Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -3557,13 +3557,10 @@ typing::Iterator<ValueType> make_value_iterator(Type &value, Extra &&...extra) {

template <typename InputType, typename OutputType>
void implicitly_convertible() {
static int tss_sentinel_pointee = 1; // arbitrary value
struct set_flag {
thread_specific_storage<int> &flag;
explicit set_flag(thread_specific_storage<int> &flag_) : flag(flag_) {
flag = &tss_sentinel_pointee; // trick: the pointer itself is the sentinel
}
~set_flag() { flag.reset(nullptr); }
bool &flag;
explicit set_flag(bool &flag_) : flag(flag_) { flag_ = true; }
~set_flag() { flag = false; }

// Prevent copying/moving to ensure RAII guard is used safely
set_flag(const set_flag &) = delete;
Expand All @@ -3572,7 +3569,7 @@ void implicitly_convertible() {
set_flag &operator=(set_flag &&) = delete;
};
auto implicit_caster = [](PyObject *obj, PyTypeObject *type) -> PyObject * {
static thread_specific_storage<int> currently_used;
thread_local bool currently_used = false;
if (currently_used) { // implicit conversions are non-reentrant
return nullptr;
}
Expand Down
Loading