Skip to content

Commit aed215c

Browse files
authored
[smart_holder] Remove obsolete detail::type_info::default_holder member. (#5541)
* git merge --squash purge_internals_versions_4_5 * Remove PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT, set PYBIND11_INTERNALS_VERSION 7 * Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under include/pybind11 * Remove obsolete PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT macro. * Remove PYBIND11_SMART_HOLDER_ENABLED in ubench/holder_comparison.cpp * Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under tests/ * Remove `#define PYBIND11_SMART_HOLDER_ENABLED` * Remove all uses of PYBIND11_SMART_HOLDER_TYPE_CASTERS under tests/ * Remove all uses of PYBIND11_TYPE_CASTER_BASE_HOLDER under tests/ * Add missing `#include <cstdint>` Example error message (🐍 3.11 • ubuntu-latest • x64, GNU 13.3.0): ``` include/pybind11/detail/value_and_holder.h:56:52: error: ‘uint8_t’ is not a member of ‘std’; did you mean ‘wint_t’? 56 | inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed; | ^~~~~~~ ``` * Remove type_info::default_holder member. DOES NOT BUILD * Remove some obsolete default_holder code and #ifdef out uses of typeinfo->default_holder. BUILDS BUT 2 TESTS ARE FAILING. * Replace `default_holder` with `holder_enum_v == holder_enum_t::std_unique_ptr` Intentionally not changing error messages, because this would result in a significantly bigger change. * Change PYBIND11_INTERNALS_VERSION to 106: It will be changed to 7 in a follow-on PR that actually changes the internals. * Change PYBIND11_INTERNALS_VERSION to 7 (because this PR actually changes the internals).
1 parent 5ab036b commit aed215c

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

include/pybind11/attr.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ struct function_record {
276276
struct type_record {
277277
PYBIND11_NOINLINE type_record()
278278
: multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false),
279-
default_holder(true), module_local(false), is_final(false),
280-
release_gil_before_calling_cpp_dtor(false) {}
279+
module_local(false), is_final(false), release_gil_before_calling_cpp_dtor(false) {}
281280

282281
/// Handle to the parent scope
283282
handle scope;
@@ -327,9 +326,6 @@ struct type_record {
327326
/// Does the class implement the buffer protocol?
328327
bool buffer_protocol : 1;
329328

330-
/// Is the default (unique_ptr) holder type used?
331-
bool default_holder : 1;
332-
333329
/// Is the class definition local to the module shared object?
334330
bool module_local : 1;
335331

@@ -350,13 +346,17 @@ struct type_record {
350346
+ "\" referenced unknown base type \"" + tname + "\"");
351347
}
352348

353-
if (default_holder != base_info->default_holder) {
349+
// SMART_HOLDER_BAKEIN_FOLLOW_ON: Refine holder compatibility checks.
350+
bool this_has_unique_ptr_holder = (holder_enum_v == holder_enum_t::std_unique_ptr);
351+
bool base_has_unique_ptr_holder
352+
= (base_info->holder_enum_v == holder_enum_t::std_unique_ptr);
353+
if (this_has_unique_ptr_holder != base_has_unique_ptr_holder) {
354354
std::string tname(base.name());
355355
detail::clean_type_id(tname);
356356
pybind11_fail("generic_type: type \"" + std::string(name) + "\" "
357-
+ (default_holder ? "does not have" : "has")
357+
+ (this_has_unique_ptr_holder ? "does not have" : "has")
358358
+ " a non-default holder type while its base \"" + tname + "\" "
359-
+ (base_info->default_holder ? "does not" : "does"));
359+
+ (base_has_unique_ptr_holder ? "does not" : "does"));
360360
}
361361

362362
bases.append((PyObject *) base_info->type);

include/pybind11/cast.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,10 @@ struct copyable_holder_caster : public type_caster_base<type> {
790790
protected:
791791
friend class type_caster_generic;
792792
void check_holder_compat() {
793-
if (typeinfo->default_holder) {
793+
// SMART_HOLDER_BAKEIN_FOLLOW_ON: Refine holder compatibility checks.
794+
bool inst_has_unique_ptr_holder
795+
= (typeinfo->holder_enum_v == holder_enum_t::std_unique_ptr);
796+
if (inst_has_unique_ptr_holder) {
794797
throw cast_error("Unable to load a custom holder type from a default-holder instance");
795798
}
796799
}
@@ -908,7 +911,10 @@ struct copyable_holder_caster<
908911
protected:
909912
friend class type_caster_generic;
910913
void check_holder_compat() {
911-
if (typeinfo->default_holder) {
914+
// SMART_HOLDER_BAKEIN_FOLLOW_ON: Refine holder compatibility checks.
915+
bool inst_has_unique_ptr_holder
916+
= (typeinfo->holder_enum_v == holder_enum_t::std_unique_ptr);
917+
if (inst_has_unique_ptr_holder) {
912918
throw cast_error("Unable to load a custom holder type from a default-holder instance");
913919
}
914920
}

include/pybind11/detail/internals.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
/// further ABI-incompatible changes may be made before the ABI is officially
3838
/// changed to the new version.
3939
#ifndef PYBIND11_INTERNALS_VERSION
40-
# define PYBIND11_INTERNALS_VERSION 106
40+
# define PYBIND11_INTERNALS_VERSION 7
4141
#endif
4242

43-
#if PYBIND11_INTERNALS_VERSION < 106
44-
# error "PYBIND11_INTERNALS_VERSION 106 is the minimum (SPECIAL SITUATION)."
43+
#if PYBIND11_INTERNALS_VERSION < 7
44+
# error "PYBIND11_INTERNALS_VERSION 7 is the minimum for all platforms for pybind11v3."
4545
#endif
4646

4747
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
@@ -234,20 +234,16 @@ struct type_info {
234234
buffer_info *(*get_buffer)(PyObject *, void *) = nullptr;
235235
void *get_buffer_data = nullptr;
236236
void *(*module_local_load)(PyObject *, const type_info *) = nullptr;
237+
holder_enum_t holder_enum_v = holder_enum_t::undefined;
237238
/* A simple type never occurs as a (direct or indirect) parent
238239
* of a class that makes use of multiple inheritance.
239240
* A type can be simple even if it has non-simple ancestors as long as it has no descendants.
240241
*/
241242
bool simple_type : 1;
242243
/* True if there is no multiple inheritance in this type's inheritance tree */
243244
bool simple_ancestors : 1;
244-
/* for base vs derived holder_type checks */
245-
// SMART_HOLDER_BAKEIN_FOLLOW_ON: Remove default_holder member here and
246-
// produce better error messages in the places where it is currently used.
247-
bool default_holder : 1;
248245
/* true if this is a type registered with py::module_local */
249246
bool module_local : 1;
250-
holder_enum_t holder_enum_v = holder_enum_t::undefined;
251247
};
252248

253249
#define PYBIND11_INTERNALS_ID \

include/pybind11/pybind11.h

-4
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,6 @@ class generic_type : public object {
14461446
tinfo->dealloc = rec.dealloc;
14471447
tinfo->simple_type = true;
14481448
tinfo->simple_ancestors = true;
1449-
tinfo->default_holder = rec.default_holder;
14501449
tinfo->module_local = rec.module_local;
14511450
tinfo->holder_enum_v = rec.holder_enum_v;
14521451

@@ -1903,9 +1902,6 @@ class class_ : public detail::generic_type {
19031902
record.holder_size = sizeof(holder_type);
19041903
record.init_instance = init_instance;
19051904

1906-
// A more fitting name would be uses_unique_ptr_holder.
1907-
record.default_holder = detail::is_instantiation<std::unique_ptr, holder_type>::value;
1908-
19091905
if (detail::is_instantiation<std::unique_ptr, holder_type>::value) {
19101906
record.holder_enum_v = detail::holder_enum_t::std_unique_ptr;
19111907
} else if (detail::is_instantiation<std::shared_ptr, holder_type>::value) {

0 commit comments

Comments
 (0)