"vscode:/vscode.git/clone" did not exist on "abcf43d59c16542e20175d1522d13518b341967f"
  1. 31 Oct, 2022 3 commits
    • Ralf W. Grosse-Kunstleve's avatar
      fix: unicode surrogate character in Python exception message. (#4297) · 3fb36a99
      Ralf W. Grosse-Kunstleve authored
      
      
      * Fix & test for issue #4288 (unicode surrogate character in Python exception message).
      
      * DRY `message_unavailable_exc`
      
      * fix: add a constexpr
      Co-authored-by: default avatarAaron Gokaslan <skylion.aaron@gmail.com>
      
      * style: pre-commit fixes
      Co-authored-by: default avatarHenry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: default avatarAaron Gokaslan <skylion.aaron@gmail.com>
      Co-authored-by: default avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      3fb36a99
    • Chekov2k's avatar
      Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` option (cmake, C++ define) (#4216) · 15fde1de
      Chekov2k authored
      * Add option to force the use of the PYPY GIL scoped acquire/release logic to support nested gil access, see https://github.com/pybind/pybind11/issues/1276 and https://github.com/pytorch/pytorch/issues/83101
      
      
      
      * Apply suggestions from code review
      
      * Update CMakeLists.txt
      
      * docs: update upgrade guide
      
      * Update docs/upgrade.rst
      
      * All bells & whistles.
      
      * Add Reminder to common.h, so that we will not forget to purge `!WITH_THREAD` branches when dropping Python 3.6
      
      * New sentence instead of semicolon.
      
      * Temporarily pull in snapshot of PR #4246
      
      * Add `test_release_acquire`
      
      * Add more unit tests for nested gil locking
      
      * Add test_report_builtins_internals_keys
      
      * Very minor enhancement: sort list only after filtering.
      
      * Revert change in docs/upgrade.rst
      
      * Add test_multi_acquire_release_cross_module, while also forcing unique PYBIND11_INTERNALS_VERSION for cross_module_gil_utils.cpp
      
      * Hopefully fix apparently new ICC error.
      
      ```
      2022-10-28T07:57:54.5187728Z -- The CXX compiler identification is Intel 2021.7.0.20220726
      ...
      2022-10-28T07:58:53.6758994Z icpc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
      2022-10-28T07:58:54.5801597Z In file included from /home/runner/work/pybind11/pybind11/include/pybind11/detail/../detail/type_caster_base.h(15),
      2022-10-28T07:58:54.5803794Z                  from /home/runner/work/pybind11/pybind11/include/pybind11/detail/../cast.h(15),
      2022-10-28T07:58:54.5805740Z                  from /home/runner/work/pybind11/pybind11/include/pybind11/detail/../attr.h(14),
      2022-10-28T07:58:54.5809556Z                  from /home/runner/work/pybind11/pybind11/include/pybind11/detail/class.h(12),
      2022-10-28T07:58:54.5812154Z                  from /home/runner/work/pybind11/pybind11/include/pybind11/pybind11.h(13),
      2022-10-28T07:58:54.5948523Z                  from /home/runner/work/pybind11/pybind11/tests/cross_module_gil_utils.cpp(13):
      2022-10-28T07:58:54.5949009Z /home/runner/work/pybind11/pybind11/include/pybind11/detail/../detail/internals.h(177): error #2282: unrecognized GCC pragma
      2022-10-28T07:58:54.5949374Z       PYBIND11_TLS_KEY_INIT(tstate)
      2022-10-28T07:58:54.5949579Z       ^
      2022-10-28T07:58:54.5949695Z
      ```
      
      * clang-tidy fixes
      
      * Workaround for PYPY WIN exitcode None
      
      * Revert "Temporarily pull in snapshot of PR #4246"
      
      This reverts commit 23ac16e859150f27fda25ca865cabcb4444e0770.
      
      * Another workaround for PYPY WIN exitcode None
      
      * Clean up how the tests are run "run in process" Part 1: uniformity
      
      * Clean up how the tests are run "run in process" Part 2: use `@pytest.mark.parametrize` and clean up the naming.
      
      * Skip some tests `#if defined(THREAD_SANITIZER)` (tested with TSAN using the Google-internal toolchain).
      
      * Run all tests again but ignore ThreadSanitizer exitcode 66 (this is less likely to mask unrelated ThreadSanitizer issues in the future).
      
      * bug fix: missing common.h include before using `PYBIND11_SIMPLE_GIL_MANAGEMENT`
      
      For the tests in the github CI this does not matter, because
      `PYBIND11_SIMPLE_GIL_MANAGEMENT` is always defined from the command line,
      but when monkey-patching common.h locally, it matters.
      
      * if process.exitcode is None: assert t_delta > 9.9
      
      * More sophisiticated `_run_in_process()` implementation, clearly reporting `DEADLOCK`, additionally exercised via added `intentional_deadlock()`
      
      * Wrap m.intentional_deadlock in a Python function, for `ForkingPickler` compatibility.
      
      ```
      >       ForkingPickler(file, protocol).dump(obj)
      E       TypeError: cannot pickle 'PyCapsule' object
      ```
      
      Observed with all Windows builds including mingw but not PyPy, and macos-latest with Python 3.9, 3.10, 3.11 but not 3.6.
      
      * Add link to potential solution for WOULD-BE-NICE-TO-HAVE feature.
      
      * Add `SKIP_IF_DEADLOCK = True` option, to not pollute the CI results with expected `DEADLOCK` failures while we figure out what to do about them.
      
      * Add COPY-PASTE-THIS: gdb ... command (to be used for debugging the detected deadlock)
      
      * style: pre-commit fixes
      
      * Do better than automatic pre-commit fixes.
      
      * Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` to `pytest_report_header()` (so that we can easily know when harvesting deadlock information from the CI logs).
      Co-authored-by: default avatarArnim Balzer <arnim@seechange.ai>
      Co-authored-by: default avatarHenry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: default avatarRalf W. Grosse-Kunstleve <rwgk@google.com>
      Co-authored-by: default avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      15fde1de
    • Aaron Gokaslan's avatar
      fix: improve bytes to str decoding error handling (#4294) · 5b395c9b
      Aaron Gokaslan authored
      * (bugfix): Improve bytes to str decoding error handling
      
      * regroup test
      
      * Further broaden tests
      
      * Add another decode error test
      
      * Fix bug in tests
      
      * Reviewer suggestions
      5b395c9b
  2. 23 Oct, 2022 1 commit
  3. 21 Oct, 2022 2 commits
  4. 20 Oct, 2022 1 commit
  5. 17 Oct, 2022 1 commit
    • Aaron Gokaslan's avatar
      bugfix: py contains raises errors when appropiate (#4209) · b926396b
      Aaron Gokaslan authored
      * bugfix: contains now throws an exception if the key is not hashable
      
      * Fix tests and improve robustness
      
      * Remove todo
      
      * Workaround PyPy corner case
      
      * PyPy xfail
      
      * Fix typo
      
      * fix xfail
      
      * Make clang-tidy happy
      
      * Remove redundant exc checking
      b926396b
  6. 10 Oct, 2022 1 commit
    • Ralf W. Grosse-Kunstleve's avatar
      Reproducer and fix for issue encountered in smart_holder update. (#4228) · da104a9e
      Ralf W. Grosse-Kunstleve authored
      * Reproducer for issue encountered in smart_holder update.
      
      * clang-tidy compatibility (untested).
      
      * Add `enable_if_t` to workaround.
      
      * Bug fix: Move `PYBIND11_USING_WORKAROUND_FOR_CUDA_11_4_THROUGH_8` determination to detail/common.h
      
      So that it actually is defined in pybind11.h
      
      * Try using the workaround (which is nicer than the original code) universally.
      
      * Reduce reproducer for CUDA 11.7 issue encountered in smart_holder update.
      
      This commit tested in isolation on top of current master + first version of reproducer (62311eb431849d135a5db84f6c75ec390f2ede7c).
      
      Succeeds with Debian Clang 14.0.6 C++17 (and probably all other compilers).
      
      Fails for CUDA 11.7:
      
      ```
      cd /build/tests && /usr/local/cuda/bin/nvcc -forward-unknown-to-host-compiler -Dpybind11_tests_EXPORTS -I/mounted_pybind11/include -isystem=/usr/include/python3.10 -g --generate-code=arch=compute_52,code=[compute_52,sm_52] -Xcompiler=-fPIC -Xcompiler=-fvisibility=hidden -Werror all-warnings -std=c++17 -MD -MT tests/CMakeFiles/pybind11_tests.dir/test_class.cpp.o -MF CMakeFiles/pybind11_tests.dir/test_class.cpp.o.d -x cu -c /mounted_pybind11/tests/test_class.cpp -o CMakeFiles/pybind11_tests.dir/test_class.cpp.o
      /mounted_pybind11/tests/test_class.cpp(53): error: more than one instance of overloaded function "pybind11::class_<type_, options...>::def [with type_=test_class::pr4220_tripped_over_this::Empty0, options=<>]" matches the argument list:
                  function template "pybind11::class_<test_class::pr4220_tripped_over_this::Empty0> &pybind11::class_<type_, options...>::def(const char *, Func &&, const Extra &...) [with type_=test_class::pr4220_tripped_over_this::Empty0, options=<>]"
      /mounted_pybind11/include/pybind11/pybind11.h(1557): here
                  function template "pybind11::class_<test_class::pr4220_tripped_over_this::Empty0> &pybind11::class_<type_, options...>::def(const T &, const Extra &...) [with type_=test_class::pr4220_tripped_over_this::Empty0, options=<>]"
      /mounted_pybind11/include/pybind11/pybind11.h(1586): here
                  argument types are: (const char [8], <unknown-type>)
                  object type is: pybind11::class_<test_class::pr4220_tripped_over_this::Empty0>
      
      1 error detected in the compilation of "/mounted_pybind11/tests/test_class.cpp".
      ```
      da104a9e
  7. 07 Oct, 2022 2 commits
  8. 30 Aug, 2022 1 commit
  9. 24 Aug, 2022 1 commit
    • Brad Messer's avatar
      Words matter updates (#4155) · a48ec3e8
      Brad Messer authored
      * Remove sanity check from code base.
      
      * Use main over master.
      
      * Better alternative that doesn't collide with language keywords/frequent usage words.
      a48ec3e8
  10. 21 Aug, 2022 1 commit
  11. 11 Aug, 2022 1 commit
  12. 09 Aug, 2022 1 commit
  13. 03 Aug, 2022 1 commit
  14. 01 Aug, 2022 2 commits
    • Thomas Eding's avatar
      f8e8403b
    • Ralf W. Grosse-Kunstleve's avatar
      Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (#4073) · 36655302
      Ralf W. Grosse-Kunstleve authored
      * Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (and `-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON`).
      
      * Using no-destructor idiom to side-step overzealous MINGW warning.
      
      * Add __MINGW32__ pragma GCC diagnostic ignored in eigen.h
      
      * Add another no-destructor workaround.
      
      * Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings.
      
      * Revert "Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings."
      
      This reverts commit f36b0af8f93e9f6f16c969fb5b646e116f5eaf0f.
      
      * Very minor shuffle to avoid MSVC warnings.
      
      * Remove all `:BOOL` as suggested by @henryiii
      36655302
  15. 21 Jul, 2022 2 commits
    • Ralf W. Grosse-Kunstleve's avatar
      More systematic gcc & clang coverage (#4083) · 9a296373
      Ralf W. Grosse-Kunstleve authored
      * More systematic gcc coverage, based on https://github.com/pybind/pybind11/pull/4074#issuecomment-1188385580
      
      * Fix complete fail.
      
      * Resolve GCC 11 & 12 "redundant move in return statement" warnings.
      
      * Also add clang 11, 12, 13 (to gather info for warning suppressions).
      
      * Add & use `PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING`
      9a296373
    • Ralf W. Grosse-Kunstleve's avatar
      For PyPy only, re-enable old behavior (runs the risk of masking bugs) (#4079) · cb35a3c1
      Ralf W. Grosse-Kunstleve authored
      * For PyPy only, re-enable old behavior (likely to mask bugs), to avoid segfault with unknown root cause.
      
      Change prompted by https://github.com/pybind/pybind11/issues/4075
      
      * Undo the change in tests/test_exceptions.py
      
      I turns out (I forgot) that PyPy segfaults in `test_flaky_exception_failure_point_init` already before the `MISMATCH` code path is reached:
      
      https://github.com/pybind/pybind11/runs/7383663596
      
      ```
      RPython traceback:
      test_exceptions.py .......X.........Error in cpyext, CPython compatibility layer:
        File "pypy_module_cpyext.c", line 14052, in wrapper_second_level__star_3_1
        File "pypy_module_cpyext_1.c", line 35750, in not_supposed_to_fail
      Fatal Python error: Segmentation fault
      Stack (most recent call first, approximate line numbers):
        File "/home/runner/work/pybind11/pybind11/tests/test_exceptions.py", line 306 in test_flaky_exception_failure_point_init
      The function PyErr_NormalizeException was not supposed to fail
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/python.py", line 185 in pytest_pyfunc_call
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/python.py", line 1716 in runtest
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 159 in pytest_runtest_call
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
      Fatal error in cpyext, CPython compatibility layer, calling PyErr_NormalizeException
      Either report a bug or consider not using this particular extension
      <SystemError object at 0x7fcc8cea6868>
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 261 in <lambda>
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 317 in from_call
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 246 in call_runtest_hook
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 218 in call_and_report
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 118 in runtestprotocol
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 110 in pytest_runtest_protocol
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 335 in pytest_runtestloop
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 318 in _main
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 255 in wrap_session
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 314 in pytest_cmdline_main
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/config/__init__.py", line 133 in main
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/config/__init__.py", line 181 in console_main
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pytest/__main__.py", line 1 in <module>
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/lib-python/3/runpy.py", line 62 in _run_code
        File "/opt/hostedtoolcache/PyPy/3.7.13/x64/lib-python/3/runpy.py", line 170 in _run_module_as_main
        File "<builtin>/app_main.py", line 109 in run_toplevel
        File "<builtin>/app_main.py", line 652 in run_command_line
        File "<builtin>/app_main.py", line 996 in entry_point
      Segmentation fault (core dumped)
      ```
      
      * Add test_pypy_oserror_normalization
      
      * Disable new `PYPY_VERSION` `#if`, to verify that the new test actually fails.
      
      * Restore PYPY_VERSION workaround and update comment to reflect what was learned.
      
      * [ci skip] Fix trivial oversight in comment.
      cb35a3c1
  16. 20 Jul, 2022 1 commit
    • Aaron Gokaslan's avatar
      Fix #3812 and fix const of inplace assignments (#4065) · f47f1edf
      Aaron Gokaslan authored
      
      
      * Fix #3812 and fix const of inplace assignments
      
      * Fix missing tests
      
      * Revert operator overloading changes
      
      * calculate answer first for tests
      
      * Simplify tests
      
      * Add more tests
      
      * Add a couple more tests
      
      * Add test_inplace_lshift, test_inplace_rshift for completeness.
      
      * Update tests
      
      * Shortcircuit on self assigment and address reviewer comment
      
      * broaden skip for self assignment
      
      * One more reviewer comment
      
      * Document opt behavior and make consistent
      
      * Revert unnecessary change
      
      * Clarify comment
      Co-authored-by: default avatarRalf W. Grosse-Kunstleve <rwgk@google.com>
      f47f1edf
  17. 14 Jul, 2022 1 commit
    • Ralf W. Grosse-Kunstleve's avatar
      Disable implicit conversion of `0` to `pybind11::handle`. (#4008) · 1d811910
      Ralf W. Grosse-Kunstleve authored
      * Disable implicit conversion from `0` to `pybind11::handle`.
      
      * Reverse or-ed condition in an attempt to resolve GCC 8.3.0 errors (i386/debian:buster).
      
      * Trying the simpler `std::is_same<T, PyObject *>`
      
      * Add implicit_conversion_from_pytorch_THPObjectPtr_to_handle test.
      
      * Accommodate types with implicit conversions to `PyObject *`, other than `handle` & `handle` subclasses, or integral types.
      
      * Fix copy-paste mishap (picked wrong name).
      
      * Revamp SFINAE construct to actually fix the pytorch issue (already validated against pytorch proper).
      
      The first version of the reduced pytorch code was critically missing the move ctor. The first version of the accompanying test was meaningless.
      
      Note: It turns out the `!std::is_arithmetic<T>` condition is not needed: `int` is not in general implicitly convertible to `PyObject *`, only the literal `0` is.
      
      * Use `NOLINT(performance-noexcept-move-constructor)` for reduced code from the wild (rather than changing the code).
      
      * Use any_of, all_of, negation. It turns out to clang-format nicer.
      
      * Clean up comments for changed code.
      
      * Reduce pytorch situation further, add test for operator ... const.
      
      * Use `none_of` as suggested by @skylion007
      
      * Add `pure_compile_tests_for_handle_from_PyObject_pointers()`
      
      * Fix inconsequential oversight (retested).
      
      * Factor our `is_pyobj_ptr_or_nullptr_t` to make the SFINAE conditions more readable.
      
      * Remove stray line (oversight).
      
      * Make the `pure_compile_tests_for_handle_from_PyObject_pointers()` "rhs-const-complete", too.
      
      * Remove the temporary PYBIND11_UNDO_PR4008 `#ifdef`.
      1d811910
  18. 13 Jul, 2022 1 commit
  19. 08 Jul, 2022 1 commit
  20. 06 Jul, 2022 1 commit
  21. 29 Jun, 2022 1 commit
    • Matthew Woehlke's avatar
      Fix arrays with zero-size dimensions (#4038) · 479e9a50
      Matthew Woehlke authored
      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.
      479e9a50
  22. 06 Jun, 2022 1 commit
  23. 02 Jun, 2022 1 commit
    • Sergei Lebedev's avatar
      error_already_set::what() is now constructed lazily (#1895) · a05bc3d2
      Sergei Lebedev authored
      * error_already_set::what() is now constructed lazily
      
      Prior to this commit throwing error_already_set was expensive due to the
      eager construction of the error string (which required traversing the
      Python stack). See #1853 for more context and an alternative take on the
      issue.
      
      Note that error_already_set no longer inherits from std::runtime_error
      because the latter has no default constructor.
      
      * Do not attempt to normalize if no exception occurred
      
      This is not supported on PyPy-2.7 5.8.0.
      
      * Extract exception name via tp_name
      
      This is faster than dynamically looking up __name__ via GetAttrString.
      Note though that the runtime of the code throwing an error_already_set
      will be dominated by stack unwinding so the improvement will not be
      noticeable.
      
      Before:
      
      396 ns ± 0.913 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
      
      After:
      
      277 ns ± 0.549 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
      
      Benchmark:
      
      const std::string foo() {
          PyErr_SetString(PyExc_KeyError, "");
          const std::string &s = py::detail::error_string();
          PyErr_Clear();
          return s;
      }
      
      PYBIND11_MODULE(foo, m) {
          m.def("foo", &::foo);
      }
      
      * Reverted error_already_set to subclass std::runtime_error
      
      * Revert "Extract exception name via tp_name"
      
      The implementation of __name__ is slightly more complex than that.
      It handles the module name prefix, and heap-allocated types. We could
      port it to pybind11 later on but for now it seems like an overkill.
      
      This reverts commit f1435c7e6b068a1ed13ebd3db597ea3bb15aa398.
      
      * Cosmit following @YannickJadoul's comments
      
      Note that detail::error_string() no longer calls PyException_SetTraceback
      as it is unncessary for pretty-printing the exception.
      
      * Fixed PyPy build
      
      * Moved normalization to error_already_set ctor
      
      * Fix merge bugs
      
      * Fix more merge errors
      
      * Improve formatting
      
      * Improve error message in rare case
      
      * Revert back if statements
      
      * Fix clang-tidy
      
      * Try removing mutable
      
      * Does build_mode release fix it
      
      * Set to Debug to expose segfault
      
      * Fix remove set error string
      
      * Do not run error_string() more than once
      
      * Trying setting the tracebackk to the value
      
      * guard if m_type is null
      
      * Try to debug PGI
      
      * One last try for PGI
      
      * Does reverting this fix PyPy
      
      * Reviewer suggestions
      
      * Remove unnecessary initialization
      
      * Add noexcept move and explicit fail throw
      
      * Optimize error_string creation
      
      * Fix typo
      
      * Revert noexcept
      
      * Fix merge conflict error
      
      * Abuse assignment operator
      
      * Revert operator abuse
      
      * See if we still need debug
      
      * Remove unnecessary mutable
      
      * Report "FATAL failure building pybind11::error_already_set error_string" and terminate process.
      
      * Try specifying noexcept again
      
      * Try explicit ctor
      
      * default ctor is noexcept too
      
      * Apply reviewer suggestions, simplify code, and make helper method private
      
      * Remove unnecessary include
      
      * Clang-Tidy fix
      
      * detail::obj_class_name(), fprintf with [STDERR], [STDOUT] tags, polish comments
      
      * consistently check m_lazy_what.empty() also in production builds
      
      * Make a comment slightly less ambiguous.
      
      * Bug fix: Remove `what();` from `restore()`.
      
      It sure would need to be guarded by `if (m_type)`, otherwise `what()` fails and masks that no error was set (see update unit test). But since `error_already_set` is copyable, there is no point in releasing m_type, m_value, m_trace, therefore we can just as well avoid the runtime overhead of force-building `m_lazy_what`, it may never be used.
      
      * Replace extremely opaque (unhelpful) error message with a truthful reflection of what we know.
      
      * Fix clang-tidy error [performance-move-constructor-init].
      
      * Make expected error message less specific.
      
      * Various changes.
      
      * bug fix: error_string(PyObject **, ...)
      
      * Putting back the two eager PyErr_NormalizeException() calls.
      
      * Change error_already_set() to call pybind11_fail() if the Python error indicator not set. The net result is that a std::runtime_error is thrown instead of error_already_set, but all tests pass as is.
      
      * Remove mutable (fixes oversight in the previous commit).
      
      * Normalize the exception only locally in error_string(). Python 3.6 & 3.7 test failures expected. This is meant for benchmarking, to determine if it is worth the trouble looking into the failures.
      
      * clang-tidy: use auto
      
      * Use `gil_scoped_acquire_local` in `error_already_set` destructor. See long comment.
      
      * For Python < 3.8: `PyErr_NormalizeException` before `PyErr_WriteUnraisable`
      
      * Go back to replacing the held Python exception with then normalized exception, if & when needed. Consistently document the side-effect.
      
      * Slightly rewording comment. (There were also other failures.)
      
      * Add 1-line comment for obj_class_name()
      
      * Benchmark code, with results in this commit message.
      
                function                   #calls  test time [s]  μs / call
      master    pure_unwind                729540      1.061      14.539876
                err_set_unwind_err_clear   681476      1.040      15.260282
                err_set_error_already_set  508038      1.049      20.640525
                error_already_set_restore  555578      1.052      18.933288
                pr1895_original_foo        244113      1.050      43.018168
                                                                             PR / master
      PR #1895  pure_unwind                736981      1.054      14.295685       98.32%
                err_set_unwind_err_clear   685820      1.045      15.237399       99.85%
                err_set_error_already_set  661374      1.046      15.811879       76.61%
                error_already_set_restore  669881      1.048      15.645176       82.63%
                pr1895_original_foo        318243      1.059      33.290806       77.39%
      
      master @ commit ad146b2a
      
      Running tests in directory "/usr/local/google/home/rwgk/forked/pybind11/tests":
      ============================= test session starts ==============================
      platform linux -- Python 3.9.10, 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
      collecting ... collected 5 items
      
      test_perf_error_already_set.py::test_perf[pure_unwind]
      PERF pure_unwind,729540,1.061,14.539876
      PASSED
      test_perf_error_already_set.py::test_perf[err_set_unwind_err_clear]
      PERF err_set_unwind_err_clear,681476,1.040,15.260282
      PASSED
      test_perf_error_already_set.py::test_perf[err_set_error_already_set]
      PERF err_set_error_already_set,508038,1.049,20.640525
      PASSED
      test_perf_error_already_set.py::test_perf[error_already_set_restore]
      PERF error_already_set_restore,555578,1.052,18.933288
      PASSED
      test_perf_error_already_set.py::test_perf[pr1895_original_foo]
      PERF pr1895_original_foo,244113,1.050,43.018168
      PASSED
      
      ============================== 5 passed in 12.38s ==============================
      
      pr1895 @ commit 8dff51d12e4af11aff415ee966070368fe606664
      
      Running tests in directory "/usr/local/google/home/rwgk/forked/pybind11/tests":
      ============================= test session starts ==============================
      platform linux -- Python 3.9.10, 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
      collecting ... collected 5 items
      
      test_perf_error_already_set.py::test_perf[pure_unwind]
      PERF pure_unwind,736981,1.054,14.295685
      PASSED
      test_perf_error_already_set.py::test_perf[err_set_unwind_err_clear]
      PERF err_set_unwind_err_clear,685820,1.045,15.237399
      PASSED
      test_perf_error_already_set.py::test_perf[err_set_error_already_set]
      PERF err_set_error_already_set,661374,1.046,15.811879
      PASSED
      test_perf_error_already_set.py::test_perf[error_already_set_restore]
      PERF error_already_set_restore,669881,1.048,15.645176
      PASSED
      test_perf_error_already_set.py::test_perf[pr1895_original_foo]
      PERF pr1895_original_foo,318243,1.059,33.290806
      PASSED
      
      ============================== 5 passed in 12.40s ==============================
      
      clang++ -o pybind11/tests/test_perf_error_already_set.os -c -std=c++17 -fPIC -fvisibility=hidden -Os -flto -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wnon-virtual-dtor -Wunused-result -isystem /usr/include/python3.9 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_perf_error_already_set.cpp
      
      clang++ -o lib/pybind11_tests.so -shared -fPIC -Os -flto -shared ...
      
      Debian clang version 13.0.1-3+build2
      Target: x86_64-pc-linux-gnu
      Thread model: posix
      
      * Changing call_repetitions_target_elapsed_secs to 0.1 for regular unit testing.
      
      * Adding in `recursion_depth`
      
      * Optimized ctor
      
      * Fix silly bug in recurse_first_then_call()
      
      * Add tests that have equivalent PyErr_Fetch(), PyErr_Restore() but no try-catch.
      
      * Add call_error_string to tests. Sample only recursion_depth 0, 100.
      
      * Show lazy-what speed-up in percent.
      
      * Include real_work in benchmarks.
      
      * Replace all PyErr_SetString() with generate_python_exception_with_traceback()
      
      * Better organization of test loops.
      
      * Add test_error_already_set_copy_move
      
      * Fix bug in newly added test (discovered by clang-tidy): actually use move ctor
      
      * MSVC detects the unreachable return
      
      * change test_perf_error_already_set.py back to quick mode
      
      * Inherit from std::exception (instead of std::runtime_error, which does not make sense anymore with the lazy what)
      
      * Special handling under Windows.
      
      * print with leading newline
      
      * Removing test_perf_error_already_set (copies are under https://github.com/rwgk/rwgk_tbx/commit/7765113fbb659e1ea004c5ba24fb578244bc6cfd).
      
      * Avoid gil and scope overhead if there is nothing to release.
      
      * Restore default move ctor. "member function" instead of "function" (note that "method" is Python terminology).
      
      * Delete error_already_set copy ctor.
      
      * Make restore() non-const again to resolve clang-tidy failure (still experimenting).
      
      * Bring back error_already_set copy ctor, to see if that resolves the 4 MSVC test failures.
      
      * Add noexcept to error_already_set copy & move ctors (as suggested by @skylion007 IIUC).
      
      * Trying one-by-one noexcept copy ctor for old compilers.
      
      * Add back test covering copy ctor. Add another simple test that exercises the copy ctor.
      
      * Exclude more older compilers from using the noexcept = default ctors. (The tests in the previous commit exposed that those are broken.)
      
      * Factor out & reuse gil_scoped_acquire_local as gil_scoped_acquire_simple
      
      * Guard gil_scoped_acquire_simple by _Py_IsFinalizing() check.
      
      * what() GIL safety
      
      * clang-tidy & Python 3.6 fixes
      
      * Use `gil_scoped_acquire` in dtor, copy ctor, `what()`. Remove `_Py_IsFinalizing()` checks (they are racy: https://github.com/python/cpython/pull/28525).
      
      * Remove error_scope from copy ctor.
      
      * Add `error_scope` to `get_internals()`, to cover the situation that `get_internals()` is called from the `error_already_set` dtor while a new Python error is in flight already. Also backing out `gil_scoped_acquire_simple` change.
      
      * Add `FlakyException` tests with failure triggers in `__init__` and `__str__`
      
      THIS IS STILL A WORK IN PROGRESS. This commit is only an important resting point.
      
      This commit is a first attempt at addressing the observation that `PyErr_NormalizeException()` completely replaces the original exception if `__init__` fails. This can be very confusing even in small applications, and extremely confusing in large ones.
      
      * Tweaks to resolve Py 3.6 and PyPy CI failures.
      
      * Normalize Python exception immediately in error_already_set ctor.
      
      For background see: https://github.com/pybind/pybind11/pull/1895#issuecomment-1135304081
      
      
      
      * Fix oversights based on CI failures (copy & move ctor initialization).
      
      * Move @pytest.mark.xfail("env.PYPY") after @pytest.mark.parametrize(...)
      
      * Use @pytest.mark.skipif (xfail does not work for segfaults, of course).
      
      * Remove unused obj_class_name_or() function (it was added only under this PR).
      
      * Remove already obsolete C++ comments and code that were added only under this PR.
      
      * Slightly better (newly added) comments.
      
      * Factor out detail::error_fetch_and_normalize. Preparation for producing identical results from error_already_set::what() and detail::error_string(). Note that this is a very conservative refactoring. It would be much better to first move detail::error_string into detail/error_string.h
      
      * Copy most of error_string() code to new error_fetch_and_normalize::complete_lazy_error_string()
      
      * Remove all error_string() code from detail/type_caster_base.h. Note that this commit includes a subtle bug fix: previously error_string() restored the Python error, which will upset pybind11_fail(). This never was a problem in practice because the two PyType_Ready() calls in detail/class.h do not usually fail.
      
      * Return const std::string& instead of const char * and move error_string() to pytypes.h
      
      * Remove gil_scope_acquire from error_fetch_and_normalize, add back to error_already_set
      
      * Better handling of FlakyException __str__ failure.
      
      * Move error_fetch_and_normalize::complete_lazy_error_string() implementation from pybind11.h to pytypes.h
      
      * Add error_fetch_and_normalize::release_py_object_references() and use from error_already_set dtor.
      
      * Use shared_ptr for m_fetched_error => 1. non-racy, copy ctor that does not need the GIL; 2. enables guard against duplicate restore() calls.
      
      * Add comments.
      
      * Trivial renaming of a newly introduced member function.
      
      * Workaround for PyPy
      
      * Bug fix (oversight). Only valgrind got this one.
      
      * Use shared_ptr custom deleter for m_fetched_error in error_already_set. This enables removing the dtor, copy ctor, move ctor completely.
      
      * Further small simplification. With the GIL held, simply deleting the raw_ptr takes care of everything.
      
      * IWYU cleanup
      
      ```
      iwyu version: include-what-you-use 0.17 based on Debian clang version 13.0.1-3+build2
      ```
      
      Command used:
      
      ```
      iwyu -c -std=c++17 -DPYBIND11_TEST_BOOST -Iinclude/pybind11 -I/usr/include/python3.9 -I/usr/include/eigen3 include/pybind11/pytypes.cpp
      ```
      
      pytypes.cpp is a temporary file: `#include "pytypes.h"`
      
      The raw output is very long and noisy.
      
      I decided to use `#include <cstddef>` instead of `#include <cstdio>` for `std::size_t` (iwyu sticks to the manual choice).
      
      I ignored all iwyu suggestions that are indirectly covered by `#include <Python.h>`.
      
      I manually verified that all added includes are actually needed.
      Co-authored-by: default avatarAaron Gokaslan <skylion.aaron@gmail.com>
      Co-authored-by: default avatarRalf W. Grosse-Kunstleve <rwgk@google.com>
      a05bc3d2
  24. 01 Jun, 2022 1 commit
    • Aaron Gokaslan's avatar
      perf: Add object rvalue overload for accessors. Enables reference stealing (#3970) · 58802de4
      Aaron Gokaslan authored
      * Add object rvalue overload for accessors. Enables reference stealing
      
      * Fix comments
      
      * Fix more comment typos
      
      * Fix bug
      
      * reorder declarations for clarity
      
      * fix another perf bug
      
      * should be static
      
      * future proof operator overloads
      
      * Fix perfect forwarding
      
      * Add a couple of tests
      
      * Remove errant include
      
      * Improve test documentation
      
      * Add dict test
      
      * add object attr tests
      
      * Optimize STL map caster and cleanup enum
      
      * Reorder to match declarations
      
      * adjust increfs
      
      * Remove comment
      
      * revert value change
      
      * add missing move
      58802de4
  25. 31 May, 2022 3 commits
  26. 28 May, 2022 1 commit
  27. 26 May, 2022 2 commits
  28. 24 May, 2022 1 commit
  29. 16 May, 2022 2 commits
  30. 05 May, 2022 1 commit
    • Ed Catmur's avatar
      Add anyset & frozenset, enable copying (cast) to std::set (#3901) · 68a0b2df
      Ed Catmur authored
      * Add frozenset, and allow it cast to std::set
      
      For the reverse direction, std::set still casts to set. This is in concordance with the behavior for sequence containers, where e.g. tuple casts to std::vector but std::vector casts to list.
      
      Extracted from #3886.
      
      * Rename set_base to any_set to match Python C API
      
      since this will be part of pybind11 public API
      
      * PR: static_cast, anyset
      
      * Add tests for frozenset
      
      and rename anyset methods
      
      * Remove frozenset default ctor, add tests
      
      Making frozenset non-default constructible means that we need to adjust pyobject_caster to not require that its value is default constructible, by initializing value to a nil handle.  This also allows writing C++ functions taking anyset, and is arguably a performance improvement, since there is no need to allocate an object that will just be replaced by load.
      
      Add some more tests, including anyset::empty, anyset::size, set::add and set::clear.
      
      * [pre-commit.ci] auto fixes from pre-commit.com hooks
      
      for more information, see https://pre-commit.ci
      
      
      
      * Add rationale to `pyobject_caster` default ctor
      
      * Remove ineffectual protected: access control
      Co-authored-by: default avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      68a0b2df