Skip to content

[smart_holder] type_caster ODR guard #4022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 85 commits into from
Jul 21, 2022
Merged
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
c84f381
Insert type_caster_odr_guard<> (an empty struct to start with).
rwgk Jun 11, 2022
5c7e77c
Add odr_guard_registry() used in type_caster_odr_guard() default cons…
rwgk Jun 12, 2022
d1960a1
Add minimal_real_caster (from PR #3862) to test_async, test_buffers
rwgk Jun 12, 2022
5095069
VERY MESSY SNAPSHOT of WIP, this was the starting point for cl/454658…
rwgk Jun 14, 2022
9a84890
Restore original test_async, test_buffers from current smart_holder HEAD
rwgk Jun 20, 2022
c148a6b
Copy from cl/454991845 snapshot Jun 14, 5:08 PM
rwgk Jun 20, 2022
3718516
Cleanup of tests. Systematically insert `if (make_caster<T>::translat…
rwgk Jun 20, 2022
5553043
Small simplification of odr_guard_impl()
rwgk Jun 20, 2022
1522f57
WIP
rwgk Jun 21, 2022
e06518d
Add PYBIND11_SOURCE_FILE_LINE macro.
rwgk Jun 21, 2022
3a95ae1
Replace PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER with PYBIND11_TYPE_CAS…
rwgk Jun 21, 2022
24d450b
Add more PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL; r…
rwgk Jun 21, 2022
0f9bb4c
load_type fixes & follow-on cleanup
rwgk Jun 21, 2022
b8876ac
Strip ./ from source_file_line
rwgk Jun 21, 2022
ca5708a
Add new tests to CMakeLists.txt, disable PYBIND11_WERROR
rwgk Jun 21, 2022
a598fe6
Replace C++17 syntax. Compiles with Debian clang 13 C++11 mode, but f…
rwgk Jun 21, 2022
0feb0be
Show C++ version along with ODR VIOLATION DETECTED message.
rwgk Jun 21, 2022
47c4e79
Add source_file_line_basename()
rwgk Jun 21, 2022
d390918
Introduce PYBIND11_TYPE_CASTER_ODR_GUARD_ON (but not set automatically).
rwgk Jun 21, 2022
e515940
Minor cleanup.
rwgk Jun 21, 2022
15db5e5
Set PYBIND11_TYPE_CASTER_ODR_GUARD_ON automatically.
rwgk Jun 21, 2022
a8144d9
Resolve clang-tidy error.
rwgk Jun 21, 2022
1bf2577
Compatibility with old compilers.
rwgk Jun 21, 2022
cfd98a7
Fix off-by-one in source_file_line_basename()
rwgk Jun 22, 2022
502f3cb
Report PYBIND11_INTERNALS_ID & C++ Version from pytest_configure()
rwgk Jun 22, 2022
369a390
Restore use of PYBIND11_WERROR
rwgk Jun 22, 2022
a34771a
Move cpp_version_in_use() from cast.h to pybind11_tests.cpp
rwgk Jun 22, 2022
6a6eb6c
define PYBIND11_DETAIL_ODR_GUARD_IMPL_THROW_DISABLED true in test_odr…
rwgk Jun 22, 2022
ed4b50b
IWYU cleanup of detail/type_caster_odr_guard.h
rwgk Jun 22, 2022
3d064fc
Replace `throw err;` to resolve clang-tidy error.
rwgk Jun 22, 2022
590171e
Add new header filename to CMakeLists.txt, test_files.py
rwgk Jun 22, 2022
5aaf96a
Experiment: Try any C++17 compiler.
rwgk Jun 22, 2022
5d45055
Fix ifdef for pragma GCC diagnostic.
rwgk Jun 22, 2022
1acc9d0
type_caster_odr_guard_impl() cleanup
rwgk Jun 22, 2022
2e6e833
Move type_caster_odr_guard to type_caster_odr_guard.h
rwgk Jun 22, 2022
61a0bb8
Rename test_odr_guard* to test_type_caster_odr_guard*
rwgk Jun 22, 2022
ec8b8b6
Remove comments that are (now) more distracting than helpful.
rwgk Jun 22, 2022
21fc6b3
Mark tu_local_no_data_always_false operator bool as explicit (clang-t…
rwgk Jun 22, 2022
d2bafae
New PYBIND11_TYPE_CASTER_ODR_GUARD_STRICT option (current on by defau…
rwgk Jun 22, 2022
1263ce9
Add test_type_caster_odr_registry_values(), test_type_caster_odr_viol…
rwgk Jun 22, 2022
262998b
Report UNEXPECTED: test_type_caster_odr_guard_2.cpp prevailed (but do…
rwgk Jun 22, 2022
3cc2c9c
Apply clang-tidy suggestion.
rwgk Jun 22, 2022
b10fc2e
Attempt to handle valgrind behavior.
rwgk Jun 22, 2022
5737b37
Another attempt to handle valgrind behavior.
rwgk Jun 22, 2022
0c0f322
Yet another attempt to handle valgrind behavior.
rwgk Jun 22, 2022
0d2bf26
Trying a new direction: show compiler info & std for UNEXPECTED: type…
rwgk Jun 23, 2022
491c2c7
compiler_info MSVC fix. num_violations == 0 condition.
rwgk Jun 23, 2022
d8280df
assert pybind11_tests.compiler_info is not None
rwgk Jun 23, 2022
4e13032
Introduce `make_caster_intrinsic<T>`, to be able to undo the 2 change…
rwgk Jun 25, 2022
3fc4833
Add test for stl.h / stl_bind.h mix.
rwgk Jun 26, 2022
3ea3700
Eliminate need for `PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UN…
rwgk Jun 28, 2022
11e858d
tu_local_descr with src_loc experiment
rwgk Jun 28, 2022
4b6d3b8
clang-tidy suggested fixes
rwgk Jun 28, 2022
37e583b
Use source_file_line_from_sloc in type_caster_odr_guard_registry
rwgk Jun 29, 2022
9ba32bd
Disable type_caster ODR guard for __INTEL_COMPILER (see comment). Als…
rwgk Jun 29, 2022
38c2565
Add missing include (discovered via google-internal testing).
rwgk Jul 1, 2022
44966da
Work `scr_loc` into `descr`
rwgk Jul 1, 2022
68b155a
Use `TypeCasterType::name.sloc` instead of `source_file_line.sloc`
rwgk Jul 1, 2022
11adace
Fix small oversight (src_loc::here() -> src_loc{nullptr, 0}).
rwgk Jul 1, 2022
ae38889
Remove PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL macr…
rwgk Jul 2, 2022
13076e4
Remove PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE macro completely. Some s…
rwgk Jul 2, 2022
70f645f
Merge branch 'smart_holder' into odr_guard_sh
rwgk Jul 10, 2022
75c6598
Minor tweaks looking at the PR with a fresh eye.
rwgk Jul 11, 2022
bd0dbd7
src_loc comments
rwgk Jul 11, 2022
2a14ee6
Add new test_descr_src_loc & and fix descr.h `concat()` `src_loc` bug…
rwgk Jul 11, 2022
38688ec
Some more work on source code comments.
rwgk Jul 12, 2022
4dabffc
Merge branch 'smart_holder' into odr_guard_sh
rwgk Jul 14, 2022
02ac969
Fully document the ODR violations in the ODR guard itself and introdu…
rwgk Jul 14, 2022
671c2ce
Update comment (incl. mention of deadsnakes known to not work as inte…
rwgk Jul 14, 2022
696b80a
Use no-destructor idiom for type_caster_odr_guard_registry, as sugges…
rwgk Jul 15, 2022
5168116
Fix clang-tidy error: 'auto reg' can be declared as 'auto *reg' [read…
rwgk Jul 15, 2022
31e8ac5
WIP
rwgk Jul 18, 2022
09b027b
Revert "WIP" (tu_local_no_data_always_false_base experiment).
rwgk Jul 20, 2022
acd5a8e
Change `PYBIND11_TYPE_CASTER_ODR_GUARD_ON` to `PYBIND11_ENABLE_TYPE_C…
rwgk Jul 20, 2022
a30c4be
Improved `#if` determining `PYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD`, b…
rwgk Jul 20, 2022
ba5c623
Make `descr::sloc` `const`, as suggested by @rainwoodman
rwgk Jul 20, 2022
f5b0946
Rename macro to `PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_DEBUG`, a…
rwgk Jul 20, 2022
fd5a298
Tweak comments some more (add "white hat hacker" analogy).
rwgk Jul 20, 2022
6182137
Bring back `PYBIND11_CPP17` in determining `PYBIND11_ENABLE_TYPE_CAST…
rwgk Jul 20, 2022
95ff3d2
Try another workaround for `__has_builtin`-related breakages (https:/…
rwgk Jul 20, 2022
0c27340
Remove `defined(__has_builtin)` and subconditions.
rwgk Jul 20, 2022
f930544
Update "known to not work" expectation in test and comment.
rwgk Jul 20, 2022
87adbbf
`pytest.skip` `num_violations == 0` only `#ifdef __NO_INLINE__` (irre…
rwgk Jul 20, 2022
f6de990
Systematically change all new `#ifdef` to `#if defined` (review sugge…
rwgk Jul 21, 2022
31a2da3
Bring back MSVC comment that got lost while experimenting.
rwgk Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Introduce make_caster_intrinsic<T>, to be able to undo the 2 change…
…s from `load_type` to `load_type<T>`. This is to avoid breaking 2 `pybind11::detail::load_type()` calls found in the wild (Google global testing).

One of the breakages in the wild was: https://github.com/google/tensorstore/blob/0f0f6007670a3588093acd9df77cce423e0de805/python/tensorstore/subscript_method.h#L61
  • Loading branch information
rwgk committed Jun 28, 2022
commit 4e13032e81afd64c7ca3ec005169061be2ef8cbf
13 changes: 8 additions & 5 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ class type_caster : public type_caster_for_class_<type> {};
#ifdef PYBIND11_TYPE_CASTER_ODR_GUARD_ON

template <typename type>
using make_caster = type_caster_odr_guard<intrinsic_t<type>, type_caster<intrinsic_t<type>>>;
using make_caster_intrinsic = type_caster_odr_guard<type, type_caster<type>>;

#else

template <typename type>
using make_caster = type_caster<intrinsic_t<type>>;
using make_caster_intrinsic = type_caster<type>;

#endif

template <typename type>
using make_caster = make_caster_intrinsic<intrinsic_t<type>>;

template <typename T>
struct type_uses_smart_holder_type_caster {
static constexpr bool value
Expand Down Expand Up @@ -1077,7 +1080,7 @@ struct return_value_policy_override<

// Basic python -> C++ casting; throws if casting fails
template <typename T>
make_caster<T> &load_type(make_caster<T> &conv, const handle &handle) {
make_caster_intrinsic<T> &load_type(make_caster_intrinsic<T> &conv, const handle &handle) {
static_assert(!detail::is_pyobject<T>::value,
"Internal error: type_caster should only be used for C++ types");
if (!conv.load(handle, true)) {
Expand All @@ -1097,7 +1100,7 @@ template <typename T>
make_caster<T> load_type(const handle &handle) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
make_caster<T> conv;
load_type<T>(conv, handle);
load_type(conv, handle);
return conv;
}

Expand Down Expand Up @@ -1235,7 +1238,7 @@ template <typename T>
enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&o,
make_caster<T> &caster) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
return cast_op<T>(load_type<T>(caster, o));
return cast_op<T>(load_type(caster, o));
}
template <typename T>
enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&,
Expand Down