26
26
#include < typeinfo>
27
27
#include < utility>
28
28
29
- #ifdef JUNK
30
- # include < iostream>
31
- inline void to_cout (std::string msg) { std::cout << msg << std::endl; }
32
- #endif
33
-
34
29
PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
35
30
36
31
using pybindit::memory::smart_holder;
@@ -278,7 +273,6 @@ struct smart_holder_type_caster_class_hooks : smart_holder_type_caster_base_tag
278
273
return false ;
279
274
}
280
275
281
- #ifdef JUNK
282
276
template <typename WrappedType, typename AnyBaseOfWrappedType>
283
277
static bool try_initialization_using_shared_from_this (
284
278
holder_type *uninitialized_location,
@@ -292,7 +286,6 @@ struct smart_holder_type_caster_class_hooks : smart_holder_type_caster_base_tag
292
286
new (uninitialized_location) holder_type (holder_type::from_shared_ptr (shd_ptr));
293
287
return true ;
294
288
}
295
- #endif
296
289
297
290
template <typename WrappedType, typename AliasType>
298
291
static void init_instance_for_type (detail::instance *inst, const void *holder_const_void_ptr) {
@@ -305,26 +298,26 @@ struct smart_holder_type_caster_class_hooks : smart_holder_type_caster_base_tag
305
298
register_instance (inst, v_h.value_ptr (), v_h.type );
306
299
v_h.set_instance_registered ();
307
300
}
301
+ auto uninitialized_location = std::addressof (v_h.holder <holder_type>());
302
+ auto value_ptr_w_t = v_h.value_ptr <WrappedType>();
308
303
if (holder_void_ptr) {
309
304
// Note: inst->owned ignored.
310
305
auto holder_ptr = static_cast <holder_type *>(holder_void_ptr);
311
- new (std::addressof (v_h. holder <holder_type>()) ) holder_type (std::move (*holder_ptr));
306
+ new (uninitialized_location ) holder_type (std::move (*holder_ptr));
312
307
} else {
313
308
if (!try_initialization_using_shared_from_this (
314
- std::addressof (v_h.holder <holder_type>()),
315
- v_h.value_ptr <WrappedType>(),
316
- v_h.value_ptr <WrappedType>())) {
309
+ uninitialized_location, value_ptr_w_t , value_ptr_w_t )) {
317
310
if (inst->owned ) {
318
- new (std::addressof (v_h. holder <holder_type>())) holder_type (
319
- holder_type::from_raw_ptr_take_ownership (v_h. value_ptr <WrappedType>() ));
311
+ new (uninitialized_location)
312
+ holder_type ( holder_type ::from_raw_ptr_take_ownership (value_ptr_w_t ));
320
313
} else {
321
- new (std::addressof (v_h. holder <holder_type>())) holder_type (
322
- holder_type::from_raw_ptr_unowned (v_h. value_ptr <WrappedType>() ));
314
+ new (uninitialized_location)
315
+ holder_type ( holder_type ::from_raw_ptr_unowned (value_ptr_w_t ));
323
316
}
324
317
}
325
318
}
326
319
v_h.holder <holder_type>().pointee_depends_on_holder_owner
327
- = dynamic_raw_ptr_cast_if_possible<AliasType>(v_h. value_ptr <WrappedType>() ) != nullptr ;
320
+ = dynamic_raw_ptr_cast_if_possible<AliasType>(value_ptr_w_t ) != nullptr ;
328
321
v_h.set_holder_constructed ();
329
322
}
330
323
@@ -394,20 +387,14 @@ struct smart_holder_type_caster_load {
394
387
auto type_raw_ptr = convert_type (void_raw_ptr);
395
388
if (holder ().pointee_depends_on_holder_owner ) {
396
389
// Tie lifetime of trampoline Python part to C++ part (PR #2839).
397
- #ifdef JUNK
398
- to_cout (" " );
399
- to_cout (" LOOOK " + std::to_string (__LINE__) + " " + __FILE__);
400
- #endif
401
390
return std::shared_ptr<T>(
402
391
type_raw_ptr,
403
392
shared_ptr_dec_ref_deleter{
404
393
handle ((PyObject *) load_impl.loaded_v_h .inst ).inc_ref ()});
405
394
}
406
- #ifdef JUNK
407
395
if (holder ().vptr_is_using_noop_deleter ) {
408
396
throw std::runtime_error (" Non-owning holder (loaded_as_shared_ptr)." );
409
397
}
410
- #endif
411
398
std::shared_ptr<void > void_shd_ptr = holder ().template as_shared_ptr <void >();
412
399
return std::shared_ptr<T>(void_shd_ptr, type_raw_ptr);
413
400
}
0 commit comments