Skip to content

Commit 7cae21f

Browse files
committed
Change macro name to PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
1 parent f4ad02b commit 7cae21f

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ jobs:
8888
# Extra ubuntu latest job
8989
- runs-on: ubuntu-latest
9090
python: '3.11'
91-
# Exercise PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
91+
# Run tests with py::smart_holder as the default holder
9292
# with recent (or ideally latest) released Python version.
9393
- runs-on: ubuntu-latest
9494
python: '3.12'
9595
args: >
96-
-DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
96+
-DCMAKE_CXX_FLAGS="-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE"
9797
- runs-on: macos-13
9898
python: '3.12'
9999
args: >
100-
-DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
100+
-DCMAKE_CXX_FLAGS="-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE"
101101
- runs-on: windows-2022
102102
python: '3.12'
103103
args: >
104-
-DCMAKE_CXX_FLAGS="/DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT /GR /EHsc"
104+
-DCMAKE_CXX_FLAGS="/DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE /GR /EHsc"
105105
exclude:
106106
# The setup-python action currently doesn't have graalpy for windows
107107
- python: 'graalpy-24.1'

include/pybind11/pybind11.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,14 +1839,13 @@ struct property_cpp_function<
18391839
detail::both_t_and_d_use_type_caster_base<T, typename D::element_type>>::value>>
18401840
: detail::property_cpp_function_sh_unique_ptr_member<T, D> {};
18411841

1842-
#if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT)
1843-
// NOTE: THIS IS MEANT FOR STRESS-TESTING ONLY!
1844-
// As of PR #5257, for production use, there is no longer a strong reason to make
1845-
// smart_holder the default holder:
1846-
// Simply use `py::classh` (see below) instead of `py::class_` as needed.
1842+
#ifdef PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
1843+
// NOTE: THIS IS MEANT FOR STRESS-TESTING OR TRIAGING ONLY!
18471844
// Running the pybind11 unit tests with smart_holder as the default holder is to ensure
18481845
// that `py::smart_holder` / `py::classh` is backward-compatible with all pre-existing
18491846
// functionality.
1847+
// Be careful not to link translation units compiled with different default holders, because
1848+
// this will cause ODR violations (https://en.wikipedia.org/wiki/One_Definition_Rule).
18501849
template <typename>
18511850
using default_holder_type = smart_holder;
18521851
#else

tests/test_class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ CHECK_NOALIAS(8);
632632
CHECK_HOLDER(1, unique);
633633
CHECK_HOLDER(2, unique);
634634
CHECK_HOLDER(3, unique);
635-
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
635+
#ifndef PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
636636
CHECK_HOLDER(4, unique);
637637
CHECK_HOLDER(5, unique);
638638
#endif

0 commit comments

Comments
 (0)