diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 97147904ce..5dbbb4ad53 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -196,7 +196,7 @@ struct function_record { bool prepend : 1; /// Number of arguments (including py::args and/or py::kwargs, if present) - std::uint16_t nargs; + std::uint16_t nargs = 0; /// Number of trailing arguments (counted in `nargs`) that are keyword-only std::uint16_t nargs_kw_only = 0; diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 5578c65160..1470687867 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -104,9 +104,9 @@ struct internals { std::unordered_map shared_data; // Custom data to be shared across extensions std::vector loader_patient_stack; // Used by `loader_life_support` std::forward_list static_strings; // Stores the std::strings backing detail::c_str() - PyTypeObject *static_property_type; - PyTypeObject *default_metaclass; - PyObject *instance_base; + PyTypeObject *static_property_type = nullptr; + PyTypeObject *default_metaclass = nullptr; + PyObject *instance_base = nullptr; #if defined(WITH_THREAD) PYBIND11_TLS_KEY_INIT(tstate); PyInterpreterState *istate = nullptr; @@ -126,9 +126,9 @@ struct internals { /// Additional type information which does not fit into the PyTypeObject. /// Changes to this struct also require bumping `PYBIND11_INTERNALS_VERSION`. struct type_info { - PyTypeObject *type; - const std::type_info *cpptype; - size_t type_size, type_align, holder_size_in_ptrs; + PyTypeObject *type = nullptr; + const std::type_info *cpptype = nullptr; + size_t type_size = 0, type_align = 0, holder_size_in_ptrs = 0; void *(*operator_new)(size_t); void (*init_instance)(instance *, const void *); void (*dealloc)(value_and_holder &v_h); diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index aee9be4e45..baa91e9562 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -65,6 +65,9 @@ struct type_caster> { function f; func_handle(function&& f_) : f(std::move(f_)) {} func_handle(const func_handle& f_) { + operator=(f_); + } + void operator=(const func_handle &f_) & { gil_scoped_acquire acq; f = f_.f; }