Skip to content

Commit 228e27f

Browse files
committed
Make clang-tidy happy
1 parent c0cbf1a commit 228e27f

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

include/pybind11/detail/internals.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class thread_specific_storage {
103103

104104
T *get() const { return reinterpret_cast<T *>(PYBIND11_TLS_GET_VALUE(key_)); }
105105

106-
operator T *() const { return get(); }
107106
T &operator*() const { return *get(); }
107+
explicit operator T *() const { return get(); }
108108
explicit operator bool() const { return get() != nullptr; }
109109

110110
void set(T *val) { PYBIND11_TLS_REPLACE_VALUE(key_, reinterpret_cast<void *>(val)); }
@@ -227,7 +227,7 @@ struct internals {
227227
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py;
228228
#ifdef Py_GIL_DISABLED
229229
std::unique_ptr<instance_map_shard[]> instance_shards; // void * -> instance*
230-
size_t instance_shards_mask;
230+
size_t instance_shards_mask = 0;
231231
#else
232232
instance_map registered_instances; // void * -> instance*
233233
#endif
@@ -251,14 +251,14 @@ struct internals {
251251

252252
type_map<PyObject *> native_enum_type_map;
253253

254-
internals() {
254+
internals()
255+
: static_property_type(make_static_property_type()),
256+
default_metaclass(make_default_metaclass()) {
255257
PyThreadState *cur_tstate = PyThreadState_Get();
256258
tstate = cur_tstate;
257259

258260
istate = cur_tstate->interp;
259261
registered_exception_translators.push_front(&translate_exception);
260-
static_property_type = make_static_property_type();
261-
default_metaclass = make_default_metaclass();
262262
#ifdef Py_GIL_DISABLED
263263
// Scale proportional to the number of cores. 2x is a heuristic to reduce contention.
264264
auto num_shards
@@ -539,19 +539,20 @@ class internals_pp_manager {
539539
dict state_dict = get_python_state_dict();
540540
auto internals_obj
541541
= reinterpret_steal<object>(dict_getitemstringref(state_dict.ptr(), holder_id_));
542+
std::unique_ptr<InternalsType> *pp;
542543
if (internals_obj) {
543544
void *raw_ptr = PyCapsule_GetPointer(internals_obj.ptr(), /*name=*/nullptr);
544545
if (!raw_ptr) {
545546
raise_from(PyExc_SystemError,
546547
"pybind11::detail::internals_pp_manager::get_pp_from_dict() FAILED");
547548
throw error_already_set();
548549
}
549-
return reinterpret_cast<std::unique_ptr<InternalsType> *>(raw_ptr);
550+
pp = reinterpret_cast<std::unique_ptr<InternalsType> *>(raw_ptr);
550551
} else {
551-
auto pp = new std::unique_ptr<InternalsType>;
552+
pp = new std::unique_ptr<InternalsType>;
552553
state_dict[holder_id_] = capsule(reinterpret_cast<void *>(pp));
553-
return pp;
554554
}
555+
return pp;
555556
}
556557

557558
char const *holder_id_ = nullptr;

include/pybind11/detail/type_caster_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class loader_life_support {
4949
/// A new patient frame is created when a function is entered
5050
loader_life_support() {
5151
auto &stack_top = get_internals().loader_life_support_tls;
52-
parent = stack_top;
52+
parent = stack_top.get();
5353
stack_top = this;
5454
}
5555

@@ -68,7 +68,7 @@ class loader_life_support {
6868
/// This can only be used inside a pybind11-bound function, either by `argument_loader`
6969
/// at argument preparation time or by `py::cast()` at execution time.
7070
PYBIND11_NOINLINE static void add_patient(handle h) {
71-
loader_life_support *frame = get_internals().loader_life_support_tls;
71+
loader_life_support *frame = get_internals().loader_life_support_tls.get();
7272
if (!frame) {
7373
// NOTE: It would be nice to include the stack frames here, as this indicates
7474
// use of pybind11::cast<> outside the normal call framework, finding such

0 commit comments

Comments
 (0)