Commit Graph

844 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
a655f95a83 Merge branch 'master' into sh_merge_master 2021-08-26 14:46:44 -07:00
Ye Zhihao
cb60ed49e4
Fix enum value's __int__ returning non-int when underlying type is bool or of char type (#1334)
* Use equivalent_integer for enum's Scalar decision

* Add test for char underlying enum

* Support translating bool type in enum's Scalar

* Add test for bool underlying enum

* Fix comment in test

* Switch from `PYBIND11_CPP20` macro to `PYBIND11_HAS_U8STRING`

* Refine tests

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-08-26 14:34:24 -07:00
Dan
930bb16c79
Call PySys_SetArgv when initializing interpreter. (#2341)
* Call PySys_SetArgv when initializing interpreter.

* Document argc/argv parameters in initialize_interpreter.

* Remove manual memory management from set_interpreter_argv in favor of smart pointers.

* Use size_t for indexers in set_interpreter_argv.

* Minimize macros for flow control in set_interpreter_argv.

* Fix 'unused variable' warning on Py2

* whitespace

* Define wide_char_arg_deleter outside set_interpreter_argv.

* Do sys.path workaround in C++ rather than eval.

* Factor out wchar conversion to a separate function.

* Restore widened_argv variable declaration.

* Fix undeclared widened_arg variable on some paths.

* Use delete[] to match new wchar_t[].

* Fix compiler errors

* Use PY_VERSION_HEX for a cleaner CVE-2008-5983 mode check.

* Fix typo

* Use explicit type for deleter so delete[] works cross-compiler.

* Always use PySys_SetArgvEx because pybind11 doesn't support pythons that don't include it.

* Remove pointless ternary operator.

* Use unique_ptr.reset instead of a second initialization.

* Rename add_program_dir_to_path parameter to clarify intent.

* Add defined() check before evaluating HAVE_BROKEN_MBSTOWCS.

* Apply clang-tidy fixes

* Pre-commit

* refactor: use const for set_interpreter_argv

* Try to fix const issue and allocate vector properly

* fix: copy strings on Python 2

* Applying clang-format-diff relative to master.

The only manual change is an added empty line between pybind11 and system `#include`s.

```
git diff -U0 --no-color master | python3 $HOME/clone/llvm-project/clang/tools/clang-format/clang-format-diff.py -p1 -style=file -i
```

Co-authored-by: Boris Staletic <boris.staletic@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2021-08-26 14:12:54 -07:00
Nick Cullen
503ff2a6fb
view for numpy arrays (#987)
* reshape

* more tests

* Update numpy.h

* Update test_numpy_array.py

* array view

* test

* Update test_numpy_array.cpp

* Update numpy.h

* Update numpy.h

* Update test_numpy_array.cpp

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

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

* Fix merge bug

* Make clang-tidy happy

* Add xfail for PyPy

* Fix casting issue

* Fix formatting

* Apply clang-tidy

* Address reviews on additional tests

* Fix ordering

* Do a little more reordering

* Fix typo

* Try improving tests

* Fix error in reshape

* Add one more reshape test

* Fix bugs and add test

* Relax test

* streamlining new tests; removing a few stray msg

* Fix style revert

* Fix clang-tidy

* Misc tweaks:
* Comment: matching style in file (///), responsibility sentence, consistent punctuation.
* Replacing `unsigned char` with `uint8_t` for max consistency.
* Removing `1` from `array_view1` because there is only one.

* Partial clang-format-diff.

Co-authored-by: ncullen93 <ncullen.th@dartmouth.edu>
Co-authored-by: NC Cullen <nicholas.c.cullen.th@dartmouth.edu>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf Grosse-Kunstleve <rwgk@google.com>
2021-08-26 14:11:01 -07:00
Henry Schreiner
db44afa33b
tests: fix pytest usage on Python 3.10 (#3221) 2021-08-26 10:52:13 -07:00
Nick Cullen
59ad1e7d05
reshape for numpy arrays (#984)
* reshape

* more tests

* Update numpy.h

* Update test_numpy_array.py

* Update numpy.h

* Update numpy.h

* Update test_numpy_array.cpp

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

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

* Fix merge bug

* Make clang-tidy happy

* Add xfail for PyPy

* Fix casting issue

* Address reviews on additional tests

* Fix ordering

* Do a little more reordering

* Fix typo

* Try improving tests

* Fix error in reshape

* Add one more reshape test

* streamlining new tests; removing a few stray msg

Co-authored-by: ncullen93 <ncullen.th@dartmouth.edu>
Co-authored-by: NC Cullen <nicholas.c.cullen.th@dartmouth.edu>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf Grosse-Kunstleve <rwgk@google.com>
2021-08-26 08:12:35 -07:00
Jouke Witteveen
031a700dfd
Add make_simple_namespace function and tests (#2840)
Co-authored-by: Jouke Witteveen <j.witteveen@cosine.nl>
2021-08-26 08:04:22 -07:00
Ralf W. Grosse-Kunstleve
c8ce4b8df8
Clone of @virtuald's PR #2112 with minor enhancements. (#3215)
* Add py::raise_from to enable chaining exceptions on Python 3.3+

* Use 'raise from' in initialization

* Documenting the exact base version of _PyErr_FormatVFromCause, adding back `assert`s.

Co-authored-by: Dustin Spicuzza <dustin@virtualroadside.com>
2021-08-23 17:30:01 -07:00
Liam Keegan
4f29b8a45b
ci: extend msys2 mingw CI (#3207)
* extend msys2 CI

- add 32-bit job
- add c++11/17 c++/interface tests copied from standard ci
- add numpy/scipy

* account for padding of PartialStruct in numpy dtypes test with mingw32

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

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

* msys2 ci: add c++14 tests

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-08-19 14:42:55 -04:00
Ralf W. Grosse-Kunstleve
b176057abc Merge branch 'master' into smart_holder 2021-08-19 11:40:24 -07:00
Ralf W. Grosse-Kunstleve
998d45e431
Cleanup of file-scoped and globally-scoped warning suppression pragmas across pybind11 header files. (#3201)
* Removing all MSVC C4127 warning suppression pragmas.

* Removing MSVC /WX (WERROR). To get a full list of all warnings.

* Inserting PYBIND11_SILENCE_MSVC_C4127. Changing one runtime if to #if.

* Changing PYBIND11_SILENCE_MSVC_C4127 macro to use absolute namespace (for use outside pybind11 include directory).

* Restoring MSVC /WX (WERROR).

* Removing globally-scoped suppression for clang -Wunsequenced. Based on an experiment under PR #3202 it is obsolete and can simply be removed.
2021-08-19 11:37:04 -07:00
Ralf W. Grosse-Kunstleve
e41fb99e7e clang-tidy fixes (mostly manual) related to PR #3166 2021-08-14 12:45:50 -07:00
Ralf W. Grosse-Kunstleve
e3e1d29fdb Removing obsolete detail/pragma_warning_block.h 2021-08-14 08:42:38 -07:00
Ralf W. Grosse-Kunstleve
191769c29b Automatic isort fixes. 2021-08-14 08:34:52 -07:00
Ralf W. Grosse-Kunstleve
8865d28317 Automatic part of merging branch 'master' into sh_merge_master.
The only manual intervention was to remove the merge conflict markers in pybind11.h.

TODO in separate commit: complete removal of the obsolete detail/pragma_warning_block.h.
2021-08-14 07:54:40 -07:00
Aaron Gokaslan
9df2f1ff13
maint(precommit): Apply isort (#3195)
* Apply isort

* Tweak isort config

* Add env.py as a known_first_party

* Add one missing known first party

* Make config compat with older isort versions

* Add another comment

* Revert pyproject setting
2021-08-13 12:37:05 -04:00
Eric Cousineau
6ac8efe52d
test_eval: Show example of working closure (#2743)
* test_eval: Show example of working closure

* Extend test_eval_closure with weirder examples of closures for py::eval

Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-08-06 15:51:53 -04:00
Aaron Gokaslan
3893f37bce
maint(clang-tidy): Bugprone enable checks (#3166)
* Enable bugprone checks

* Reset delta and massage config

* Start to apply bugprone fixes

* try to fix minor bug

* Fix later

* Fix perfect forwarding bugprone

* Remove nolint

* undo constructor delete

* Fix bugprone-perfect-forwarding again

* Remove TODO

* Add another nolint for bugprone-exception-escape in scoped interpreter

* Fix remaining bugprone errors

* Properly apply bugprone-macro-parantheses

* Redo formatting and remove bugprone nolint

* Add coment and revert more whitespace changes

* Fix typo

* Fix parsing bug

* Add back comma

* Fix clang-tidy issue

* Apply remaining clang-tidy fixes
2021-08-06 14:30:28 -04:00
Ralf W. Grosse-Kunstleve
aff3cf7b65 Merge branch 'master' into sh_merge_master 2021-07-30 12:25:43 -07:00
Jerome Robert
9e8a741baa
fix: Mingw64 corrected and add a CI job to test it (#3132)
* mingw64 platform string is like mingw_xxx not "mingw"

See https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-python/0099-Change-the-get_platform-method-in-sysconfig-and-dist.patch

* Mingw: Do not dllexport exceptions

This is a fix for errors like:

D:/a/pybind11/pybind11/include/pybind11/detail/common.h:735:23: error: 'dllexport' implies default visibility, but 'class pybind11::builtin_exception' has already been declared with a different visibility
  735 | class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
      |                       ^~~~~~~~~~~~~~~~~

* GHA: Test Mingw64 build

* fix: avoid thin binaries on mingw

* fix: drop lto on MinGW

* Mingw64: disable PYBIND11_DEPRECATED

It trigger many warnings for unknown reasons

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2021-07-30 13:48:41 -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
119db695ca Follow-on to PR #3148 (cang-tidy). 2021-07-27 16:18:30 -07:00
Ralf W. Grosse-Kunstleve
45ef484366 Merge branch 'master' into smart_holder 2021-07-27 15:38:09 -07:00
Ralf W. Grosse-Kunstleve
2164c2e0e7
Removing __INTEL_COMPILER section from pragma block at the top of pybind11.h (#3135)
* Fixing `pragma warning pop` for `__INTEL_COMPILER`.

* Adding push/pop to 3 tests. Removing #878 from top of pybind11.h (it was/is only needed for 1 test).

* Trying again after CI failure, moving the push to the top of 2 tests.

* Trying more after CI failure, adding push/pop to pybind11_tests.h, constructor_stats.h.

* Moving ICC #2196 suppression to CMakeLists.txt

* Fixing condition for `pragma GCC diagnostic push` in pybind11.h

* Moving `pragma warning disable 2196` to common.h

* Revising #ifdef to be more conservative.

* Undoing insertion of notes that will hopefully soon be completely obsolete anyway.
2021-07-27 15:33:31 -07:00
Aaron Gokaslan
9beaa925db
maint(clang-tidy): Improve code readability with explicit boolean casts (#3148)
* maint(clang-tidy) Improve code readability

* Fix minor typos

* Revert optimization that removed test case

* Fix comment formatting

* Revert another optimization to repro an issue

* Remove make_unique since it C++14 and newer only

* eformat comments

* Fix unsignedness of comparison

* Update comment
2021-07-27 15:32:26 -07:00
Henry Schreiner
7cc0ebb475
fix: the CMake config in Python package had a hard coded path (#3144) 2021-07-27 17:23:52 -04:00
Ralf W. Grosse-Kunstleve
1cd7179f1f Merge branch 'master' into smart_holder 2021-07-27 11:30:23 -07:00
David Hewitt
a0b975965f
Allow python builtins to be used as callbacks (#1413)
* Allow python builtins to be used as callbacks

* Try to fix pypy segfault

* Add expected fail for PyPy

* Fix typo

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

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

* Add more info to xfail

* Add env

* Try returning false

* Try removing the move for pypy

* Fix bugs

* Try removing move

* Just keep ignoring for PyPy

* Add back xfail

* Fix ctors

* Revert change of std::move

* Change to skip

* Fix bug and edit comments

* Remove clang-tidy bugprone fix skip bug

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-07-27 14:16:28 -04:00
Ralf W. Grosse-Kunstleve
7cc433ca7f Merge branch 'master' into smart_holder 2021-07-21 06:56:03 -07:00
jesse-sony
d65edfb024
Feature/local exception translator (#2650)
* Create a module_internals struct

Since we now have two things that are going to be module local, it felt
correct to add a struct to manage them.

* Add local exception translators

These are added via the  register_local_exception_translator function
and are then applied before the global translators

* Add unit tests to show the local exception translator works

* Fix a bug in the unit test with the string value of KeyError

* Fix a formatting issue

* Rename registered_local_types_cpp()

Rename it to get_registered_local_types_cpp() to disambiguate from the
new member of module_internals

* Add additional comments to new local exception code path

* Add a register_local_exception function

* Add additional unit tests for register_local_exception

* Use get_local_internals like get_internals

* Update documentation for new local exception feature

* Add back a missing space

* Clean-up some issues in the docs

* Remove the code duplication when translating exceptions

Separated out the exception processing into a standalone function in the
details namespace.

Clean-up some comments as per PR notes as well

* Remove the code duplication in register_exception

* Cleanup some formatting things caught by clang-format

* Remove the templates from exception translators

But I added a using declaration to alias the type.

* Remove the extra local from local_internals variable names

* Add an extra explanatory comment to local_internals

* Fix a typo in the code
2021-07-21 05:22:18 -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
279c93654e Merge branch 'master' into smart_holder 2021-07-13 21:24:02 -07:00
Shane Loretz
7331d381af
Raise codec errors when casting to std::string (#2903)
* Raise codec errors when casting to std::string

Allow the codec's exception to be raised instead of RuntimeError when
casting from py::str to std::string.

PY2 allows ucs surrogates in UTF-8 conversion

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Attempt to fix py2 error

* Revert all unicode literals

* Fixed

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-07-13 21:21:55 -07:00
Ralf W. Grosse-Kunstleve
aca6c3ba37
* Removing stray semicolons (discovered by running clang-format v12 followed by tools/check-style.sh). (#3087)
* Manually moving `// NOLINT` comments so that clang-format does not move them to the wrong places.

* Manually reformatting comments related to `static_assert`s so that clang-format does not need two passes.

* Empty lines between #includes, to prevent clang-format from shuffling the order and thereby confusing MSVC 2015.

* git diff -U0 --no-color HEAD^ | python3 $HOME/clone/llvm-project/clang/tools/clang-format/clang-format-diff.py -p1 -style=file -i
2021-07-13 18:14:58 -07:00
Antony Lee
1be0a0a610
Add helper to build in-tree extensions. (#2831)
For single-file extensions, a convenient pattern offered by cython
is to place the source files directly in the python source tree
(`foo/__init__.py`, `foo/ext.pyx`), deriving the package names from
their filesystem location.  Adapt this pattern for pybind11, using an
`intree_extensions` helper, which should be thought of as the moral
equivalent to `cythonize`.

Differences with cythonize: I chose not to include globbing support
(`intree_extensions(glob.glob("**/*.cpp"))` seems sufficient), nor to
provide extension-customization kwargs (directly setting the attributes
on the resulting Pybind11Extension objects seems sufficient).

We could choose to have `intree_extension` (singular instead) and make
users write `[*map(intree_extension, glob.glob("**/*.cpp"))]`; no strong
opinion here.

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-07-13 17:21:55 -04:00
Ralf W. Grosse-Kunstleve
6133fc7b0c Merge branch 'master' into smart_holder 2021-07-13 10:29:36 -07:00
Aaron Gokaslan
25e470c57d
fix(clang-tidy): Add cppcoreguidelines-init-vars,slicing, and throw-by-value-catch-by-reference checks (#3094)
* clang-tidy: guard against more UB behavior

* Remove slicing check for now
2021-07-13 09:54:32 -04:00
Ralf W. Grosse-Kunstleve
88cc350075 Merge branch 'master' into smart_holder 2021-07-13 05:57:50 -07:00
Henry Schreiner
0e2e003508 style: add pyupgrade check, 2.7+ 2021-07-12 21:46:24 -04:00
Henry Schreiner
84fdadfbcc chore: update pre-commit hooks 2021-07-12 21:46:24 -04:00
Ralf W. Grosse-Kunstleve
678538f097 Merge branch 'master' into smart_holder 2021-07-12 16:59:58 -07:00
Ralf W. Grosse-Kunstleve
75090647ce
More precise return_value_policy::automatic documentation. (#2920)
* Adding test_return_vector_bool_raw_ptr to test_stl.py.

* First attempt to make the documentation more accurate, but not trying to be comprehensive, to not bloat the reference table with too many details.

* Fixing minor oversights.

* Applying reviewer suggestion.
2021-07-12 16:56:10 -07:00
Ralf W. Grosse-Kunstleve
932a4cf409 Merge branch 'master' into smart_holder 2021-07-12 14:07:26 -07:00
Ralf W. Grosse-Kunstleve
7472d37a93
Adding iostream.h thread-safety documentation. (#2995)
* Adding iostream.h thread-safety documentation.

* Restoring `TestThread` code with added `std::lock_guard<std::mutex>`.

* Updating new comments to reflect new information.

* Fixing up `git rebase -X theirs` accidents.
2021-07-12 13:39:06 -07:00
Ralf W. Grosse-Kunstleve
2d468697d9
NOLINT reduction (#3096)
* Copying from prework_no_rst branch (PR #3087): test_numpy_array.cpp, test_stl.cpp

* Manual changes reducing NOLINTs.

* clang-format-diff.py

* Minor adjustment to avoid MSVC warning C4702: unreachable code
2021-07-12 13:10:28 -07:00
Ralf W. Grosse-Kunstleve
14fc79f18e
WIP: restoring valgrind CI on smart_holder branch (#3090)
* * Rollback of PR #3068.
* Using latest pytest main branch for 3.9 and 3.10.
* WORKAROUND_ENABLING_ROLLBACK_OF_PR3068 in test_class_sh_trampoline_shared_from_this.py

First experiment combining two potential fixes: latest pytest, workaround.
If this succeeds the next step will be to try only latest pytest without the workaround.

Note: the workaround is known to resolve the MSAN error reported under
https://github.com/pybind/pybind11/pull/3068#issuecomment-877658470

* WORKAROUND_ENABLING_ROLLBACK_OF_PR3068 = False

* Narrowing down WORKAROUND_ENABLING_ROLLBACK_OF_PR3068 to Python 3.9
2021-07-10 17:54:23 -07:00
Ralf W. Grosse-Kunstleve
3c185332b1 Merge branch 'master' into smart_holder 2021-07-09 18:25:32 -07:00
Ralf W. Grosse-Kunstleve
bac5a0c370
Go all the way fixing clang-tidy issues to avoid the NOLINTNEXTLINE clutter and clang-format issues. This was really meant to be part of PR #3051 but was held back either out of an abundance of caution, or because of confusion caused by stray semicolons. (#3086) 2021-07-09 14:09:56 -07:00
Ralf W. Grosse-Kunstleve
e7d146bdbd Merge branch 'master' into smart_holder 2021-07-09 06:47:46 -07:00
Aaron Gokaslan
b5357d1fa8
fix(clang-tidy): Enable clang-tidy else-after-return and redundant void checks (#3080)
* Enable clang-tidy else-after-return and redundant void checks

* Fix remaining else-after

* Address reviewer comments

* Fix indentation

* Rerun clang-tidy post merge
2021-07-09 06:45:53 -07:00
Ralf W. Grosse-Kunstleve
c03061fcff Merge branch 'master' into smart_holder 2021-07-08 09:48:42 -07:00
Ralf W. Grosse-Kunstleve
6d1b197b46
Splitting out pybind11/stl/filesystem.h. (#3077)
* Splitting out pybind11/stl/filesystem.h.

To solve breakages like: https://github.com/deepmind/open_spiel/runs/2999582108

Mostly following the suggestion here: https://github.com/pybind/pybind11/pull/2730#issuecomment-750507575

Except using pybind11/stl/filesystem.h instead of pybind11/stlfs.h, as decided via chat.

stl.h restored to the exact state before merging PR #2730 via:
```
git checkout 733f8de24f stl.h
```

* Properly including new stl subdirectory in pip wheel config.

This now passes interactively:
```
pytest tests/extra_python_package/
```

* iwyu cleanup.

iwyuh.py -c -std=c++17 -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/include/python3.9 -I/usr/include/eigen3 include/pybind11/stl/filesystem.h

* Adding PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL.

* Eliminating else after return.
2021-07-08 09:02:48 -07:00
Robert Haschke
c090c8c409
Unify cast_error message thrown by [simple|unpacking]_collector (#3013)
* Unify cast_error message thrown by [simple|unpacking]_collector

simple_collector and unpacking_collector throw different error messages
when the casting of an argument failed: While the former mentions make_tuple(),
the latter emphasises the call argument (and its name/position).

* Consolidating "Unable to convert call argument" error reporting code to guarantee uniformity.

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2021-07-06 15:13:13 -07:00
Ralf W. Grosse-Kunstleve
00b0365ca3 codespell fixes and adding .codespell-ignorelines 2021-07-06 14:31:18 -07:00
Ralf W. Grosse-Kunstleve
704daac879 Merge branch 'master' into smart_holder 2021-07-06 14:12:08 -07:00
luzpaz
8bee61b645
docs: fix various typos (#3075)
Found via `codespell -q 3 -L nd,ot,thist`
2021-07-04 19:58:35 -04:00
Ralf W. Grosse-Kunstleve
52c3f4cc30
This was meant to be PR #3065: pure clang-format changes. NO manual changes. (#3073) 2021-07-02 16:51:24 -07: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
cad79c1146
tests: remove very minor oversight in PR #3059. (#3066) 2021-06-30 17:30:26 -04:00
Ralf W. Grosse-Kunstleve
94f0db58ee Fixing merge accident related to merging PR #3059 from master.
I did not go back to check when and why exactly this slipped in.

Also removing unused `msg` (oversight in PR #3059).
2021-06-30 13:30:34 -07:00
Ralf W. Grosse-Kunstleve
c2111fd353 Merge branch 'master' into smart_holder 2021-06-30 12:36:27 -07:00
Ralf W. Grosse-Kunstleve
fbae8f313b
pickle setstate: setattr __dict__ only if not empty (#2972)
* pickle setstate: setattr __dict__ only if not empty, to not force use of py::dynamic_attr() unnecessarily.

* Adding unit test.

* Clang 3.6 & 3.7 compatibility.

* PyPy compatibility.

* Minor iwyu fix, additional comment.

* Addressing reviewer requests.

* Applying clang-tidy suggested fixes.

* Adding check_dynamic_cast_SimpleCppDerived, related to issue #3062.
2021-06-30 12:34:32 -07:00
Ralf W. Grosse-Kunstleve
5af253d66c Adding test_multiple_registered_instances_for_same_pointee_recursive. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
a021e045a9 Adding test_multiple_registered_instances_for_same_pointee_leak. Subtle changes in smart_holder_type_caster_load, trying to work on weak_ptr for shared_ptr_trampoline_self_life_support, but that didn't work out. Manually fully leak-checked again. 2021-06-30 07:04:31 -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
e2108546e1 Adding unit tests: 2 x test_std_make_shared_factory
Completes unit test coverage for the changed code in smart_holder_type_casters.h.
2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
1b752f56c1 Adding unit test: test_multiple_registered_instances_for_same_pointee 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
64716cc14c Adding a few comments after review by @laramiel. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
4a08160a1f Revert "Updating Catch version to latest, in hopes of resolving the GHA download issue affecting all MSVC builds."
This reverts commit f4e1112dc434d0505cecad6259113f0621ecba70.

It didn't help.
2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
db6244864f Updating Catch version to latest, in hopes of resolving the GHA download issue affecting all MSVC builds. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
ab3c5134ad Cleaning out debug code. 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
146a925e4e Resolving TODOs for from_unique_ptr void_cast_raw_ptr. Adding test to exercise the path through cast. The path through init.h is missing a test that would fail if the flag is incorrect. The plan is to systematically cover all situations (there are many that are not exercised for shared_from_this). 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
a0e19bdc46 Use casting to void * to evade to shared_from_this mechanism only if pointee_depends_on_holder_owner, but currently only for from_raw_ptr_take_ownership. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
ccd16a1a14 Adding test_pure_cpp_sft_raw_ptr (with 3 TODO: Fix), test_pure_cpp_sft_shd_ptr (works as desired). 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
4a15ed742c Adding // NOLINT for clang-tidy. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
10abe15052 Automatic clang-tidy fixes. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
48eb78ae77 Simpler and safe implementation based on new requirement: C++ (outside of the Python object) needs to hold a shared_ptr before shared_from_this is called. This is more similar to the existing implementation on current smart_holder HEAD, but still uses a weak_ptr to always return the same shared_ptr as long as C++ does not let it expire. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
3dd89f14df smart_holder_poc.h: type-erase raw_ptr before passing to shared_ptr::reset, to not trigger populating the shared_from_this weak_ptr. This way the only way the weak_ptr is populated is through loaded_as_shared_ptr. Breaks all but one test in test_class_sh_trampoline_shared_from_this.py, now marked skip WIP to test everything else with the GitHub CI. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
b1d9f0d28f Applying clang-tidy suggested fixes. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
adfd3e1700 Partial cleanup of tests. WIP. The cleanup uncovered a major problem. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
bfd4c4893e Leveraging new noop_deleter_acting_as_weak_ptr_owner to retrieve released vptr.
The placeholder `vptr` is never exposed anymore, therefore the externally visible `use_count`s are more intuitive.
2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
0e4b38e34d Minor clang-tidy fix. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
4b872febcc Adding test_pass_released_shared_ptr_as_unique_ptr, exercising new guard in smart_holder_type_casters.h. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
e04196e82b Attempts to side-step various platform-specific issues. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
6214137c8d Resolving gcc warning-as-error (many versions, old and new). 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
553054b26b Adding tests involving stashing shared_ptrs. WIP. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
4218213f29 nodiscard fix. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
223283295f Two minor platform-specific fixes. Using static_cast instead of reinterpret_cast. 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
5bb38c10b3 MSVC 2015 compatibility. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
45ec61f419 Adding shared_ptr_reset_and_rescue_pointee_model_proof_of_concept. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
b633bb5b84 Inserting #ifdef to preempt Windows fatal exception. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
e0b770d549 Explictly discarding [[nodiscard]] to avoid MSVC CI failures. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
4f00ffdc69 Copying in shared_from_this_custom_deleters.cpp from github.com/rwgk, with adjustments.
Base version: e5318faa6a/shared_from_this_custom_deleters.cpp
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
05bd93543b Fully emulating type_caster_base-related behavior: trying shared_from_this also for unowned pointees. 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
Ralf W. Grosse-Kunstleve
775873d0b6 Adding from_raw_pointer_take_ownership_or_shared_from_this(). 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
2a265860a7 enable_shared_from_this_from_raw_ptr_take_ownership_guard: better static_assert that also triggers for derived classes. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
24c223ad8e static_assert in from_raw_ptr_take_ownership, to be tested. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
7a74bfede7 Restoring init_holder overload for std::enable_shared_from_this and original tests/test_smart_ptr.py. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
e5b38a4459 Breaking up test_shared_ptr_from_this_and_references into smaller subtests. Skipping the only test that generates an ASAN heap-use-after-free. 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
94523e8a02 Experiments: 1. disabling enable_shared_from_this, 2. using smart_holder in test_class_sh_shared_from_this.cpp 2021-06-30 07:04:31 -07:00
Ralf W. Grosse-Kunstleve
252b6aefb8 Isolating shared_from_this tests from test_smart_ptr (minimal changes). 2021-06-30 07:04:31 -07:00
Jakob Lykke Andersen
b9241c0330 SM, remove type annotations in test 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
f39efb850b SH, attribute and property tests 2021-06-29 05:57:32 -07:00
Ralf W. Grosse-Kunstleve
fa5ffc3d02 Automatic clang-format. 2021-06-29 05:57:32 -07:00
Ralf W. Grosse-Kunstleve
a428f5755d Automatic clang-tidy fixes. 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
f06f0927b3 SH, history tracking 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
0337ed944d SH, fix use of PYBIND11_TYPE_CASTER_BASE_HOLDER 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
ee53a45ffd SH, fix typo 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
b735093fde SH, shared_ptr copy/move, rename to 'history' 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
ef6907c1ae SH, shared_ptr copy/move, make MSVC happy 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
abf11b9d9a SH, shared_ptr copy/move, update after review 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
660f83e81d SH, test for shared_ptr move 2021-06-29 05:57:32 -07:00
Jakob Lykke Andersen
2934913761 SH, test update 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
Jakob Lykke Andersen
1f98d74761 Initial test 2021-06-29 05:57:32 -07:00
Cris Luengo
57a36633c4 fix: enable py::implicitly_convertible<py::none, ...> for py::class_-wrapped types (#3059)
* Allow casting from None to a custom object, closes #2778

* ci.yml patch from the smart_holder branch for full CI coverage.
2021-06-25 21:57:45 -07:00
Cris Luengo
93e69191c1
fix: enable py::implicitly_convertible<py::none, ...> for py::class_-wrapped types (#3059)
* Allow casting from None to a custom object, closes #2778

* ci.yml patch from the smart_holder branch for full CI coverage.
2021-06-25 17:56:17 -07:00
Ralf W. Grosse-Kunstleve
2c828ff552 More clang-tidy fixes. These escaped before because -DDOWNLOAD_EIGEN=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=17, as used in the GitHub Actions, were missing in the interactive run. 2021-06-22 14:42:47 -07:00
Ralf W. Grosse-Kunstleve
2eeac0c369 Applying clang-tidy fixes needed after merging PR #3051 (mostly automatically). 2021-06-22 13:38:30 -07:00
Ralf W. Grosse-Kunstleve
898d5b301c Manually fixing merge conflict. 2021-06-22 12:19:40 -07:00
Aaron Gokaslan
dac74ebdf5
fix(clang-tidy): performance fixes applied in tests and CI (#3051)
* Initial fixes

* Whoops

* Finish clang-tidy manual fixes

* Add two missing fixes

* Revert

* Update clang-tidy

* Try to fix unreachable code error

* Move nolint comment

* Apply missing fix

* Don't override clang-tidy config

* Does this fix clang-tidy?

* Make all clang-tidy errors visible

* Add comments about NOLINTs and remove a few

* Fix typo
2021-06-22 12:11:54 -04:00
Ralf W. Grosse-Kunstleve
8d1e0b3903
[smart_holder] clang-tidy fixes (related to recent clang-tidy changes on master). (#3053)
* clang-tidy fixes (related to recent clang-tidy changes on master).

* More clang-tidy fixes.
2021-06-21 12:40:10 -07:00
Ralf W. Grosse-Kunstleve
274b014578 Merge branch 'master' into smart_holder 2021-06-21 07:51:19 -07:00
Aaron Gokaslan
3b30b0a51e
fix(clang-tidy): clang-tidy readability and misc fixes, like adding const (#3052)
* Enable and apply clang-tidy readability and misc fixes.

* Revert deprecated tester

* add space to tests/test_constants_and_functions.cpp
2021-06-21 10:37:48 -04:00
Ralf W. Grosse-Kunstleve
29fafcc1b2
Fixing clang-tidy error (related to PR #3049). (#3050)
Example:
```
test_class_sh_unique_ptr_member.cpp:17:5: error: deleted member function should be public [modernize-use-equals-delete,-warnings-as-errors]
    pointee(const pointee &) = delete;
    ^
```
2021-06-19 16:51:09 -07:00
Ralf W. Grosse-Kunstleve
fb7452ce39 Merge branch 'master' into smart_holder 2021-06-19 15:52:36 -07:00
Aaron Gokaslan
e0b5cbd4c6
chore(clang-tidy): add more modernize clang-tidy checks (#3049)
* Add more modernize clang-tidy checks

* Enable a few more
2021-06-19 18:38:56 -04:00
Ralf W. Grosse-Kunstleve
48c7a3a68f Merge branch 'master' into smart_holder 2021-06-08 12:05:19 -07:00
Jack S. Hale
4c7697dbe9
Add const T to docstring generation. (#3020)
* Add const T to docstring generation.

* Change order.

* See if existing test triggers for a const type.

* Add tests.

* Fix test.

* Remove experiment.

* Reformat.

* More tests, checks run.

* Adding `test_fmt_desc_` prefix to new test functions.

* Using pytest.mark.parametrize to 1. condense test; 2. exercise all functions even if one fails; 3. be less platform-specific (e.g. C++ float is not necessarily float32).

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2021-06-08 11:56:45 -07:00
Ralf W. Grosse-Kunstleve
f5bc2040bf Merge branch 'master' into smart_holder 2021-05-27 12:59:42 -07:00
Ralf W. Grosse-Kunstleve
e25b1505db
Adjusting valgrind suppression for pypocketfft to resolve systematic failures that started to appear on 2020-05-27. (#3022) 2021-05-27 12:51:46 -07:00
Ralf W. Grosse-Kunstleve
2cfc017e2d Merge branch 'master' into smart_holder 2021-05-27 11:30:03 -07:00
Yichen
3ac690b88b
Explicitly export exception types. (#2999)
* Set visibility of exceptions to default.

Co-authored-by: XZiar <czktc2007@gmail.com>

* add test

* update docs

* Skip failed test.
2021-05-27 08:00:18 -07:00
Ralf W. Grosse-Kunstleve
29e46381e4 Merge branch 'master' into smart_holder 2021-05-06 09:48:55 -07:00
Eric Cousineau
b6ec0e950c
functions: Add doc on incorrect argument index (#2979)
test_call_policies: Explicitly check free-functions and static methods
2021-05-06 10:13:30 -04:00
Ralf W. Grosse-Kunstleve
6cca66b276 Merge branch 'master' into smart_holder 2021-05-03 22:15:44 -07:00
Ralf W. Grosse-Kunstleve
bc3cd8a8a8
Splitting out include/pybind11/detail/pragma_warning_block.h (#2988)
* Splitting out include/pybind11/detail/pragma_warning_block.h

* Always including pragma_warning_block.h before common.h (resolved 8 CI failures).
2021-05-03 22:08:04 -07:00
Pieter P
0c93a0f3fc
Fix Unicode support for ostream redirects (#2982)
* Crash when printing Unicode to redirected cout
Add failing tests

* Fix Unicode crashes redirected cout

* pythonbuf::utf8_remainder check end iterator

* Remove trailing whitespace and formatting iostream

* Avoid buffer overflow if ostream redirect races
This doesn't solve the actual race, but at least it now has a much lower
probability of reading past the end of the buffer even when data races
do occur.
2021-05-03 22:04:38 -07:00
Ralf W. Grosse-Kunstleve
7d093a1906 Merge branch 'master' into smart_holder 2021-04-21 12:36:53 -07:00
Henry Schreiner
5e4804bb66
tests: use master commit for pytest on 3.10 (#2967) 2021-04-21 13:30:01 -04:00
Ralf W. Grosse-Kunstleve
99de498b26
Bug fix: adding back !is_alias<Class>(ptr) that were accidentally omitted. (#2958)
* Bug fix: adding back `!is_alias<Class>(ptr)` that were accidentally omitted.

* Introducing PYBIND11_SH_AVL, PYBIND11_SH_DEF macros. Applying PYBIND11_SH_DEF to test_factory_constructors.py to complete test coverage.

* Using PYBIND11_SH_DEF in test_methods_and_attributes.cpp, for more complete test coverage.

* Using PYBIND11_SH_DEF in test_multiple_inheritance.cpp, for more complete test coverage.

* Cleaning up test_classh_mock.cpp.

* Better explanations for PYBIND11_SH_AVL, PYBIND11_SH_DEF.

* Disabling 3.10-dev builds.
2021-04-19 10:54:37 -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