From e88737b2091cd129a993c826ceaa09f230ae054a Mon Sep 17 00:00:00 2001 From: cyy Date: Thu, 1 Jul 2021 17:42:46 +0800 Subject: [PATCH 1/3] init member --- include/pybind11/attr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 7d1d65751b77337d59ac03daa27af2455d8e155f Mon Sep 17 00:00:00 2001 From: cyy Date: Sat, 3 Jul 2021 11:01:53 +0800 Subject: [PATCH 2/3] init more members --- include/pybind11/detail/internals.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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); From 02ce52b7e4792d7351ee6d00c3613df941a31967 Mon Sep 17 00:00:00 2001 From: cyy Date: Sat, 3 Jul 2021 11:44:03 +0800 Subject: [PATCH 3/3] add copy assignment to avoid inconsistent behavior --- include/pybind11/functional.h | 3 +++ 1 file changed, 3 insertions(+) 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; }