Commit Graph

141 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve 203cc26f5b
[smart_holder] Add test_namespace_visibility (#4050)
* 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 #4054

* 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 485dacef6a Merge branch 'master' into sh_merge_master 2022-06-01 14:39:51 -07:00
Ralf W. Grosse-Kunstleve de4ba92c9f
Add `error_scope` to `detail::get_internals()` (#3981)
* Add `error_scope` to `detail::get_internals()`

* Adjust test to tolerate macOS PyPy behavior.
2022-05-31 11:51:13 -07:00
Ralf W. Grosse-Kunstleve bdf22c8ee7 Merge branch 'master' into sh_merge_master 2022-05-17 16:37:59 -07:00
Ralf W. Grosse-Kunstleve d28c3a5da7
[smart_holder] .def_readonly, .def_readwrite adaptors (continuation of PR #3581). (#3844)
* Transferred net diff from PR #3581, as-is.

* Automatic `pre-commit run --all-files` fixes. NO manual changes.

* Removing trailing `//` (originally added to manipulate clang-format), as suggested by @charlesbeattie back in Jan/Feb under PR #3581.

* Renaming `xetter_cpp_function` to `property_cpp_function` as suggested by @rainwoodman

* Fully explain the terse variable naming scheme in test_class_sh_property (as suggested by @rainwoodman)

* Also use parametrize for readonly, readwrite (as suggested by @rainwoodman)

* Apply change suggested by @skylion007 (with clang-format).
2022-05-17 16:35:43 -07:00
Henry Schreiner 1a7b12983e
ci: fix cuda issue & MSVC spurious warning (#3950)
* ci: fix cuda issue

* ci: cuda 11.3-11.4 produce warnings -> errors

* tests: ignore unused warning for MSVC

* Update tests/CMakeLists.txt
2022-05-16 17:27:19 -04:00
Ralf W. Grosse-Kunstleve e1751c04f0 Merge branch 'master' into sh_merge_master_after_clang-format_etc
First pass manually resolving the many merge conflicts.
2022-02-14 14:36:08 -08:00
Ralf W. Grosse-Kunstleve 6493f496e3
Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688)
* `#error BYE_BYE_GOLDEN_SNAKE`

* Removing everything related to 2.7 from ci.yml

* Commenting-out Centos7

* Removing `PYTHON: 27` from .appveyor.yml

* "PY2" removal, mainly from tests. C++ code is not touched.

* Systematic removal of `u` prefix from `u"..."` and `u'...'` literals. Collateral cleanup of a couple minor other things.

* Cleaning up around case-insensitive hits for `[^a-z]py.*2` in tests/.

* Removing obsolete Python 2 mention in compiling.rst

* Proper `#error` for Python 2.

* Using PY_VERSION_HEX to guard `#error "PYTHON 2 IS NO LONGER SUPPORTED.`

* chore: bump pre-commit

* style: run pre-commit for pyupgrade 3+

* tests: use sys.version_info, not PY

* chore: more Python 2 removal

* Uncommenting Centos7 block (PR #3691 showed that it is working again).

* Update pre-commit hooks

* Fix pre-commit hook

* refactor: remove Python 2 from CMake

* refactor: remove Python 2 from setup code

* refactor: simplify, better static typing

* feat: fail with nice messages

* refactor: drop Python 2 C++ code

* docs: cleanup for Python 3

* revert: intree

revert: intree

* docs: minor touchup to py2 statement

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-02-10 18:28:08 -08:00
Xiaofei Wang 93a376a40a
[smart_holder] Add missing test case to CMakeLists.txt (#3645)
* Add missing test case to CMakeLists.txt

* Fix warnings

* Fix Clangtidy
2022-01-25 16:43:11 -08:00
Ralf W. Grosse-Kunstleve aa209cc90f Adding back test_class_sh, test_classh additions, building on PR #3590. 2022-01-11 17:48:59 -08:00
Ralf W. Grosse-Kunstleve ea0c1e77c8 Merge branch 'master' into sh_merge_master 2022-01-11 17:48:37 -08:00
Ralf W. Grosse-Kunstleve ea4cc147a2 Temporarily backing out all test_class_sh, test_classh additions. 2022-01-11 17:48:05 -08:00
Ivor Wanders 21911e126f
A way to register additional test targets and support .py only tests. (#3590)
* A way to register additional test targets.

* Support specifying tests with extension.

* Ensure TEST_OVERRIDE is backwards compatible.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Ensure regex is non greedy.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-11 17:31:19 -08:00
Ralf W. Grosse-Kunstleve f588810871
Replacing ICC C++14 with C++17 (#3570)
* Replacing ICC C++14 with C++17

* ICPC: -diag-disable:conversion

Try to suppress the `-Werror-all` promotion in `#include <variant>`

* Trying `-DPYBIND11_WERROR=OFF`

* Trying `-Wno-conversion` (todo: make specific to C++17 if it works)

* Inserting -Wno-conversion only for C++17

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
2022-01-11 12:13:02 -08:00
Ralf W. Grosse-Kunstleve 388c03b18c Merge branch 'master' into sh_merge_master_clean 2021-12-29 13:24:20 -08:00
Ralf W. Grosse-Kunstleve 1bbaeb3462
Adding dedicated test_const_name. (#3578)
* Adding dedicated test_const_name.

Also exercises pybind11::detail::_ backward compatibility.

See also: PR #3423

* Backing out tests involving int_to_str (requires C++17 or higher).

* Suppressing clang-tidy errors.

* Disabling test_const_name for MSVC 2015 due to bizarre failures.

* Stacking @pytest.mark.parametrize (thanks to @skylion007 for pointing out).
2021-12-29 12:54:25 -08:00
Ralf W. Grosse-Kunstleve e57afe23f7 Merge branch 'master' into smart_holder 2021-11-20 09:35:40 -08:00
Henry Schreiner 15f8d7c12e
fix(build): cleaner CMake printouts & IDE folders (#3479) 2021-11-18 10:01:24 -05:00
Ralf W. Grosse-Kunstleve 4958fd9aa1 Merge branch 'master' into sh_merge_master 2021-10-26 12:10:34 -07:00
Henry Schreiner e7e2c79f3f
fix: improve support for Python 3.11-dev (#3368)
* ci: support Python 3.11-dev

Also update 3.10 to final, better PyPy usage

* fix: use PyFrame_GetCode on Python 3.9+

* ci: some bitiness of pypy not supported on win

* chore: update CMake support to 3.22rc1 to quiet warning

* fix: use dev version of py to fix Py 3.11

* tests: print proper Eigen version

* ci: include pypy2, not sure why

* ci: avoid running on Python 3.11 for now

* ci: fix runs

* ci: simpler PyPy usage, drop unmaintained scipy + pypy index

* ci: only binary numpy, wait on pypy 3.8

* refactor: address review
2021-10-26 14:50:34 -04:00
Ryan Cahoon c2d3e220bd
fix: the types for return_value_policy_override in optional_caster (#3376)
* fix: the types for return_value_policy_override in optional_caster

`return_value_policy_override` was not being applied correctly in
`optional_caster` in two ways:
- The `is_lvalue_reference` condition referenced `T`, which was the
`optional<T>` type parameter from the class, when it should have used `T_`,
which was the parameter to the `cast` function. `T_` can potentially be a
reference type, but `T` will never be.
- The type parameter passed to `return_value_policy_override` should be
`T::value_type`, not `T`. This matches the way that the other STL container
type casters work.

The result of these issues was that a method/property definition which used a
`reference` or `reference_internal` return value policy would create a Python
value that's bound by reference to a temporary C++ object, resulting in
undefined behavior. For reasons that I was not able to figure out fully, it
seems like this causes problems when using old versions of `boost::optional`,
but not with recent versions of `boost::optional` or the `libstdc++`
implementation of `std::optional`. The issue (that the override to
`return_value_policy::move` is never being applied) is present for all
implementations, it just seems like that somehow doesn't result in problems for
the some implementation of `optional`. This change includes a regression type
with a custom optional-like type which was able to reproduce the issue.

Part of the issue with using the wrong types may have stemmed from the type
variables `T` and `T_` having very similar names. This also changes the type
variables in `optional_caster` to use slightly more descriptive names, which
also more closely follow the naming convention used by the other STL casters.

Fixes #3330

* Fix clang-tidy complaints

* Add missing NOLINT

* Apply a couple more fixes

* fix: support GCC 4.8

* tests: avoid warning about unknown compiler for compilers missing C++17

* Remove unneeded test module attribute

* Change test enum to have more unique int values

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-25 19:04:45 -07:00
Ralf W. Grosse-Kunstleve fd68dede10 Merge branch 'master' into sh_merge_master 2021-10-11 13:18:33 -07:00
Ralf W. Grosse-Kunstleve 7c580586f8
Correct options on Eigen::MappedSparseMatrix & adding MSVC C4127 suppression around Eigen includes. (#3352)
* Adding MSVC C4127 suppression around Eigen includes.

* For MSVC 2015 only: also adding the C4127 suppression to test_eigen.cpp

* Copying original change from PR #3343, with extra line breaks to not run past 99 columns (our desired but currently not enforced limit).
2021-10-11 13:13:01 -07:00
Ralf W. Grosse-Kunstleve 5a90dae7fe Merge branch 'master' into smart_holder 2021-10-06 00:47:43 -07:00
Henry Schreiner d7a7edc12b tests: support Eigen configuration 2021-10-04 10:06:12 -07:00
Ralf W. Grosse-Kunstleve 55fcade987 Merge branch 'master' into sh_merge_master 2021-09-24 12:13:34 -07:00
Jeremy Maitin-Shepard 62c4909cce
Add `custom_type_setup` attribute (#3287)
* Fix `pybind11::object::operator=` to be safe if `*this` is accessible from Python

* Add `custom_type_setup` attribute

This allows for custom modifications to the PyHeapTypeObject prior to
calling `PyType_Ready`.  This may be used, for example, to define
`tp_traverse` and `tp_clear` functions.
2021-09-24 12:08:22 -07:00
Ralf W. Grosse-Kunstleve ce62ec56d7 Merge branch 'master' into sh_merge_master 2021-09-12 19:55:42 -07:00
Laramie Leavitt 0e599589fe
Fix thread safety for pybind11 loader_life_support (#3237)
* Fix thread safety for pybind11 loader_life_support

Fixes issue: https://github.com/pybind/pybind11/issues/2765

This converts the vector of PyObjects to either a single void* or
a per-thread void* depending on the WITH_THREAD define.

The new field is used by each thread to construct a stack
of loader_life_support frames that can extend the life of python
objects.

The pointer is updated when the loader_life_support object is allocated
(which happens before a call) as well as on release.

Each loader_life_support maintains a set of PyObject references
that need to be lifetime extended; this is done by storing them
in a c++ std::unordered_set and clearing the references when the
method completes.

* Also update the internals version as the internal struct is no longer compatible

* Add test demonstrating threading works correctly.

It may be appropriate to run this under msan/tsan/etc.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test to use lifetime-extended references rather than
std::string_view, as that's a C++ 17 feature.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Make loader_life_support members private

* Update version to dev2

* Update test to use python threading rather than concurrent.futures

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove unnecessary env in test

* Remove unnecessary pytest in test

* Use native C++ thread_local in place of python per-thread data structures to retain compatability

* clang-format test_thread.cpp

* Add a note about debugging the py::cast() error

* thread_test.py now propagates exceptions on join() calls.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused sys / merge

* Update include order in test_thread.cpp

* Remove spurious whitespace

* Update comment / whitespace.

* Address review comments

* lint cleanup

* Fix test IntStruct constructor.

* Add explicit to constructor

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>
2021-09-10 12:29:21 -04:00
Ralf W. Grosse-Kunstleve 663dfb28af Merge branch 'master' into smart_holder 2021-07-28 22:50:18 -07:00
Henry Schreiner c14b193308
chore: increase CMake upper limit (#3124) 2021-07-28 18:04:14 -07:00
Ralf W. Grosse-Kunstleve 88546fff7d Fixing merge conflict. 2021-07-15 06:23:06 -07:00
Henry Schreiner cd061aeef1
style: pre-commit cleanup (#3111)
* style: disallow PyTest (should be pytest)

* style: cleanup spell checking a bit

* style: add a few items to the .gitignore
2021-07-14 16:49:13 -04:00
Ralf W. Grosse-Kunstleve 84cbec0bc1 Merge branch 'master' into smart_holder 2021-07-02 07:07:49 -07:00
Antony Lee 5bcaaa0423
Add a std::filesystem::path <-> os.PathLike caster. (#2730) 2021-07-02 07:00:50 -07:00
Ralf W. Grosse-Kunstleve 595f7f4f6e Fixing `git rebase -X theirs smart_holder` issue. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve ef89a43452 Removing experimental code from here. Will be moved to https://github.com/rwgk/rwgk_tbx. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve bf8d6a2900 First fully successful attempt to make `shared_from_this` and trampolines play nicely.
Now also passes the open_spiel iterated_prisoners_dilemma_test ASAN clean, in addition to all pybind11 and PyCLIF unit tests.

The problem was that calling `std::shared_ptr<void>::reset()` with a `void` pointer cannot possibly update the `shared_from_this` `weak_ptr`.

The solution is to store a `shd_ptr_reset` function pointer in `guarded_deleter` (similar in idea to the stored function pointer for calling `delete`).

This commit still includes all debugging code, i.e. is "dirty". The code will be cleaned up after the GitHub CI is fully successful.
2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve 28ed5ecce8 Revert "Experiment: commenting out test_class_sh_shared_from_this."
This reverts commit febf9ce949c0bc87a8bf7ab3ddae4deb28636c9d.
2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve 6989f174ac Experiment: commenting out test_class_sh_shared_from_this. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve e1de4e88b8 Adding test_class_sh_shared_from_this.cpp to tests/CMakeLists.txt. 2021-06-30 07:04:31 -07:00
Jakob Lykke Andersen 660f83e81d SH, test for shared_ptr move 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen fc548c067f SH, update shared_ptr copy tests 2021-06-29 05:57:32 -07:00
Ralf W. Grosse-Kunstleve cf89b865bb Adding documentation with associated test: Using py::classh but with fallback to classic pybind11 2021-04-14 15:00:56 -07:00
Ralf W. Grosse-Kunstleve 793adbda50 Revert "Adding documentation with associated test: Using py::classh but with fallback to classic pybind11"
This reverts commit 49f8f60ec4.

The direct commit was accidental. I meant to create a PR.
2021-04-14 12:31:41 -07:00
Ralf W. Grosse-Kunstleve 5f050c4a7e Merge branch 'master' into smart_holder 2021-04-14 12:21:49 -07:00
Ralf W. Grosse-Kunstleve 49f8f60ec4 Adding documentation with associated test: Using py::classh but with fallback to classic pybind11 2021-04-14 12:19:15 -07:00
Philipp Bucher 62976cfcb8
fix: using -Werror-all for Intel (#2948)
* correcting Werror for Intel

* adding ward for Intel

* adding wards for intel

* another ward for Intel

* missed one intel ward

* exact match for intel compiler

* removing inline limits

* disable warnings about inline limits

* formatter suggestion

* more indent

* hopefully make formatter happy

* addressed review

* fix &&

* Update tests/CMakeLists.txt

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-04-14 14:01:27 -04:00
Ralf W. Grosse-Kunstleve 8efd5e3820
Bug fix: trampoline_self_life_support CpCtor, MvCtor. (#2947) 2021-04-13 05:34:46 -07:00
Ralf W. Grosse-Kunstleve 6c922614ed
Adding reclaim_disowned logic & miscellaneous naming and documentation improvements. (#2943)
* Using new smart_holder::reclaim_disowned in smart_holder_type_caster for unique_ptr.

* Systematically renaming was_disowned to is_disowned (because disowning is now reversible: reclaim_disowned).

* Systematically renaming virtual_overrider_self_life_support to trampoline_self_life_support (to reuse existing terminology instead of introducing new one).

* Systematically renaming test_class_sh_with_alias to test_class_sh_trampoline_basic.

* Adding a Trampolines and std::unique_ptr section to README_smart_holder.rst.

* MSVC compatibility.
2021-04-09 23:08:44 -07:00