Skip to content

Commit 5ed381d

Browse files
authored
Replace all SMART_HOLDER_WIP comments with reminders, notes, or pointers. (#5336)
The SMART_HOLDER_WIP comments are mostly from 2021. In the meantime, the smart_holder code was extremely thoroughly tested in the Google codebase (production code). Additionally, testing via PyCLIF-pybind11 provided thousands of diverse use cases that needed to satisfy many million unit tests (the success rate was about 99.999%).
1 parent 04d9f84 commit 5ed381d

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

include/pybind11/detail/struct_smart_holder.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct smart_holder {
215215
// race conditions, but in the context of Python it is a bug (elsewhere)
216216
// if the Global Interpreter Lock (GIL) is not being held when this code
217217
// is reached.
218-
// SMART_HOLDER_WIP: IMPROVABLE: assert(GIL is held).
218+
// PYBIND11:REMINDER: This may need to be protected by a mutex in free-threaded Python.
219219
if (vptr.use_count() != 1) {
220220
throw std::invalid_argument(std::string("Cannot disown use_count != 1 (") + context
221221
+ ").");
@@ -277,29 +277,32 @@ struct smart_holder {
277277
return hld;
278278
}
279279

280-
// Caller is responsible for ensuring preconditions (SMART_HOLDER_WIP: details).
280+
// Caller is responsible for ensuring the complex preconditions
281+
// (see `smart_holder_type_caster_support::load_helper`).
281282
void disown() {
282283
reset_vptr_deleter_armed_flag(false);
283284
is_disowned = true;
284285
}
285286

286-
// Caller is responsible for ensuring preconditions (SMART_HOLDER_WIP: details).
287+
// Caller is responsible for ensuring the complex preconditions
288+
// (see `smart_holder_type_caster_support::load_helper`).
287289
void reclaim_disowned() {
288290
reset_vptr_deleter_armed_flag(true);
289291
is_disowned = false;
290292
}
291293

292-
// Caller is responsible for ensuring preconditions (SMART_HOLDER_WIP: details).
294+
// Caller is responsible for ensuring the complex preconditions
295+
// (see `smart_holder_type_caster_support::load_helper`).
293296
void release_disowned() { vptr.reset(); }
294297

295-
// SMART_HOLDER_WIP: review this function.
296298
void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") const {
297299
ensure_is_not_disowned(context);
298300
ensure_vptr_is_using_builtin_delete(context);
299301
ensure_use_count_1(context);
300302
}
301303

302-
// Caller is responsible for ensuring preconditions (SMART_HOLDER_WIP: details).
304+
// Caller is responsible for ensuring the complex preconditions
305+
// (see `smart_holder_type_caster_support::load_helper`).
303306
void release_ownership() {
304307
reset_vptr_deleter_armed_flag(false);
305308
release_disowned();

include/pybind11/detail/type_caster_base.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ inline PyObject *make_new_instance(PyTypeObject *type);
475475

476476
#ifdef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT
477477

478-
// SMART_HOLDER_WIP: Needs refactoring of existing pybind11 code.
478+
// PYBIND11:REMINDER: Needs refactoring of existing pybind11 code.
479479
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo);
480480

481481
PYBIND11_NAMESPACE_BEGIN(smart_holder_type_caster_support)
@@ -568,8 +568,7 @@ handle smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&src,
568568

569569
if (static_cast<void *>(src.get()) == src_raw_void_ptr) {
570570
// This is a multiple-inheritance situation that is incompatible with the current
571-
// shared_from_this handling (see PR #3023).
572-
// SMART_HOLDER_WIP: IMPROVABLE: Is there a better solution?
571+
// shared_from_this handling (see PR #3023). Is there a better solution?
573572
src_raw_void_ptr = nullptr;
574573
}
575574
auto smhldr = smart_holder::from_unique_ptr(std::move(src), src_raw_void_ptr);
@@ -623,8 +622,8 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr<T> &src,
623622
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
624623
const detail::type_info *tinfo = st.second;
625624
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) {
626-
// SMART_HOLDER_WIP: MISSING: Enforcement of consistency with existing smart_holder.
627-
// SMART_HOLDER_WIP: MISSING: keep_alive.
625+
// PYBIND11:REMINDER: MISSING: Enforcement of consistency with existing smart_holder.
626+
// PYBIND11:REMINDER: MISSING: keep_alive.
628627
return existing_inst;
629628
}
630629

include/pybind11/trampoline_self_life_support.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1616

1717
PYBIND11_NAMESPACE_BEGIN(detail)
18-
// SMART_HOLDER_WIP: Needs refactoring of existing pybind11 code.
18+
// PYBIND11:REMINDER: Needs refactoring of existing pybind11 code.
1919
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo);
2020
PYBIND11_NAMESPACE_END(detail)
2121

2222
// The original core idea for this struct goes back to PyCLIF:
2323
// https://github.com/google/clif/blob/07f95d7e69dca2fcf7022978a55ef3acff506c19/clif/python/runtime.cc#L37
24-
// URL provided here mainly to give proper credit. To fully explain the `HoldPyObj` feature, more
25-
// context is needed (SMART_HOLDER_WIP).
24+
// URL provided here mainly to give proper credit.
2625
struct trampoline_self_life_support {
2726
detail::value_and_holder v_h;
2827

tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_shared_ptr_arg_identity():
6262
del obj
6363
pytest.gc_collect()
6464

65-
# SMART_HOLDER_WIP: the behavior below is DIFFERENT from PR #2839
65+
# NOTE: the behavior below is DIFFERENT from PR #2839
6666
# python reference is gone because it is not an Alias instance
6767
assert objref() is None
6868
assert tester.has_python_instance() is False

0 commit comments

Comments
 (0)