1
0
mirror of https://github.com/pybind/pybind11.git synced 2025-03-04 21:43:19 +00:00
Commit Graph

2937 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
696b80a59b Use no-destructor idiom for type_caster_odr_guard_registry, as suggested by @laramiel 2022-07-15 11:19:50 -07:00
Ralf W. Grosse-Kunstleve
671c2ce0d5 Update comment (incl. mention of deadsnakes known to not work as intended). 2022-07-14 08:10:23 -07:00
Ralf W. Grosse-Kunstleve
02ac969c80 Fully document the ODR violations in the ODR guard itself and introduce PYBIND11_TYPE_CASTER_ODR_GUARD_ON_IF_AVAILABLE 2022-07-13 19:11:53 -07:00
Ralf W. Grosse-Kunstleve
4dabffcbd5 Merge branch 'smart_holder' into odr_guard_sh 2022-07-13 17:40:20 -07:00
Ralf W. Grosse-Kunstleve
0ec9e31bbf Merge branch 'master' into sh_merge_master 2022-07-12 18:37:15 -07:00
Ralf W. Grosse-Kunstleve
203cc26f5b
[smart_holder] Add test_namespace_visibility ()
* Add test_namespace_visibility

To probe environment/toolchain/platform-specific behavior under the exact same conditions as normal tests.

