@@ -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
3939inline 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}
0 commit comments