Commit 3a8c99c1 authored by PyBind11 Upstream's avatar PyBind11 Upstream Committed by Atkins, Charles Vernon
Browse files

pybind11 2020-10-29 (06a54018)

Code extracted from:

    https://github.com/pybind/pybind11.git

at commit 06a54018c8a9fd9a7be5f5b56414b5da9259f637 (master).

Upstream Shortlog
-----------------

Ahmed Sobhy (1):
      8d8d48c5 fix: do not use abi::__forced_unwind with libc++, even with gcc instead of clang (#2569)

Andrew J. Hesford (1):
      a3118130 pytypes.h: fix docs generation (#2220)

Andrey Dorozhkin (1):
      1817d211 Disable defining (v)snprintf as macro in modern Visual Studio

Ashley Whetter (1):
      8e85fadf Render `py::none` as `None` in docstrings

Axel Huebl (2):
      a6355b00 CMake: Add Python 3.8 to pybind11Tools (#1974)
      6ebfc4b2 Document CMAKE_CXX_STANDARD

B Krishna Chaitanya (1):
      71442438 Refactor: Extract Custom Type Casts related tests

Baljak (2):
      07e22593 Fix compilation with MinGW only (#2053)
      4f72ef84 Fix the use of MSVC in an MSYS environment (#2087)

Bjorn (1):
      d4d7ef5d Update pybind11Tools.cmake (#2419)

Boris Staletic (14):
      fe2a06e3 Pin breathe to 4.13.1
      dc9006db Use newer macOS image for python3 testing
      1376eb0e Free tstate on python 3.7+ on finalize_interpreter (#2020)
      ae2ee2a4 Avoid using deprecated API in python 3.9
      b2f52225 Rename embedded_module object's name (#2282)
      8b9eb964 Check for NULL in raw_str on Python3 (#2290)
      aa982e13 Small fixes in numpy.h (#2293)
      441e7770 Use new style __init__ in numpy docs (#2316)
      2819ce64 Avoid attr("__repr__") in initialize_generic (#2317)
      cc982ac1 fix: allow assignment of time points of resolutions other than that of a system clock (#2481)
      32bb9071 Avoid C-style casts for pointers in docs (#2487)
      d3c999c7 fix: rename `pybind11::module` to `pybind11::module_` (#2489)
      5ebc7816 Allow raw unions without base classes in is_accessible_base_of (#2320)
      4038542b Remove friend declaration of py::class_ in py::detail::generic_type (#2613)

Charles Brossollet (1):
      0f1d3bfe Add FAQ entry for dealing with long functions interruption (#2000)

Chuck Atkins (1):
      d730fbc0 Utilize CMake's language standards abstraction when possible

Ciro Santilli (1):
      b47efd35 Use defined for some preprocessor variables that might be undefined (#2476)

Clemens Sielaff (1):
      63df87fa Add lvalue ref-qualified cpp_function constructors (#2213)

Daniel Saxton (1):
      fb0a3a0e Fix broken README link (#2449)

Dariusz Suchojad (1):
      bed9080c  docs: Updated the link to the PDF docs (#2603) (#2605)

David Stone (1):
      5088364b Declare `operator==` and `operator!=` member functions const.

David Vo (1):
      5e6ec496 Add enum value to enum repr (#2126)

Dekken (1):
      1abc4a9d fix: doc typo, drop second use of 'without' (#2439)

Dustin Spicuzza (4):
      0dfffcf2 Add is_final to disallow inheritance from Python
      2c4cd841 Add AutoWIG to list of binding generators (#1990)
      1b0bf352 Throw TypeError when subclasses forget to call __init__ (#2152)
      6f3470f7 Add robotpy-build to list of tools (#2359)

Eric Cousineau (10):
      baf69345 Minor modifications to interrupt handling FAQ (#2007)
      2c30e0a1 cmake: Expose `PYBIND11_TEST_OVERRIDE` (#2218)
      53095730 operators: Move hash check to before mutations, tweak whitespace
      4e3d9fea operators: Explicitly expose `py::hash(py::self)`
      ebdd0d36 tests: Consolidate version (2 vs. 3) and platform (CPython vs. PyPy) checks (#2376)
      5a3ff723 ci: Remove "Setup Boost (macOS)" step (#2395)
      44fa79ca pytypes: Add Gotchas section about default-constructed wrapper types and py::none() (#2362)
      4e7c08da test_numpy_dtypes: Add test for py::vectorize() (#2260)
      d74be321 tests: Fix test override execution (#2512)
      c513b5e3 tests(CMakeLists): robustify against add'l versions of Boost (#2608)

Erick Matsen (1):
      b32b762c Fixing minor typo in basics.rst (#1984)

Florian Apolloner (1):
      fe1392d0 Silence Clang 10 compiler warnings. Fixes #2225. (#2294)

Francesco Biscani (2):
      deb3cb23 Add exception translation for std::overflow_error. (#1977)
      bd24155b Aligned allocation fix for clang-cl (#1988)

Fritz Reese (1):
      e8ad33bb Fix buffer_info for ctypes buffers (pybind#2502) (#2503)

Griffin Downs (1):
      a4cee36b Add vcpkg installation instructions (#1936)

Guilherme Dantas (1):
      8908552d typo

Hans Dembinski (2):
      c27a6e13 make builds with python tests and cpp tests fail if either one fails (#1967)
      bdf6a5e8 Report type names in return value policy-related cast exceptions (#1965)

Henry Fredrick Schreiner (2):
      11f756f5 fix: type bug intruduced in #2492
      e3774b76 tests: the condition was too look on xfail

Henry Schreiner (151):
      a38e5331 Fix CI, prepare test on Python 3.9 beta (#2233)
      d8c7ee00 ci: GHA basic format & pre-commit (#2309)
      ef057f12 test: support pypy2 7.3
      3d20b73e test: pass through C++ std for cmake test
      49007b7f test: fix warning/error on Python 2 in 14/17 mode
      a59c6de8 test: allow MSVC/Xcode to run the embed test
      73dc9786 style: avoid adding virtual environment directories
      b16347e5 ci: enable GHA testing
      8b0ccf76 style: adding pre-commit check-style.sh
      5c936d4b refactor: issue fixed upstream
      6f3e5e38 ci: keep travis from running twice
      6a80171c ci: Add clang builds & C++17
      e428a7f6 ci: fix clang warnings
      1f53c373 fix: C++17 mode on Clang may error
      44706717 fix: too many braces on clang 3.6
      5927c581 chore: update Catch
      aab70139 ci: cache, build wheels on macOS PyPy3
      78069057 ci: trim down Appveyor
      9521bc56 ci: drop parts from Travis
      1b880dfd ci: download EIGEN
      2ee1bcd9 ci: add GHA badge
      2fbbd510 ci: add gcc
      e450ea05 ci: add docker build to GHA
      249a13bd ci: move docs check to GHA
      ff39ad3f ci: include scipy for tests
      88b3e5c6 ci: nicer naming scheme
      a6324868 ci: Windows 2016 test
      c51b3f43 ci: change caching
      1491c94c ci: cmake Configure test (#2327)
      6ec1775f feat: drop CMake 3.6 and below, modernize CMake
      1b92cd17 fix: address review points from @YannickJadoul
      f64d5aa6 fix: typo for warning on C++17, support Win + 2.7
      1651c324 update: address review points
      e2a96890 format: add cmake-format to pre-commit
      94db5c5e format: apply cmake-format
      b8047245 fix: uninstall cleanup (#2346)
      1caf1d06 fix: check list validity and add missing file (#2352)
      df115977 chore: cleanup
      da803eb0 fix: duplicate target names removed
      ed6de125 format: include .in files
      c664d557 ci: better output / more config
      227170dc fix: better handling of PYBIND11_CPP_STANDARD
      0af7fe6c fix: typo in pybind11_add_module (#2374)
      f7abac66 fix: boost's include dir was listed first (#2384)
      1534e17e ci: include Python 3.9 RC1 (#2387)
      2e2de8c8 fix: add missing signature (#2363)
      cba4a985 ci: include Boost (#2393)
      a876aac2 tests: loosen test, not valid on some systems (#2399)
      4d9024ec tests: cleanup and ci hardening (#2397)
      64040997 docs: contrib/issue templates (#2377)
      cf0a6459 fix: throwing repr caused a segfault (#2389)
      1729aae9 feat: new FindPython support (#2370)
      04fdc44f tests: avoid putting build products into source directory (#2353)
      24dffe46 fix: PYBIND11_MASTER_PROJECT always ON (#2412)
      110e6c12 ci: reduce flakiness a little (#2418)
      a6887b60 docs: update changelog and versionadded
      2fa18431 docs: pin versions for readthedocs
      f31df738 docs: move CONTRIBUTING (#2402)
      56df3c46 fix: a couple more places where pybind11 is missing 11 (#2421)
      c58f7b74 fix: reduce target collision in add_submodule mode (#2423)
      5b59b7b2 ci: gha annotations (#2427)
      9b8cb020 fix: respect PYTHON_VERSION if set in classic mode (#2414)
      3a89bffa ci: harden chrono test, mark another macos 4.9 dev failure (#2448)
      72b06b86 ci: Eigen moved
      0dbda6e8 feat: py::pos_only (#2459)
      ce1a07ef fix: use classic extension handling unless otherwise requested (#2462)
      37f845a1 ci: disallow some common capitalization mistakes (#2472)
      621906b3 fix: support nvcc and test (#2461)
      f12ec00d feat: py::type::of<T>() and py::type::of(h) (#2364)
      8dc31c7b style: clang-tidy: llvm-namespace-comment
      5dfbe6f9 style: clang-tidy: modernize-use-override
      96e6a8d5 style: clang-tidy: readability-container-size-empty
      b342c373 style: clang-tidy: modernize-use-using
      b491b465 style: clang-tidy: modernize-use-equals-default
      ce88e940 style: clang-tidy: modernize-use-auto
      4d786408 style: clang-tidy: modernize-use-emplace
      e7bafc8e style: clang-tidy: default checks and fix bug in iostream deconstruction
      dabbbf31 fix: use OVERRIDE instead of OVERLOAD (#2490)
      41aa9260 refactor: replace .get_type with type::handle_of (#2492)
      fd61f503 feat: setup.py redesign and helpers (#2433)
      e37921d7 refactor: drop mkdoc and update changelog (#2491)
      dec33c29 docs: installing section (#2494)
      99ef2b84 docs: read version from pybind11 file (#2496)
      81555ce6 docs: Use README.rst in docs as home page (#2500)
      54831a9a fix: use svg to pdf converter instead of original solution
      d753b769 docs: corrected link to documentation
      8fa70e74 ci: fix broken documenation test (works on RtD) (#2506)
      87828c7e fix: typo in Windows C++17 support (#2507)
      4a288ab9 fix: Windows C++ latest (#2508)
      d0ed035c fix: AppleClang 12 warnings (#2510)
      e01f4924 fix: Add a nice CMake error when Interpreter component is missing. (#2519)
      3c7ef56b fix: warning on latest AppleClang (#2522)
      82dbc5b7 ci: releases (#2530)
      21902462 chore: bump to 2.6.0b1, beta release
      0fc5774c fix: beta does not have a dot in front (#2539)
      1994691a ci: download artifact issue
      319b9964 fix: metadata was adding quotes to distinfo
      01ad8920 ci: publish in two steps
      6d2d08db fix: conda-forge patch (#2540)
      b9d00273 feat: parallel compiler (#2521)
      5f9b1667 ci: label PRs with changelog needed (#2546)
      1bcd5f0a Update pr_merged.yml
      ca4127ce ci: fix labeler
      3488494a refactor: import check as a common function (#2526)
      560ed3e3 docs: fix odd spacing
      6bcd220c refactor: module -> module_ with typedef (#2544)
      2a2f5220 fix: find_import didn't work properly for classic tools (#2550)
      9a0c96dd feat: py::prepend tag (#1131)
      00edc300 fix: PYBIND11_OBJECT required pybind11 namespace (regression) (#2553)
      b6f37f67 docs: minor cleanup (#2555)
      49c389b7 ci: test on Windows 3.8 and 3.9 (mostly) (#2560)
      deba040b test: hide segfault (#2559)
      e4e5c49a docs: known issues (#2565)
      fae45325 ci: fix labeler
      f385eccd chore: bump to 2.6.0rc1
      c02f0ec6 fix: formatting issue
      fecef388 refactor: simpler followup to #2569 (#2572)
      d46f3322 fix: allow cmake varibles from Python calls to be cached (#2570)
      7d7309b8 ci: monitor dependencies
      cd2c25a2 ci: adjust labeler match pattern
      4f45052d ci: fix ci label
      993495c9 fix: Intel 18+ required (#2577)
      ae2e5a36 ci: try to get labeler to add needs changelog
      2f746eee ci: original labeler
      7c71dd38 ci: inverted labeler logic
      edda89ba fix: install to DATAROOTDIR instead of hardcoding share (#2584)
      c99d7f1c docs: PR template (#2580)
      2a263e08 docs: some final 2.6.0 updates (#2582)
      526a7733 ci: merged labels still missing
      a8c2e3ee fix: ipo should be off for debug or relwithdebinfo (#2590)
      645d8381 feat: typing support for helpers (#2588)
      c4a8b5bb chore: bump to 2.6.0rc2
      63f2deea chore: update Eigen
      f2008325 style: ssize_t -> py::ssize_t
      b72c79f9 fix: std::is_pod -> pybind11::detail::is_pod
      9ac604a3 fix: PyPy windows issue
      6bb71c48 fix: more intp asserts, reinterpret_cast
      ad2fe0ee fix: pypy3 windows extension issue
      a4221153 fix: new line in PYPY_VERSION
      8ae11fbf ci: add more runs
      2e31e466 docs: update for PyPy win 32 issue
      c50f90ec style: use Black everywhere (#2594)
      064362fb fix: allow the ABI string to be forced (#2602)
      c16da993 chore: bump to 2.6.0rc3
      09056717 fix: much better pdf (#2604)
      0b9acc40 fix: chapters in PDF again (#2606)
      120e2e21 docs: tiny typo
      4d037439 fix: missing identifier for Python 3.9
      ace4deb4 ci: add more jobs (#2610)
      139c05da ci: test on NumPy + Python 3.9 (#2628)
      06a54018 fix: min macos (#2622)

Holger Kohr (1):
      fbc75636 Add py::object casting example to embedding docs (#2466)

Hyrum Wright (1):
      961b2e62 fix: ensure the GIL is held when copying a function. (#2545)

Isuru Fernando (3):
      37352491 Install headers using both headers and package_data (#1995)
      e107fc2a Fix setuptools record of headers
      0d70f0e1 PyPy3 support (#2146)

JGamache-autodesk (1):
      37d04abd Fixes #1295: Handle debug interpreter (#2025)

James R. Barlow (1):
      3618bea2 Add and document py::error_already_set::discard_as_unraisable()

Jason Rhinelander (1):
      be0d8045 Support keyword-only arguments

Jay Soffian (1):
      01453b05 fix (setup_helpers): fix bug in _add_lflags (#2586)

Jeremy Nimmer (1):
      759221f5 Obey __cpp_sized_deallocation and __cpp_aligned_new

Kota Yamaguchi (1):
      e2488698 Fix undefined memoryview format (#2223)

Liam Keegan (1):
      c4fd1fd9 CMake improvement: support windows python on msys (#2312)

Lin Hsu (1):
      d031efe7 Typo

MRocholl (3):
      00c462d1 find library path to libclang.so via glob command in /usr/lib/llvm-* and set it
      9358e30d change set_path to set_file
      b14aeb7c fix typo in sorted function call argument reverse

Mana Borwornpadungkitti (1):
      6edd0e6d fix: Reject keyword argument `None` with `.none(false)` (#2611)

Marcin Wojdyr (1):
      8e40e389 cast pointer to std::tuple and std::pair (#2334)

Matthew Dawkins (1):
      6f11347a Prevent cmake error when prefix empty (#1986)

Matthijs van der Burgh (1):
      b5240089 Deepcopy documentation (#2242)

Michael Goulding (1):
      fb042d69 Fix warning C26817 on copying in `for (auto vh : value_and_holder(...))` (#2382)

Mosalam Ebrahimi (1):
      7dd2bdb0 docs: fix typo (#2405)

Nicholas Musolino (1):
      02c83dba Propagate exceptions in sequence::size() (#2076)

Nils Berg (1):
      819802da Fix a memory leak when creating Python3 modules. (#2019)

Nils Leif Fischer (1):
      141e8cc0 Fix uninitialized-variables cmake warnings

Orell Garten (1):
      9ed8b440 Change __init__(self) to __new__(cls)

Paul Fultz II (1):
      69821d9e Disable testing when using BUILD_TESTING (#1682)

Ralf W. Grosse-Kunstleve (8):
      4697149d Allows users to specialize polymorphic_type_hook with std::enable_if.
      f6e543b1 Adding a default virtual destructor to Animal type in test_tagbased_polymorphic.cpp.
      96c67636 test_builtin_casters.py test_string_view: Python 2 c++17, c++2a compatibility. (#2314)
      17320463 Adding tests specifically to exercise pybind11::str::raw_str. (#2366)
      cd856992 Using recently added `pytest.PY2` instead of `str is bytes`. (#2396)
      3c061f21 Fixing `pybind11::bytes()` ambiguous conversion issue.
      d159a563 static allocation for PyModuleDef, to avoid leak check errors. (#2413)
      8290a5a0 clang -Wnon-virtual-dtor compatibility (#2626)

Riccardo Bertossa (1):
      6c29cbf8 misleading comment corrected (strides in buffer_info is bytes and not number of entries) (#1958)

Rickard Hallerbäck (1):
      5a8ec8e5 Include what is used in pybind11.h (#2499)

Riyaz Haque (1):
      2b6b98e2 Bugfix/Check actual value when deregistering pybind11 instance (#2252)

Robert Haschke (2):
      370a2ae2 Declare call_impl() as && (#2057)
      f2226aef Allow perfect forwarding of method args (#2048)

Sebastian Gsänger (1):
      a83d69e7 test pair-copyability on C++17 upwards (#1886)

Sebastian Koslowski (2):
      dc65d661 support for readonly buffers (#863) (#1466)
      a86ac538 rename args_kw_only to kwonly

Sergei Izmailov (7):
      22b25040 Render full numpy numeric names (e.g. numpy.int32)
      57070fb0 Render py::iterator/py::iterable as Iterator/Iterable in docstrings
      90d99b56 Render pybind11::array as numpy.ndarray in docstrings
      4f1531c4 Render `py::int_` as `int` in docstrings
      ab323e04 Test py::iterable/py::iterator representation in docstrings
      7b067cc3 Set __hash__ to None for types that defines __eq__, but not __hash__ (#2291)
      4c36fb7b [DOC] avoid C++ types in docstrings (#2441)

Simeon Ehrig (1):
      c776e9ef Fix compiler error with MSVC 17 and CUDA 10.2

Takahiro Ishikawa (1):
      3618807d Fix python.lib name

Thomas Köppe (3):
      eeb10448 [common.h] Mark entry point as "unused".
      1e14930d [common.h] Mark another entry point as "unused".
      f2e79986 [common.h] Mark another entry point as "unused". (#2625)

Valentin Boettcher (1):
      3be085d1 docs: typo prefix -> suffix (#2593)

Vemund Handeland (1):
      6e39b765 Add C++20 char8_t/u8string support (#2026)

Wenzel Jakob (22):
      dfde1554 begin working on next version
      61e4f118 numpy.h: minor preprocessor fix suggested by @chaekwan
      a6064822 Revert "numpy.h: minor preprocessor fix suggested by @chaekwan"
      fb910ae9 Revert "Fix a memory leak when creating Python3 modules. (#2019)"
      b4e5d582 undo #define copysign in pyconfig.h
      f9f3bd71 Use C++17 fold expressions when casting tuples and argument lists (#2043)
      2fda9d5d Travis CI fix (MacOS, Py3)
      4c206e8c bindings for import_error exception
      bf2b0314 Handle cases where binding code immediately throws py::error_already_set
      bb9c91cc pybind11Tools.cmake: search for Python 3.9
      3b1dbeba v2.5.0 release
      02348716 begin working on next version
      a54eab92 Revert "Change __init__(self) to __new__(cls)"
      8c0cd944 ignore another type of visual studio project file
      fc3a4490 Minor clarification (@AntoinePrv, #2083)
      36c666f0 pybind11_add_module(): OPT_SIZE target
      064a03a4 main CMakeLists.txt file: be less noisy
      3232e59b Check if module file extension could be queried correctly (#2538)
      2bc62dc8 updated credits
      7f9445a6 Thanks, Google!
      59a2ac27 v2.6.0 release
      86d3e9eb begin working towards a future v2.6.1 patch release

Wink Saville (1):
      7c26c718 Fix mispelling in basics.rst (#2614)

Yannick Jadoul (30):
      55ff4642 Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load (#1976)
      805c5862 Adding method names to cpp_function constructor calls in enum_base
      d54d6d8c Adding pybind11::cast overload for rvalue references (#1260)
      f980d76d Change NAMESPACE_* macros into PYBIND11_NAMESPACE_* (#2283)
      964ab956 Fix DeprecationWarning about 'invalid escape sequence' in tools/docs Python scripts (#2281)
      3e448c0b Enable py::ellipsis on Python 2 (#2360)
      4493751a Fix new-style __init__ usage in numpy docs (#2426)
      b3d8fec0 Adapt code example in advanced/classes.rst to new handling of forgetting to call the superclass __init__ (#2429)
      43f390ad Add note that VS2017 requires /permissive- to build in C++17 mode (#2431)
      a2bb297b Throw exception on returning a unique_ptr or shared_ptr nullptr (or any other holder type) from py::init, rather than crashing (#2430)
      03b3d59d tests: fix CI by including <algorithm> to stop MSVC from complaining about std::count_if in tests/test_sequences_and_iterators.cpp (#2435)
      6a192781 Fix bug roundtripping datetime.time objects after midnight in eastern hemisphere timezones (#2417) (#2438)
      fe9ee86b Add check if `str(handle)` correctly converted the object, and throw py::error_already_set if not (bis) (#2477)
      9df13835 Stop py::array_t arguments from accepting arrays that do not match the C- or F-contiguity flags (#2484)
      d65e34d6 Resolve empty statement warning when using PYBIND11_OVERLOAD_PURE_NAME and PYBIND11_OVERLOAD_PURE (#2325)
      16f199f8 Change base parameter type in register_exception and exception constructor from PyObject* to handle (#2467)
      c72708a7 Moving tp_class access, and consistent fully-qualified naming for PyPy, to detail::get_tp_name (#2520)
      07b069a5 Unify Python 2 & 3 py::module constructor, and make contructor with pre-allocated PyModuleDef private (#2534)
      56784c4f Add unchecked_reference::operator() and operator[] to overload resolution of unchecked_mutable_reference (#2514)
      9796fe98 feat: vectorize functions with void return type (#1969)
      b70894df docs: add std::valarray to docs/advanced/cast/stl.rst (#2547)
      14112077 chore: drop support for PyPy < 7.3.1 and clean up old PyPy workarounds (#2456)
      f537093a Fail on passing py::object with wrong Python type to py::object subclass using PYBIND11_OBJECT macro (#2349)
      71aea49b Check scope's __dict__ instead of using hasattr when registering classes and exceptions (#2335)
      0c5cc031 feat: deprecate public constructors of module_ class (#2552)
      1914b7d3 Shorten PYBIND11_EMBEDDED_MODULE macro implementation by using PYBIND11_CATCH_INIT_EXCEPTIONS (#2579)
      99773fc5 fix: throw error_already_set in py::len on failing PyObject_Length (#2575)
      493649f9 fix: valgrind-detected after-freeing access of PyMethodDef (macOS Python 3.9.0 segfaults) (#2576)
      6364b732 fix: test_factory_constructors.py failure triggered by test_register_duplicate_class (#2564)
      3a37d338 Add __builtins__ to globals argument of `py::exec` and `py::eval` if not present (#2616)

acxz (1):
      6f6e9394 feat: add uninstall target for CMake (#2265)

andriish (2):
      38370a87 fix: support NVIDIA-PGI HPC SDK (#2475)
      59323a97 ci: update PGI to 20.9 (#2566)

fatvlady (4):
      a3daf87d Add failing optional test
      556277d6 Fix optional dereference type deduction
      8c06b954 Fix compile error on GCC4.8
      f99ff736 Add additional check to be more compliant with other casters

fwjavox (1):
      e97c735f stl_bind: add binding for std::vector::clear (#2074)

jbarlow83 (3):
      4d90f1a1 Add error_scope to py::class_::dealloc() to protect destructor calls (#2342)
      b8863698 Improve documentation of Python and C++ exceptions (#2408)
      49cdb70a docs: use sorted(glob()) in example setup.py (#2561)

marc-chiesa (1):
      830adda8 Modified Vector STL bind initialization from a buffer type with optimization for simple arrays (#2298)

methylDragon (1):
      d96c3451 Fix docs typo

michalsustr (1):
      3bd0d7a8 Add note about specifying custom base class for Exceptions. (#2465)

nicolov (1):
      de5a29c0 Fix build with -Wmissing-prototypes (#1954)

peter (1):
      03f9e4a8 Fix compilation with clang-cl

tuxmaster5000 (1):
      7e0a4fb7 Fix for #2168 (#2299)

xkszltl (1):
      134a2ec3 Add `.git` suffix to URL because only GitHub itself works without it. (#2319)
parent 90e56b2b
Loading
Loading
Loading
Loading
+68 −10
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@

#include "cast.h"

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

/// \addtogroup annotations
/// @{
@@ -23,6 +23,9 @@ struct is_method { handle class_; is_method(const handle &c) : class_(c) { } };
/// Annotation for operators
struct is_operator { };

/// Annotation for classes that cannot be subclassed
struct is_final { };

/// Annotation for parent scope
struct scope { handle value; scope(const handle &s) : value(s) { } };

@@ -37,8 +40,9 @@ struct sibling { handle value; sibling(const handle &value) : value(value.ptr())

/// Annotation indicating that a class derives from another given type
template <typename T> struct base {

    PYBIND11_DEPRECATED("base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
    base() { }
    base() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
};

/// Keep patient alive while nurse lives
@@ -58,7 +62,7 @@ struct metaclass {
    handle value;

    PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
    metaclass() {}
    metaclass() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute

    /// Override pybind11's default metaclass
    explicit metaclass(handle value) : value(value) { }
@@ -70,6 +74,9 @@ struct module_local { const bool value; constexpr module_local(bool v = true) :
/// Annotation to mark enums as an arithmetic type
struct arithmetic { };

/// Mark a function for addition at the beginning of the existing overload chain instead of the end
struct prepend { };

/** \rst
    A call policy which places one or more guard variables (``Ts...``) around the function call.

@@ -110,7 +117,7 @@ struct call_guard<T, Ts...> {

/// @} annotations

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
/* Forward declarations */
enum op_id : int;
enum op_type : int;
@@ -134,7 +141,8 @@ struct argument_record {
struct function_record {
    function_record()
        : is_constructor(false), is_new_style_constructor(false), is_stateless(false),
          is_operator(false), has_args(false), has_kwargs(false), is_method(false) { }
          is_operator(false), is_method(false), has_args(false),
          has_kwargs(false), has_kw_only_args(false), prepend(false) { }

    /// Function name
    char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
@@ -172,18 +180,30 @@ struct function_record {
    /// True if this is an operator (__add__), etc.
    bool is_operator : 1;

    /// True if this is a method
    bool is_method : 1;

    /// True if the function has a '*args' argument
    bool has_args : 1;

    /// True if the function has a '**kwargs' argument
    bool has_kwargs : 1;

    /// True if this is a method
    bool is_method : 1;
    /// True once a 'py::kw_only' is encountered (any following args are keyword-only)
    bool has_kw_only_args : 1;

    /// True if this function is to be inserted at the beginning of the overload resolution chain
    bool prepend : 1;

    /// Number of arguments (including py::args and/or py::kwargs, if present)
    std::uint16_t nargs;

    /// Number of trailing arguments (counted in `nargs`) that are keyword-only
    std::uint16_t nargs_kw_only = 0;

    /// Number of leading arguments (counted in `nargs`) that are positional-only
    std::uint16_t nargs_pos_only = 0;

    /// Python method object
    PyMethodDef *def = nullptr;

@@ -201,7 +221,7 @@ struct function_record {
struct type_record {
    PYBIND11_NOINLINE type_record()
        : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false),
          default_holder(true), module_local(false) { }
          default_holder(true), module_local(false), is_final(false) { }

    /// Handle to the parent scope
    handle scope;
@@ -254,6 +274,9 @@ struct type_record {
    /// Is the class definition local to the module shared object?
    bool module_local : 1;

    /// Is the class inheritable from python classes?
    bool is_final : 1;

    PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *)) {
        auto base_info = detail::get_type_info(base, false);
        if (!base_info) {
@@ -353,12 +376,20 @@ template <> struct process_attribute<is_new_style_constructor> : process_attribu
    static void init(const is_new_style_constructor &, function_record *r) { r->is_new_style_constructor = true; }
};

inline void process_kw_only_arg(const arg &a, function_record *r) {
    if (!a.name || strlen(a.name) == 0)
        pybind11_fail("arg(): cannot specify an unnamed argument after an kw_only() annotation");
    ++r->nargs_kw_only;
}

/// Process a keyword argument attribute (*without* a default value)
template <> struct process_attribute<arg> : process_attribute_default<arg> {
    static void init(const arg &a, function_record *r) {
        if (r->is_method && r->args.empty())
            r->args.emplace_back("self", nullptr, handle(), true /*convert*/, false /*none not allowed*/);
        r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none);

        if (r->has_kw_only_args) process_kw_only_arg(a, r);
    }
};

@@ -390,6 +421,22 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
#endif
        }
        r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none);

        if (r->has_kw_only_args) process_kw_only_arg(a, r);
    }
};

/// Process a keyword-only-arguments-follow pseudo argument
template <> struct process_attribute<kw_only> : process_attribute_default<kw_only> {
    static void init(const kw_only &, function_record *r) {
        r->has_kw_only_args = true;
    }
};

/// Process a positional-only-argument maker
template <> struct process_attribute<pos_only> : process_attribute_default<pos_only> {
    static void init(const pos_only &, function_record *r) {
        r->nargs_pos_only = static_cast<std::uint16_t>(r->args.size());
    }
};

@@ -416,6 +463,11 @@ struct process_attribute<dynamic_attr> : process_attribute_default<dynamic_attr>
    static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; }
};

template <>
struct process_attribute<is_final> : process_attribute_default<is_final> {
    static void init(const is_final &, type_record *r) { r->is_final = true; }
};

template <>
struct process_attribute<buffer_protocol> : process_attribute_default<buffer_protocol> {
    static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; }
@@ -431,6 +483,12 @@ struct process_attribute<module_local> : process_attribute_default<module_local>
    static void init(const module_local &l, type_record *r) { r->module_local = l.value; }
};

/// Process a 'prepend' attribute, putting this at the beginning of the overload chain
template <>
struct process_attribute<prepend> : process_attribute_default<prepend> {
    static void init(const prepend &, function_record *r) { r->prepend = true; }
};

/// Process an 'arithmetic' attribute for enums (does nothing here)
template <>
struct process_attribute<arithmetic> : process_attribute_default<arithmetic> {};
@@ -489,5 +547,5 @@ constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
    return named == 0 || (self + named + has_args + has_kwargs) == nargs;
}

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
+59 −21
Original line number Diff line number Diff line
@@ -11,7 +11,30 @@

#include "detail/common.h"

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

PYBIND11_NAMESPACE_BEGIN(detail)

// Default, C-style strides
inline std::vector<ssize_t> c_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
    auto ndim = shape.size();
    std::vector<ssize_t> strides(ndim, itemsize);
    if (ndim > 0)
        for (size_t i = ndim - 1; i > 0; --i)
            strides[i - 1] = strides[i] * shape[i];
    return strides;
}

// F-style strides; default when constructing an array_t with `ExtraFlags & f_style`
inline std::vector<ssize_t> f_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
    auto ndim = shape.size();
    std::vector<ssize_t> strides(ndim, itemsize);
    for (size_t i = 1; i < ndim; ++i)
        strides[i] = strides[i - 1] * shape[i - 1];
    return strides;
}

PYBIND11_NAMESPACE_END(detail)

/// Information record describing a Python buffer object
struct buffer_info {
@@ -21,14 +44,15 @@ struct buffer_info {
    std::string format;           // For homogeneous buffers, this should be set to format_descriptor<T>::format()
    ssize_t ndim = 0;             // Number of dimensions
    std::vector<ssize_t> shape;   // Shape of the tensor (1 entry per dimension)
    std::vector<ssize_t> strides; // Number of entries between adjacent entries (for each per dimension)
    std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension)
    bool readonly = false;        // flag to indicate if the underlying storage may be written to

    buffer_info() { }
    buffer_info() = default;

    buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
                detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in)
                detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
    : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
      shape(std::move(shape_in)), strides(std::move(strides_in)) {
      shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
        if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size())
            pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
        for (size_t i = 0; i < (size_t) ndim; ++i)
@@ -36,20 +60,31 @@ struct buffer_info {
    }

    template <typename T>
    buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in)
    : buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in)) { }
    buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
    : buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) { }

    buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
    : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { }

    buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size)
    : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}) { }
    template <typename T>
    buffer_info(T *ptr, ssize_t size, bool readonly=false)
    : buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) { }

    template <typename T>
    buffer_info(T *ptr, ssize_t size)
    : buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size) { }
    buffer_info(const T *ptr, ssize_t size, bool readonly=true)
    : buffer_info(const_cast<T*>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) { }

    explicit buffer_info(Py_buffer *view, bool ownview = true)
    : buffer_info(view->buf, view->itemsize, view->format, view->ndim,
            {view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}) {
        this->view = view;
            {view->shape, view->shape + view->ndim},
            /* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
             * ignore this flag and return a view with NULL strides.
             * When strides are NULL, build them manually.  */
            view->strides
            ? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
            : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
            view->readonly) {
        this->m_view = view;
        this->ownview = ownview;
    }

@@ -68,27 +103,30 @@ struct buffer_info {
        ndim = rhs.ndim;
        shape = std::move(rhs.shape);
        strides = std::move(rhs.strides);
        std::swap(view, rhs.view);
        std::swap(m_view, rhs.m_view);
        std::swap(ownview, rhs.ownview);
        readonly = rhs.readonly;
        return *this;
    }

    ~buffer_info() {
        if (view && ownview) { PyBuffer_Release(view); delete view; }
        if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; }
    }

    Py_buffer *view() const { return m_view; }
    Py_buffer *&view() { return m_view; }
private:
    struct private_ctr_tag { };

    buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
                detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in)
    : buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in)) { }
                detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
    : buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { }

    Py_buffer *view = nullptr;
    Py_buffer *m_view = nullptr;
    bool ownview = false;
};

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)

template <typename T, typename SFINAE = void> struct compare_buffer_info {
    static bool compare(const buffer_info& b) {
@@ -104,5 +142,5 @@ template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_
    }
};

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
+160 −73

File changed.

Preview size limit exceeded, changes collapsed.

+20 −13
Original line number Diff line number Diff line
@@ -27,15 +27,15 @@
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
#endif

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)

template <typename type> class duration_caster {
public:
    typedef typename type::rep rep;
    typedef typename type::period period;
    using period = typename type::period;

    typedef std::chrono::duration<uint_fast32_t, std::ratio<86400>> days;
    using days = std::chrono::duration<uint_fast32_t, std::ratio<86400>>;

    bool load(handle src, bool) {
        using namespace std::chrono;
@@ -98,7 +98,7 @@ public:
// This is for casting times on the system clock into datetime.datetime instances
template <typename Duration> class type_caster<std::chrono::time_point<std::chrono::system_clock, Duration>> {
public:
    typedef std::chrono::time_point<std::chrono::system_clock, Duration> type;
    using type = std::chrono::time_point<std::chrono::system_clock, Duration>;
    bool load(handle src, bool) {
        using namespace std::chrono;

@@ -140,7 +140,7 @@ public:
        }
        else return false;

        value = system_clock::from_time_t(std::mktime(&cal)) + msecs;
        value = time_point_cast<Duration>(system_clock::from_time_t(std::mktime(&cal)) + msecs);
        return true;
    }

@@ -150,21 +150,28 @@ public:
        // Lazy initialise the PyDateTime import
        if (!PyDateTimeAPI) { PyDateTime_IMPORT; }

        std::time_t tt = system_clock::to_time_t(time_point_cast<system_clock::duration>(src));
        // Get out microseconds, and make sure they are positive, to avoid bug in eastern hemisphere time zones
        // (cfr. https://github.com/pybind/pybind11/issues/2417)
        using us_t = duration<int, std::micro>;
        auto us = duration_cast<us_t>(src.time_since_epoch() % seconds(1));
        if (us.count() < 0)
            us += seconds(1);

        // Subtract microseconds BEFORE `system_clock::to_time_t`, because:
        // > If std::time_t has lower precision, it is implementation-defined whether the value is rounded or truncated.
        // (https://en.cppreference.com/w/cpp/chrono/system_clock/to_time_t)
        std::time_t tt = system_clock::to_time_t(time_point_cast<system_clock::duration>(src - us));
        // this function uses static memory so it's best to copy it out asap just in case
        // otherwise other code that is using localtime may break this (not just python code)
        std::tm localtime = *std::localtime(&tt);

        // Declare these special duration types so the conversions happen with the correct primitive types (int)
        using us_t = duration<int, std::micro>;

        return PyDateTime_FromDateAndTime(localtime.tm_year + 1900,
                                          localtime.tm_mon + 1,
                                          localtime.tm_mday,
                                          localtime.tm_hour,
                                          localtime.tm_min,
                                          localtime.tm_sec,
                                          (duration_cast<us_t>(src.time_since_epoch() % seconds(1))).count());
                                          us.count());
    }
    PYBIND11_TYPE_CASTER(type, _("datetime.datetime"));
};
@@ -180,5 +187,5 @@ template <typename Rep, typename Period> class type_caster<std::chrono::duration
: public duration_caster<std::chrono::duration<Rep, Period>> {
};

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#  undef I
#endif

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
    static constexpr const char c = format_descriptor<T>::c;
@@ -32,7 +32,7 @@ template <typename T> constexpr const char format_descriptor<

#endif

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)

template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
    static constexpr bool value = true;
@@ -61,5 +61,5 @@ public:

    PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
};
NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
Loading