(An earlier version of this code was used to inform PR #4043.)

* Disable flake8 in ubench/holder_comparison_*.py, to suppress new & useless diagnostics.

* Disable namespace_visibility_1s.cpp (tosee if that resolves the MSVC and CUDA `test_cross_module_exception_translator` failures).

* Turn off flake8 completely for ubench (the Strip unnecessary `# noqa`s action un-helpfully removed the added noqa).

* Disable test_namespace_visibility completely. Just keep the two .cpp files, only setting the module docstring and doing nothing else.

* Rename test_namespace_visibility.py to test_exc_namespace_visibility.py, so that it is imported by pytest before test_exceptions.py

* Add `set_property(SOURCE namespace_visibility_1s.cpp PROPERTY LANGUAGE CUDA)`

* Add reference to PR 

* Complete the documentation (comments in test_exc_namespace_visibility.py).

* Rename namespace_visibility.h to namespace_visibility.inl, as suggested by @charlesbeattie
2022-07-12 18:33:42 -07:00
Ralf W. Grosse-Kunstleve
023b3f32c8
Undo accidental one-line change under PR () 2022-07-12 12:02:20 -07:00
Ralf W. Grosse-Kunstleve
38688ec32c Some more work on source code comments. 2022-07-11 19:39:47 -07:00
pre-commit-ci[bot]
790241bce2
[pre-commit.ci] pre-commit autoupdate ()
updates:
- [github.com/asottile/pyupgrade: v2.34.0 → v2.37.1](https://github.com/asottile/pyupgrade/compare/v2.34.0...v2.37.1)
- [github.com/hadialqattan/pycln: v1.3.5 → v2.0.1](https://github.com/hadialqattan/pycln/compare/v1.3.5...v2.0.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-11 22:31:54 -04:00
Ralf W. Grosse-Kunstleve
2a14ee6e48 Add new test_descr_src_loc & and fix descr.h concat() src_loc bug discovered while working on the test. 2022-07-11 18:04:15 -07:00
Ralf W. Grosse-Kunstleve
bd0dbd7cf5 src_loc comments 2022-07-11 10:22:05 -07:00
Ralf W. Grosse-Kunstleve
75c659866f Minor tweaks looking at the PR with a fresh eye. 2022-07-11 10:14:26 -07:00
Ralf W. Grosse-Kunstleve
70f645f6d1 Merge branch 'smart_holder' into odr_guard_sh 2022-07-10 09:17:16 -07:00
Ralf W. Grosse-Kunstleve
bcd1800cf4 Turn off flake8 completely for ubench/
To suppress these new errors (apparently after a flake8 upgrade):

```
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

ubench/holder_comparison.py:96:38: B023 Function definition does not bind loop variable 'nb1'.
                    assert int(round(nb1.sum())) == data_size
                                     ^
ubench/holder_comparison.py:96:53: B023 Function definition does not bind loop variable 'data_size'.
                    assert int(round(nb1.sum())) == data_size
                                                    ^
ubench/holder_comparison.py:99:25: B023 Function definition does not bind loop variable 'nb1'.
                        nb1.sum()
                        ^
ubench/holder_comparison.py:103:28: B023 Function definition does not bind loop variable 'nb1'.
                    assert nb1.add(nb2) == data_size
                           ^
ubench/holder_comparison.py:103:36: B023 Function definition does not bind loop variable 'nb2'.
                    assert nb1.add(nb2) == data_size
                                   ^
ubench/holder_comparison.py:103:44: B023 Function definition does not bind loop variable 'data_size'.
                    assert nb1.add(nb2) == data_size
                                           ^
ubench/holder_comparison.py:106:25: B023 Function definition does not bind loop variable 'nb1'.
                        nb1.add(nb2)
                        ^
ubench/holder_comparison.py:106:33: B023 Function definition does not bind loop variable 'nb2'.
                        nb1.add(nb2)
                                ^
ubench/holder_comparison_extract_sheet_data.py:21:16: B023 Function definition does not bind loop variable 'header_row'.
            if header_row:
               ^
ubench/holder_comparison_extract_sheet_data.py:22:20: B023 Function definition does not bind loop variable 'header'.
                if header is None:  # type: ignore[unreachable]
                   ^
ubench/holder_comparison_extract_sheet_data.py:23:36: B023 Function definition does not bind loop variable 'header_row'.
                    print(",".join(header_row))
                                   ^
ubench/holder_comparison_extract_sheet_data.py:25:28: B023 Function definition does not bind loop variable 'header'.
                    assert header == header_row
                           ^
ubench/holder_comparison_extract_sheet_data.py:25:38: B023 Function definition does not bind loop variable 'header_row'.
                    assert header == header_row
                                     ^
ubench/holder_comparison_extract_sheet_data.py:26:16: B023 Function definition does not bind loop variable 'data_row'.
            if data_row is not None:
               ^
ubench/holder_comparison_extract_sheet_data.py:27:32: B023 Function definition does not bind loop variable 'data_row'.
                print(",".join(data_row))  # type: ignore[unreachable]
                               ^
ubench/holder_comparison_extract_sheet_data.py:28:17: B023 Function definition does not bind loop variable 'data_row_buffer'.
                data_row_buffer.append(data_row)
                ^
ubench/holder_comparison_extract_sheet_data.py:28:40: B023 Function definition does not bind loop variable 'data_row'.
                data_row_buffer.append(data_row)
                                       ^
ubench/holder_comparison_extract_sheet_data.py:29:20: B023 Function definition does not bind loop variable 'header_row'.
            return header_row
                   ^
```
2022-07-09 21:50:36 -07:00
Ralf W. Grosse-Kunstleve
3bd20627d3 Tracking ci.yml changes from master. 2022-07-09 21:50:08 -07:00
Ralf W. Grosse-Kunstleve
27ce64fc43 Merge branch 'master' into sh_merge_master 2022-07-09 21:47:49 -07:00
Aaron Gokaslan
f9f00495a3
Properly visit self in >=3.9 traverse ()
* Properly visit self in >=3.9 traverse

* Add comment about 3.9 behavior
2022-07-09 21:43:53 -07:00
Ralf W. Grosse-Kunstleve
432bc5cfb5
Add std::string clean_type_id(const char *typeid_name) overload (in namespace detail). ()
Very minor refactoring to ease development and debugging.

Having to declare a local `std::string` has bugged me many times. Nice to get this little nuisance out of the way.

Extracted from PR , where it is used like this:

```
    std::fprintf(stdout,
                 "\nTYPE_CASTER_ODR_GUARD_IMPL %s %s\n",
                 clean_type_id(intrinsic_type_info.name()).c_str(),
                 source_file_line_from_sloc.c_str());
```
2022-07-07 19:08:10 -07:00
Ralf W. Grosse-Kunstleve
85bc088441
Report C++ Info: via pytest_report_header() ()
* Report `C++ Info:` from `pytest_configure()`

* Use pytest_report_header() as suggested by @skylion007
2022-07-07 17:51:44 -07:00
Ralf W. Grosse-Kunstleve
cd08869df1
PYBIND11_NAMESPACE consistency fixes. () 2022-07-06 14:29:20 -07:00
Henry Schreiner
0ab1fcfb1c
docs: update changelog ()
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-07-06 16:36:05 -04:00
Aaron Gokaslan
2af163d9c7
Fix: 3.11 beta support ()
* Placeholder commit for 3.11 testing

* Does this fix it?

* Try suggestion

* Placeholder commit for 3.11 testing

* Does this fix it?

* Try suggestion

* fix: try using modern init for embedded interp

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* fix: error message changed in 3.11

* fix: apply logic in Python manually

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* fix autodetect dynamic attrs in 3.11

* fix: include error message if possible in error

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: enable standard Python 3.11 testing

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Make dynamic attrs condtiion exclusive to ver.

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-07-06 16:35:12 -04:00
pre-commit-ci[bot]
c42e3ab793
[pre-commit.ci] pre-commit autoupdate ()
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 22.3.0 → 22.6.0](https://github.com/psf/black/compare/22.3.0...22.6.0)
- [github.com/Lucas-C/pre-commit-hooks: v1.2.0 → v1.3.0](https://github.com/Lucas-C/pre-commit-hooks/compare/v1.2.0...v1.3.0)
- [github.com/PyCQA/pylint: v2.14.3 → v2.14.4](https://github.com/PyCQA/pylint/compare/v2.14.3...v2.14.4)
- [github.com/pre-commit/mirrors-clang-format: v14.0.5 → v14.0.6](https://github.com/pre-commit/mirrors-clang-format/compare/v14.0.5...v14.0.6)

* Update blacken-docs

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-07-04 22:21:59 -04:00
dependabot[bot]
bc1f9f9ba6
chore(deps): bump actions/setup-python from 3 to 4 ()
* chore(deps): bump actions/setup-python from 3 to 4

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Apply suggestions from code review

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2022-07-04 10:24:55 -04:00
Henry Schreiner
5a3a1e3415
chore: simpler dependabot ()
Ignores no longer needed after April 2022. Dependabot keeps the same style pinning now.
2022-07-04 10:24:34 -04:00
Ralf W. Grosse-Kunstleve
13076e4fb7 Remove PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE macro completely. Some small extra cleanup. 2022-07-01 18:48:23 -07:00
Ralf W. Grosse-Kunstleve
ae38889322 Remove PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL macro completely. 2022-07-01 18:15:32 -07:00
Ralf W. Grosse-Kunstleve
11adace1ea Fix small oversight (src_loc::here() -> src_loc{nullptr, 0}). 2022-07-01 16:52:54 -07:00
Ralf W. Grosse-Kunstleve
68b155a10c Use TypeCasterType::name.sloc instead of source_file_line.sloc
Manual re-verification:

```
+++ b/tests/test_type_caster_odr_guard_2.cpp
-    // m.def("pass_vector_type_mrc", mrc_ns::pass_vector_type_mrc);
+    m.def("pass_vector_type_mrc", mrc_ns::pass_vector_type_mrc);
```

```
>           assert num_violations == 1
E           assert 2 == 1

num_violations = 2

test_type_caster_odr_guard_1.py:51: AssertionError
```
2022-07-01 16:40:33 -07:00
Ralf W. Grosse-Kunstleve
44966dab16 Work scr_loc into descr 2022-07-01 16:40:33 -07:00
Ralf W. Grosse-Kunstleve
38c25655b7 Add missing include (discovered via google-internal testing). 2022-07-01 16:40:33 -07:00
Matthew Woehlke
479e9a50f3
Fix arrays with zero-size dimensions ()
When converting an array to an Eigen matrix, ignore the strides if any
dimension size is 0. If the array is empty, the strides aren't relevant,
and especially numpy ≥ 1.23 explicitly sets the strides to 0 in this
case. (See numpy commit dd5ab7b11520.)

Update tests to verify that this works, and continues to work.
2022-06-29 11:37:16 -07:00
Ralf W. Grosse-Kunstleve
9ba32bde5e Disable type_caster ODR guard for __INTEL_COMPILER (see comment). Also turn off printf. 2022-06-28 20:43:09 -07:00
Ralf W. Grosse-Kunstleve
37e583bab8 Use source_file_line_from_sloc in type_caster_odr_guard_registry 2022-06-28 19:38:47 -07:00
Masaki Kozuki
374a5b000a
[docs] Fix "Enumerations and internal types" example ()
* Fix binding of `Pet::Attributes`

* omit `attributes` as it's not needed

Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
2022-06-28 12:38:37 -07:00
Ralf W. Grosse-Kunstleve
4b6d3b87a7 clang-tidy suggested fixes 2022-06-28 08:56:54 -07:00
Ralf W. Grosse-Kunstleve
11e858d0da tu_local_descr with src_loc experiment 2022-06-28 08:42:44 -07:00
Ralf W. Grosse-Kunstleve
3ea37002b1 Eliminate need for PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL macro.
Copying code first developed by @amauryfa. I tried this at an earlier stage, but by itself this was insufficient. In the meantime I added in the TU-local mechanisms: trying again.

Passes local testing:
```
DISABLED std::system_error: ODR VIOLATION DETECTED: pybind11::detail::type_caster<mrc_ns::type_mrc>: SourceLocation1="/usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_odr_guard_1.cpp:18", SourceLocation2="/usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_odr_guard_2.cpp:19"
C++ Info: Debian Clang 13.0.1 C++17 __pybind11_internals_v4_clang_libstdcpp_cxxabi1002_sh_def__
=========================================================== test session starts ============================================================
platform linux -- Python 3.9.12, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests, configfile: pytest.ini
collected 6 items

test_type_caster_odr_guard_1.py::test_type_mrc_to_python PASSED
test_type_caster_odr_guard_1.py::test_type_mrc_from_python PASSED
test_type_caster_odr_guard_1.py::test_type_caster_odr_registry_values PASSED
test_type_caster_odr_guard_1.py::test_type_caster_odr_violation_detected_counter PASSED
test_type_caster_odr_guard_2.py::test_type_mrc_to_python PASSED
test_type_caster_odr_guard_2.py::test_type_mrc_from_python PASSED

============================================================ 6 passed in 0.01s =============================================================
```
2022-06-28 07:10:20 -07:00
Ralf W. Grosse-Kunstleve
3fc4833433 Add test for stl.h / stl_bind.h mix.
Manually verified that the ODR guard detects the ODR violation:

```
C++ Info: Debian Clang 13.0.1 C++17 __pybind11_internals_v4_clang_libstdcpp_cxxabi1002_sh_def__
=========================================================== test session starts ============================================================
platform linux -- Python 3.9.12, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
...
================================================================= FAILURES =================================================================
_____________________________________________ test_type_caster_odr_violation_detected_counter ______________________________________________

    def test_type_caster_odr_violation_detected_counter():
        ...
        else:
>           assert num_violations == 1
E           assert 2 == 1
E             +2
E             -1

num_violations = 2

test_type_caster_odr_guard_1.py:51: AssertionError
========================================================= short test summary info ==========================================================
FAILED test_type_caster_odr_guard_1.py::test_type_caster_odr_violation_detected_counter - assert 2 == 1
======================================================= 1 failed, 5 passed in 0.08s ========================================================
```
2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
4e13032e81 Introduce make_caster_intrinsic<T>, to be able to undo the 2 changes 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: 0f0f600767/python/tensorstore/subscript_method.h (L61)
2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
d8280df5d5 assert pybind11_tests.compiler_info is not None 2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
491c2c7983 compiler_info MSVC fix. num_violations == 0 condition. 2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
0d2bf264c8 Trying a new direction: show compiler info & std for UNEXPECTED: type_caster_odr_violation_detected_count() == 0 2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
0c0f322e23 Yet another attempt to handle valgrind behavior. 2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
5737b37dd4 Another attempt to handle valgrind behavior. 2022-06-28 00:20:53 -07:00
Ralf W. Grosse-Kunstleve
b10fc2ef15 Attempt to handle valgrind behavior. 2022-06-28 00:20:52 -07:00
Ralf W. Grosse-Kunstleve
3cc2c9cd45 Apply clang-tidy suggestion. 2022-06-28 00:20:52 -07:00
Ralf W. Grosse-Kunstleve
262998b317 Report UNEXPECTED: test_type_caster_odr_guard_2.cpp prevailed (but do not fail). 2022-06-28 00:20:52 -07:00
Ralf W. Grosse-Kunstleve
1263ce9ee2 Add test_type_caster_odr_registry_values(), test_type_caster_odr_violation_detected_counter() 2022-06-28 00:20:52 -07:00
Ralf W. Grosse-Kunstleve
d2bafaeba7 New PYBIND11_TYPE_CASTER_ODR_GUARD_STRICT option (current on by default). 2022-06-28 00:20:52 -07:00