Skip to content

Commit 8bd68a3

Browse files
style: pre-commit fixes
1 parent 647df8b commit 8bd68a3

File tree

13 files changed

+157
-164
lines changed

13 files changed

+157
-164
lines changed

include/pybind11/cast.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class type_caster_enum_type {
9696

9797
type_caster_base<EnumType> legacy_caster;
9898
if (legacy_caster.load(src, convert)) {
99-
legacy_ptr = static_cast<EnumType*>(legacy_caster);
99+
legacy_ptr = static_cast<EnumType *>(legacy_caster);
100100
return true;
101101
}
102102
return false;
@@ -106,14 +106,13 @@ class type_caster_enum_type {
106106
using cast_op_type = detail::cast_op_type<T>;
107107

108108
// NOLINTNEXTLINE(google-explicit-constructor)
109-
operator EnumType *() {
110-
return native_loaded ? &native_value : legacy_ptr;
111-
}
109+
operator EnumType *() { return native_loaded ? &native_value : legacy_ptr; }
112110

113111
// NOLINTNEXTLINE(google-explicit-constructor)
114112
operator EnumType &() {
115-
return native_loaded ? native_value :
116-
legacy_ptr ? *legacy_ptr : throw reference_cast_error();
113+
return native_loaded ? native_value
114+
: legacy_ptr ? *legacy_ptr
115+
: throw reference_cast_error();
117116
}
118117

119118
private:

include/pybind11/detail/common.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,16 @@
276276

277277
// 3.14 Compatibility
278278
#if !defined(Py_GIL_DISABLED)
279-
inline bool is_uniquely_referenced(PyObject *obj) {
280-
return Py_REFCNT(obj) == 1;
281-
}
279+
inline bool is_uniquely_referenced(PyObject *obj) { return Py_REFCNT(obj) == 1; }
282280
#elif 0x030E0000 <= PY_VERSION_HEX
283281
inline bool is_uniquely_referenced(PyObject *obj) {
284282
return PyUnstable_Object_IsUniquelyReferenced(obj);
285283
}
286284
#else // backport for 3.13
287285
inline bool is_uniquely_referenced(PyObject *obj) {
288-
return _Py_IsOwnedByCurrentThread(obj) &&
289-
_Py_atomic_load_uint32_relaxed(&ob->ob_ref_local) == 1 &&
290-
_Py_atomic_load_ssize_relaxed(&ob->ob_ref_shared) == 0;
286+
return _Py_IsOwnedByCurrentThread(obj)
287+
&& _Py_atomic_load_uint32_relaxed(&ob->ob_ref_local) == 1
288+
&& _Py_atomic_load_ssize_relaxed(&ob->ob_ref_shared) == 0;
291289
}
292290
#endif
293291

@@ -1369,13 +1367,13 @@ constexpr
13691367
#endif
13701368

13711369
#if defined(PY_BIG_ENDIAN)
1372-
# define PYBIND11_BIG_ENDIAN PY_BIG_ENDIAN
1370+
# define PYBIND11_BIG_ENDIAN PY_BIG_ENDIAN
13731371
#else // pypy doesn't define PY_BIG_ENDIAN
1374-
# if defined(_MSC_VER)
1375-
# define PYBIND11_BIG_ENDIAN 0 // All Windows platforms are little-endian
1376-
# else // GCC and Clang define the following macros
1377-
# define PYBIND11_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
1378-
# endif
1372+
# if defined(_MSC_VER)
1373+
# define PYBIND11_BIG_ENDIAN 0 // All Windows platforms are little-endian
1374+
# else // GCC and Clang define the following macros
1375+
# define PYBIND11_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
1376+
# endif
13791377
#endif
13801378

13811379
PYBIND11_NAMESPACE_END(detail)

include/pybind11/detail/foreign.h

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ inline bool should_autoimport_foreign(interop_internals &interop_internals,
3737

3838
// Determine whether a pybind11 type is module-local from a different module
3939
inline bool is_local_to_other_module(type_info *ti) {
40-
return ti->module_local_load != nullptr &&
41-
ti->module_local_load != &type_caster_generic::local_load;
40+
return ti->module_local_load != nullptr
41+
&& ti->module_local_load != &type_caster_generic::local_load;
4242
}
4343

4444
// Add the given `binding` to our type maps so that we can use it to satisfy
@@ -73,8 +73,8 @@ inline void *interop_cb_from_python(pymb_binding *binding,
7373
return nullptr;
7474
}
7575
try {
76-
auto cap = reinterpret_borrow<capsule>(
77-
pytype.attr(native_enum_info::attribute_name()));
76+
auto cap
77+
= reinterpret_borrow<capsule>(pytype.attr(native_enum_info::attribute_name()));
7878
auto *info = cap.get_pointer<native_enum_info>();
7979
auto value = handle(pyobj).attr("value");
8080
uint64_t ival;
@@ -83,8 +83,8 @@ inline void *interop_cb_from_python(pymb_binding *binding,
8383
} else {
8484
ival = cast<uint64_t>(value);
8585
}
86-
bytes holder{reinterpret_cast<const char *>(&ival) +
87-
PYBIND11_BIG_ENDIAN * (8 - info->size_bytes),
86+
bytes holder{reinterpret_cast<const char *>(&ival)
87+
+ PYBIND11_BIG_ENDIAN * (8 - info->size_bytes),
8888
info->size_bytes};
8989
keep_referenced(keep_referenced_ctx, holder.ptr());
9090
return PyBytes_AsString(holder.ptr());
@@ -124,7 +124,8 @@ inline void *interop_cb_from_python(pymb_binding *binding,
124124
type_caster_generic caster{static_cast<const type_info *>(binding->context)};
125125
void *ret = nullptr;
126126
try {
127-
if (caster.load_impl<type_caster_generic>(pyobj, convert != 0,
127+
if (caster.load_impl<type_caster_generic>(pyobj,
128+
convert != 0,
128129
/* foreign_ok */ false)) {
129130
ret = caster.value;
130131
}
@@ -163,15 +164,15 @@ inline void init_instance_unregistered(instance *inst, const void *holder) {
163164

164165
// Undo our shenanigans even if init_instance raises an exception
165166
struct guard {
166-
value_and_holder& v_h;
167+
value_and_holder &v_h;
167168
~guard() noexcept {
168169
v_h.set_instance_registered(false);
169170
if (v_h.type->holder_enum_v == holder_enum_t::smart_holder) {
170171
v_h.inst->owned = false;
171172
auto &h = v_h.holder<smart_holder>();
172173
h.vptr_is_using_std_default_delete = true;
173-
h.reset_vptr_deleter_armed_flag(
174-
v_h.type->get_memory_guarded_delete, /* armed_flag */ false);
174+
h.reset_vptr_deleter_armed_flag(v_h.type->get_memory_guarded_delete,
175+
/* armed_flag */ false);
175176
}
176177
}
177178
} guard{v_h};
@@ -183,7 +184,7 @@ inline PyObject *interop_cb_to_python(pymb_binding *binding,
183184
enum pymb_rv_policy rvp_,
184185
pymb_to_python_feedback *feedback) noexcept {
185186
feedback->relocate = 0; // we don't support relocation
186-
feedback->is_new = 0; // unless overridden below
187+
feedback->is_new = 0; // unless overridden below
187188

188189
if (cobj == nullptr) {
189190
return none().release().ptr();
@@ -193,16 +194,25 @@ inline PyObject *interop_cb_to_python(pymb_binding *binding,
193194
// Native enum type
194195
try {
195196
handle pytype((PyObject *) binding->pytype);
196-
auto cap = reinterpret_borrow<capsule>(
197-
pytype.attr(native_enum_info::attribute_name()));
197+
auto cap
198+
= reinterpret_borrow<capsule>(pytype.attr(native_enum_info::attribute_name()));
198199
auto *info = cap.get_pointer<native_enum_info>();
199200
uint64_t key;
200201
switch (info->size_bytes) {
201-
case 1: key = *(uint8_t *) cobj; break;
202-
case 2: key = *(uint16_t *) cobj; break;
203-
case 4: key = *(uint32_t *) cobj; break;
204-
case 8: key = *(uint64_t *) cobj; break;
205-
default: return nullptr;
202+
case 1:
203+
key = *(uint8_t *) cobj;
204+
break;
205+
case 2:
206+
key = *(uint16_t *) cobj;
207+
break;
208+
case 4:
209+
key = *(uint32_t *) cobj;
210+
break;
211+
case 8:
212+
key = *(uint64_t *) cobj;
213+
break;
214+
default:
215+
return nullptr;
206216
}
207217
if (rvp_ == pymb_rv_policy_take_ownership)
208218
::operator delete(cobj);
@@ -216,7 +226,7 @@ inline PyObject *interop_cb_to_python(pymb_binding *binding,
216226
return pytype(ikey).release().ptr();
217227
}
218228
return pytype(key).release().ptr();
219-
} catch (error_already_set& exc) {
229+
} catch (error_already_set &exc) {
220230
exc.restore();
221231
return nullptr;
222232
}
@@ -293,21 +303,21 @@ inline int interop_cb_keep_alive(PyObject *nurse, void *payload, void (*cb)(void
293303
}
294304
auto cb_to_use = cb ? cb : (decltype(cb)) Py_DecRef;
295305
bool success = false;
296-
if (v_h.type->holder_enum_v == holder_enum_t::std_shared_ptr &&
297-
!v_h.holder_constructed()) {
306+
if (v_h.type->holder_enum_v == holder_enum_t::std_shared_ptr
307+
&& !v_h.holder_constructed()) {
298308
// Create a shared_ptr whose destruction will perform the action
299309
std::shared_ptr<void> owner(payload, cb_to_use);
300310
// Use the aliasing constructor to make its get() return the right thing
301-
new (std::addressof(v_h.holder<std::shared_ptr<void>>())) std::shared_ptr<void>(
302-
std::move(owner), v_h.value_ptr());
311+
new (std::addressof(v_h.holder<std::shared_ptr<void>>()))
312+
std::shared_ptr<void>(std::move(owner), v_h.value_ptr());
303313
v_h.set_holder_constructed();
304314
success = true;
305-
} else if (v_h.type->holder_enum_v == holder_enum_t::smart_holder &&
306-
v_h.holder_constructed() && !v_h.inst->owned) {
315+
} else if (v_h.type->holder_enum_v == holder_enum_t::smart_holder
316+
&& v_h.holder_constructed() && !v_h.inst->owned) {
307317
auto &h = v_h.holder<smart_holder>();
308318
auto *gd = v_h.type->get_memory_guarded_delete(h.vptr);
309319
if (gd && !gd->armed_flag) {
310-
gd->del_fun = [=](void*) { cb_to_use(payload); };
320+
gd->del_fun = [=](void *) { cb_to_use(payload); };
311321
gd->use_del_fun = true;
312322
gd->armed_flag = true;
313323
success = true;
@@ -553,9 +563,8 @@ PYBIND11_NOINLINE void import_for_interop(handle pytype, const std::type_info *c
553563
// they're already locked
554564
auto &internals = get_internals();
555565
auto it = internals.registered_types_py.find(binding->pytype);
556-
if (it != internals.registered_types_py.end() &&
557-
it->second.size() == 1 &&
558-
is_local_to_other_module(*it->second.begin())) {
566+
if (it != internals.registered_types_py.end() && it->second.size() == 1
567+
&& is_local_to_other_module(*it->second.begin())) {
559568
// Allow importing module-local types from other pybind11 modules,
560569
// even if they're ABI-compatible with us and thus use the same
561570
// pymb_framework. The import is not doing much here; the export
@@ -628,14 +637,13 @@ PYBIND11_NOINLINE void interop_enable_import_all() {
628637
// type object. `ti` may be nullptr if exporting a native enum.
629638
// Caller must hold the internals lock and have already called
630639
// interop_internals.initialize_if_needed().
631-
PYBIND11_NOINLINE void export_for_interop(const std::type_info *cpptype,
632-
PyTypeObject *pytype,
633-
type_info *ti) {
640+
PYBIND11_NOINLINE void
641+
export_for_interop(const std::type_info *cpptype, PyTypeObject *pytype, type_info *ti) {
634642
auto &interop_internals = get_interop_internals();
635643
auto range = interop_internals.bindings.equal_range(*cpptype);
636644
for (auto it = range.first; it != range.second; ++it) {
637-
if (it->second->framework == interop_internals.self.get() &&
638-
it->second->pytype == pytype) {
645+
if (it->second->framework == interop_internals.self.get()
646+
&& it->second->pytype == pytype) {
639647
return; // already exported
640648
}
641649
}
@@ -678,10 +686,8 @@ PYBIND11_NOINLINE void interop_enable_export_all() {
678686
auto cap = reinterpret_borrow<capsule>(
679687
handle(entry.second).attr(native_enum_info::attribute_name()));
680688
auto *info = cap.get_pointer<native_enum_info>();
681-
detail::export_for_interop(info->cpptype,
682-
(PyTypeObject *) entry.second,
683-
nullptr);
684-
} catch (error_already_set&) {
689+
detail::export_for_interop(info->cpptype, (PyTypeObject *) entry.second, nullptr);
690+
} catch (error_already_set &) {
685691
// Ignore native enums without a __pybind11_enum__ capsule;
686692
// they might be from an older version of pybind11
687693
}
@@ -707,9 +713,9 @@ PYBIND11_NOINLINE void *try_foreign_bindings(const std::type_info *type,
707713
auto it = range.first;
708714
for (; it != range.second; ++it) {
709715
auto *binding = it->second;
710-
if (binding->framework == interop_internals.self.get() &&
711-
(!binding->context ||
712-
!is_local_to_other_module((type_info *) binding->context))) {
716+
if (binding->framework == interop_internals.self.get()
717+
&& (!binding->context
718+
|| !is_local_to_other_module((type_info *) binding->context))) {
713719
// Don't try to use our own types, unless they're module-local
714720
// to some other module and this is the only way we'd see them.
715721
// (The module-local escape hatch is only relevant for
@@ -779,31 +785,28 @@ inline void export_for_interop(handle ty) {
779785
interop_internals.initialize_if_needed();
780786
detail::type_info *ti = detail::get_type_info((PyTypeObject *) ty.ptr());
781787
if (ti) {
782-
detail::with_internals([&](detail::internals &) {
783-
detail::export_for_interop(ti->cpptype, ti->type, ti);
784-
});
788+
detail::with_internals(
789+
[&](detail::internals &) { detail::export_for_interop(ti->cpptype, ti->type, ti); });
785790
return;
786791
}
787792
// Not a class_; maybe it's a native_enum?
788793
try {
789-
auto cap = reinterpret_borrow<capsule>(
790-
ty.attr(detail::native_enum_info::attribute_name()));
794+
auto cap
795+
= reinterpret_borrow<capsule>(ty.attr(detail::native_enum_info::attribute_name()));
791796
auto *info = cap.get_pointer<detail::native_enum_info>();
792797
bool ours = detail::with_internals([&](detail::internals &internals) {
793798
auto it = internals.native_enum_type_map.find(*info->cpptype);
794-
if (it != internals.native_enum_type_map.end() &&
795-
it->second == ty.ptr()) {
796-
detail::export_for_interop(info->cpptype,
797-
(PyTypeObject *) ty.ptr(),
798-
nullptr);
799+
if (it != internals.native_enum_type_map.end() && it->second == ty.ptr()) {
800+
detail::export_for_interop(info->cpptype, (PyTypeObject *) ty.ptr(), nullptr);
799801
return true;
800802
}
801803
return false;
802804
});
803805
if (ours) {
804806
return;
805807
}
806-
} catch (error_already_set&) {}
808+
} catch (error_already_set &) {
809+
}
807810
pybind11_fail("pybind11::export_for_interop: not a "
808811
"pybind11 class or enum bound in this domain");
809812
}

include/pybind11/detail/native_enum_data.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ class native_enum_data {
3333
enum_type_index{*enum_info_.cpptype}, parent_scope(parent_scope), enum_name{enum_name},
3434
native_type_name{native_type_name}, class_doc(class_doc), export_values_flag{false},
3535
finalize_needed{false} {
36-
enum_info = capsule(new native_enum_info{enum_info_},
37-
native_enum_info::attribute_name(),
38-
+[](void *enum_info_) {
39-
auto *info = (native_enum_info *) enum_info_;
40-
with_internals([&](internals &internals) {
41-
internals.native_enum_type_map.erase(*info->cpptype);
42-
});
43-
delete info;
44-
});
36+
enum_info = capsule(
37+
new native_enum_info{enum_info_},
38+
native_enum_info::attribute_name(),
39+
+[](void *enum_info_) {
40+
auto *info = (native_enum_info *) enum_info_;
41+
with_internals([&](internals &internals) {
42+
internals.native_enum_type_map.erase(*info->cpptype);
43+
});
44+
delete info;
45+
});
4546
}
4647

4748
void finalize();

0 commit comments

Comments
 (0)