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