1. 10 Feb, 2022 1 commit
  2. 08 Feb, 2022 1 commit
  3. 12 Jan, 2022 1 commit
  4. 15 Nov, 2021 1 commit
    • Trigve's avatar
      [master] Wrong caching of overrides (#3465) · afdc09de
      Trigve authored
      * override: Fix wrong caching of the overrides
      
      There was a problem when the python type, which was stored in override
      cache for C++ functions, was destroyed and  the record wasn't removed from the
      override cache. Therefor, dangling pointer was stored there. Then when the
      memory was reused and new type was allocated at the given address and the
      method with the same name (as previously stored in the cache) was actually
      overridden in python, it would wrongly find it in the override cache for C++
      functions and therefor override from python wouldn't be called.
      The fix is to erase the type from the override cache when the type is destroyed.
      
      * test: Pass by const ref instead of by value (clang-tidy)
      
      * test: Rename classes and move to different files
      
      Rename the classes and files so they're no too generic. Also, better place to
      test the stuff is in test_virtual_functions.cpp/.py as we're basically testing
      the virtual functions/trampolines.
      
      * Add TODO for erasure code
      
      * [pre-commit.ci] auto fixes from pre-commit.com hooks
      
      for more information, see https://pre-commit.ci
      
      Co-authored-by: default avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      afdc09de
  5. 22 Oct, 2021 1 commit
  6. 09 Sep, 2021 1 commit
    • Ralf W. Grosse-Kunstleve's avatar
      CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) · 6abf2baa
      Ralf W. Grosse-Kunstleve authored
      * Adding google-explicit-constructor to .clang-tidy
      
      * clang-tidy explicit attr.h (all automatic)
      
      * clang-tidy explicit cast.h (all automatic)
      
      * clang-tidy detail/init.h (1 NOLINT)
      
      * clang-tidy detail/type_caster_base.h (2 NOLINT)
      
      * clang-tidy pybind11.h (7 NOLINT)
      
      * clang-tidy detail/common.h (3 NOLINT)
      
      * clang-tidy detail/descr.h (2 NOLINT)
      
      * clang-tidy pytypes.h (23 NOLINT, only 1 explicit)
      
      * clang-tidy eigen.h (7 NOLINT, 0 explicit)
      
      * Adding 2 explicit in functional.h
      
      * Adding 4 explicit in iostream.h
      
      * clang-tidy numpy.h (1 NOLINT, 1 explicit)
      
      * clang-tidy embed.h (0 NOLINT, 1 explicit)
      
      * clang-tidy tests/local_bindings.h (0 NOLINT, 4 explicit)
      
      * clang-tidy tests/pybind11_cross_module_tests.cpp (0 NOLINT, 1 explicit)
      
      * clang-tidy tests/pybind11_tests.h (0 NOLINT, 2 explicit)
      
      * clang-tidy tests/test_buffers.cpp (0 NOLINT, 2 explicit)
      
      * clang-tidy tests/test_builtin_casters.cpp (0 NOLINT, 4 explicit)
      
      * clang-tidy tests/test_class.cpp (0 NOLINT, 6 explicit)
      
      * clang-tidy tests/test_copy_move.cpp (0 NOLINT, 7 explicit)
      
      * clang-tidy tests/test_embed/external_module.cpp (0 NOLINT, 1 explicit)
      
      * clang-tidy tests/test_embed/test_interpreter.cpp (0 NOLINT, 1 explicit)
      
      * clang-tidy tests/object.h (0 NOLINT, 2 explicit)
      
      * clang-tidy batch of fully automatic fixes.
      
      * Workaround for MSVC 19.16.27045.0 C++17 Python 2 C++ syntax error.
      6abf2baa
  7. 06 Aug, 2021 1 commit
    • Aaron Gokaslan's avatar
      maint(clang-tidy): Bugprone enable checks (#3166) · 3893f37b
      Aaron Gokaslan authored
      * 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
      3893f37b
  8. 09 Jul, 2021 1 commit
  9. 22 Jun, 2021 1 commit
    • Aaron Gokaslan's avatar
      fix(clang-tidy): performance fixes applied in tests and CI (#3051) · dac74ebd
      Aaron Gokaslan authored
      * 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
      dac74ebd
  10. 03 Oct, 2020 1 commit
  11. 15 Sep, 2020 4 commits
  12. 12 Sep, 2020 1 commit
    • andriish's avatar
      fix: support NVIDIA-PGI HPC SDK (#2475) · 38370a87
      andriish authored
      
      
      * Added guards to the includes
      
      Added new CI config
      
      Added new trigger
      
      Changed CI workflow name
      
      Debug CI
      
      Debug CI
      
      Debug CI
      
      Debug CI
      
      Added flags fro PGI
      
      Disable Eigen
      
      Removed tests that fail
      
      Uncomment lines
      
      * fix: missing include
      
      fix: minor style cleanup
      
      tests: support skipping
      
      ci: remove and tighten a bit
      
      fix: try msvc workaround for pgic
      
      * tests: split up prealoc tests
      
      * fix: PGI compiler fix
      
      * fix: PGI void_t only
      
      * fix: try to appease nvcc
      
      * ci: better ordering for slow tests
      
      * ci: minor improvements to testing
      
      * ci: Add NumPy to testing
      
      * ci: Eigen generates CUDA warnings / PGI errors
      
      * Added CentOS7 back for a moment
      
      * Fix YAML
      
      * ci: runs-on missing
      
      * centos7 is missing pytest
      
      * ci: use C++11 on CentOS 7
      
      * ci: test something else
      
      * Try just adding flags on CentOS 7
      
      * fix: CentOS 7
      
      * refactor: move include to shared location
      
      * Added verbose flag
      
      * Try to use system cmake3 on CI
      
      * Try to use system cmake3 on CI, attempt2
      
      * Try to use system cmake3 on CI, attempt3
      
      * tests: not finding pytest should be a warning, not a fatal error
      
      * tests: cleanup
      
      * Weird issue?
      
      * fix: final polish
      Co-authored-by: default avatarAndrii Verbytskyi <andrii.verbytskyi@mpp.mpg.de>
      Co-authored-by: default avatarHenry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: default avatarAndrii Verbytskyi <averbyts@cern.ch>
      38370a87
  13. 10 Sep, 2020 1 commit
    • Henry Schreiner's avatar
      fix: support nvcc and test (#2461) · 621906b3
      Henry Schreiner authored
      * fix: support nvcc and test
      
      * fixup! fix: support nvcc and test
      
      * docs: mention what compilers fail
      
      * fix: much simpler logic
      
      * refactor: slightly faster / clearer
      621906b3
  14. 26 Jul, 2020 1 commit
  15. 06 Apr, 2019 1 commit
    • Henry Schreiner's avatar
      CI fixes (#1744) · ae951ca0
      Henry Schreiner authored
      * Fix warning that not including a cmake source or build dir will be a fatal error (it is now on newest CMakes)
          * Fixes appveyor
      * Travis uses CMake 3.9 for more than a year now
      * Travis dropped sudo: false in December
      * Dropping Sphinx 2
      - clang7: Suppress self-assign warnings; fix missing virtual dtors
      - pypy:
        - Keep old version (newer stuff breaks)
        - Pin packages to extra index for speed
      - travis:
        - Make docker explicit; remove docker if not needed
        - Make commands more verbose (for debugging / repro)
        - Make Ubuntu dist explicit per job
      - Fix Windows
      - Add names to travis
      ae951ca0
  16. 11 Sep, 2018 1 commit
  17. 18 May, 2018 1 commit
  18. 10 Mar, 2018 1 commit
    • Jason Rhinelander's avatar
      Improve macro type handling for types with commas · e88656ab
      Jason Rhinelander authored
      - PYBIND11_MAKE_OPAQUE now takes ... rather than a single argument and
        expands it with __VA_ARGS__; this lets templated, comma-containing
        types get through correctly.
      - Adds a new macro PYBIND11_TYPE() that lets you pass the type into a
        macro as a single argument, such as:
      
            PYBIND11_OVERLOAD(PYBIND11_TYPE(R<1,2>), PYBIND11_TYPE(C<3,4>), func)
      
        Unfortunately this only works for one macro call: to forward the
        argument on to the next macro call (without the processor breaking it
        up again) requires also adding the PYBIND11_TYPE(...) to type macro
        arguments in the PYBIND11_OVERLOAD_... macro chain.
      - updated the documentation with these two changes, and use them at a couple
        places in the test suite to test that they work.
      e88656ab
  19. 02 Nov, 2017 1 commit
    • Unknown's avatar
      Trivial typos · 0b3f44eb
      Unknown authored
      Non-user facing. 
      Found using `codespell -q 3`
      0b3f44eb
  20. 17 Aug, 2017 2 commits
    • Jason Rhinelander's avatar
      Reimplement py::init<...> to use common factory code · c4e18008
      Jason Rhinelander authored
      This reimplements the py::init<...> implementations using the various
      functions added to support `py::init(...)`, and moves the implementing
      structs into `detail/init.h` from `pybind11.h`.  It doesn't simply use a
      factory directly, as this is a very common case and implementation
      without an extra lambda call is a small but useful optimization.
      
      This, combined with the previous lazy initialization, also avoids
      needing placement new for `py::init<...>()` construction: such
      construction now occurs via an ordinary `new Type(...)`.
      
      A consequence of this is that it also fixes a potential bug when using
      multiple inheritance from Python: it was very easy to write classes
      that double-initialize an existing instance which had the potential to
      leak for non-pod classes.  With the new implementation, an attempt to
      call `__init__` on an already-initialized object is now ignored.  (This
      was already done in the previous commit for factory constructors).
      
      This change exposed a few warnings (fixed here) from deleting a pointer
      to a base class with virtual functions but without a virtual destructor.
      These look like legitimate warnings that we shouldn't suppress; this
      adds virtual destructors to the appropriate classes.
      c4e18008
    • Jason Rhinelander's avatar
      Allow binding factory functions as constructors · 464d9896
      Jason Rhinelander authored
      This allows you to use:
      
          cls.def(py::init(&factory_function));
      
      where `factory_function` returns a pointer, holder, or value of the
      class type (or a derived type).  Various compile-time checks
      (static_asserts) are performed to ensure the function is valid, and
      various run-time type checks where necessary.
      
      Some other details of this feature:
      - The `py::init` name doesn't conflict with the templated no-argument
        `py::init<...>()`, but keeps the naming consistent: the existing
        templated, no-argument one wraps constructors, the no-template,
        function-argument one wraps factory functions.
      - If returning a CppClass (whether by value or pointer) when an CppAlias
        is required (i.e. python-side inheritance and a declared alias), a
        dynamic_cast to the alias is attempted (for the pointer version); if
        it fails, or if returned by value, an Alias(Class &&) constructor
        is invoked.  If this constructor doesn't exist, a runtime error occurs.
      - for holder returns when an alias is required, we try a dynamic_cast of
        the wrapped pointer to the alias to see if it is already an alias
        instance; if it isn't, we raise an error.
      - `py::init(class_factory, alias_factory)` is also available that takes
        two factories: the first is called when an alias is not needed, the
        second when it is.
      - Reimplement factory instance clearing.  The previous implementation
        failed under python-side multiple inheritance: *each* inherited
        type's factory init would clear the instance instead of only setting
        its own type value.  The new implementation here clears just the
        relevant value pointer.
      - dealloc is updated to explicitly set the leftover value pointer to
        nullptr and the `holder_constructed` flag to false so that it can be
        used to clear preallocated value without needing to rebuild the
        instance internals data.
      - Added various tests to test out new allocation/deallocation code.
      - With preallocation now done lazily, init factory holders can
        completely avoid the extra overhead of needing an extra
        allocation/deallocation.
      - Updated documentation to make factory constructors the default
        advanced constructor style.
      - If an `__init__` is called a second time, we have two choices: we can
        throw away the first instance, replacing it with the second; or we can
        ignore the second call.  The latter is slightly easier, so do that.
      464d9896
  21. 05 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Update all remaining tests to new test styles · 391c7544
      Jason Rhinelander authored
      This udpates all the remaining tests to the new test suite code and
      comment styles started in #898.  For the most part, the test coverage
      here is unchanged, with a few minor exceptions as noted below.
      
      - test_constants_and_functions: this adds more overload tests with
        overloads with different number of arguments for more comprehensive
        overload_cast testing.  The test style conversion broke the overload
        tests under MSVC 2015, prompting the additional tests while looking
        for a workaround.
      
      - test_eigen: this dropped the unused functions `get_cm_corners` and
        `get_cm_corners_const`--these same tests were duplicates of the same
        things provided (and used) via ReturnTester methods.
      
      - test_opaque_types: this test had a hidden dependence on ExampleMandA
        which is now fixed by using the global UserType which suffices for the
        relevant test.
      
      - test_methods_and_attributes: this required some additions to UserType
        to make it usable as a replacement for the test's previous SimpleType:
        UserType gained a value mutator, and the `value` property is not
        mutable (it was previously readonly).  Some overload tests were also
        added to better test overload_cast (as described above).
      
      - test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
        the templated versions with an empty parameter pack expand to the same
        thing.
      
      - test_stl: this was already mostly in the new style; this just tweaks
        things a bit, localizing a class, and adding some missing
        `// test_whatever` comments.
      
      - test_virtual_functions: like `test_stl`, this was mostly in the new
        test style already, but needed some `// test_whatever` comments.
        This commit also moves the inherited virtual example code to the end
        of the file, after the main set of tests (since it is less important
        than the other tests, and rather length); it also got renamed to
        `test_inherited_virtuals` (from `test_inheriting_repeat`) because it
        tests both inherited virtual approaches, not just the repeat approach.
      391c7544
  22. 27 Jun, 2017 2 commits
  23. 02 May, 2017 1 commit
  24. 11 Sep, 2016 2 commits
  25. 07 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Allow passing base types as a template parameter · 6b52c838
      Jason Rhinelander authored
      This allows a slightly cleaner base type specification of:
      
          py::class_<Type, Base>("Type")
      
      as an alternative to
      
          py::class_<Type>("Type", py::base<Base>())
      
      As with the other template parameters, the order relative to the holder
      or trampoline types doesn't matter.
      
      This also includes a compile-time assertion failure if attempting to
      specify more than one base class (but is easily extendible to support
      multiple inheritance, someday, by updating the class_selector::set_bases
      function to set multiple bases).
      6b52c838
  26. 06 Sep, 2016 2 commits
    • Dean Moldovan's avatar
      Replace std::cout with py::print in tests · 81511be3
      Dean Moldovan authored
      With this change both C++ and Python write to sys.stdout which resolves
      the capture issues noted in #351. Therefore, the related workarounds are
      removed.
      81511be3
    • Jason Rhinelander's avatar
      Allow arbitrary class_ template option ordering · 5fffe200
      Jason Rhinelander authored
      The current pybind11::class_<Type, Holder, Trampoline> fixed template
      ordering results in a requirement to repeat the Holder with its default
      value (std::unique_ptr<Type>) argument, which is a little bit annoying:
      it needs to be specified not because we want to override the default,
      but rather because we need to specify the third argument.
      
      This commit removes this limitation by making the class_ template take
      the type name plus a parameter pack of options.  It then extracts the
      first valid holder type and the first subclass type for holder_type and
      trampoline type_alias, respectively.  (If unfound, both fall back to
      their current defaults, `std::unique_ptr<type>` and `type`,
      respectively).  If any unmatched template arguments are provided, a
      static assertion fails.
      
      What this means is that you can specify or omit the arguments in any
      order:
      
          py::class_<A, PyA> c1(m, "A");
          py::class_<B, PyB, std::shared_ptr<B>> c2(m, "B");
          py::class_<C, std::shared_ptr<C>, PyB> c3(m, "C");
      
      It also allows future class attributes (such as base types in the next
      commit) to be passed as class template types rather than needing to use
      a py::base<> wrapper.
      5fffe200
  27. 03 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Make test initialization self-registering · 52f4be89
      Jason Rhinelander authored
      Adding or removing tests is a little bit cumbersome currently: the test
      needs to be added to CMakeLists.txt, the init function needs to be
      predeclared in pybind11_tests.cpp, then called in the plugin
      initialization.  While this isn't a big deal for tests that are being
      committed, it's more of a hassle when working on some new feature or
      test code for which I temporarily only care about building and linking
      the test being worked on rather than the entire test suite.
      
      This commit changes tests to self-register their initialization by
      having each test initialize a local object (which stores the
      initialization function in a static variable).  This makes changing the
      set of tests being build easy: one only needs to add or comment out
      test names in tests/CMakeLists.txt.
      
      A couple other minor changes that go along with this:
      
      - test_eigen.cpp is now included in the test list, then removed if eigen
        isn't available.  This lets you disable the eigen tests by commenting
        it out, just like all the other tests, but keeps the build working
        without eigen eigen isn't available.  (Also, if it's commented out, we
        don't even bother looking for and reporting the building with/without
        eigen status message).
      
      - pytest is now invoked with all the built test names (with .cpp changed
        to .py) so that it doesn't try to run tests that weren't built.
      52f4be89
  28. 29 Aug, 2016 1 commit
    • Jason Rhinelander's avatar
      Fix template trampoline overload lookup failure · 20978263
      Jason Rhinelander authored
      Problem
      =======
      
      The template trampoline pattern documented in PR #322 has a problem with
      virtual method overloads in intermediate classes in the inheritance
      chain between the trampoline class and the base class.
      
      For example, consider the following inheritance structure, where `B` is
      the actual class, `PyB<B>` is the trampoline class, and `PyA<B>` is an
      intermediate class adding A's methods into the trampoline:
      
          PyB<B> -> PyA<B> -> B -> A
      
      Suppose PyA<B> has a method `some_method()` with a PYBIND11_OVERLOAD in
      it to overload the virtual `A::some_method()`.  If a Python class `C` is
      defined that inherits from the pybind11-registered `B` and tries to
      provide an overriding `some_method()`, the PYBIND11_OVERLOADs declared
      in PyA<B> fails to find this overloaded method, and thus never invoke it
      (or, if pure virtual and not overridden in PyB<B>, raises an exception).
      
      This happens because the base (internal) `PYBIND11_OVERLOAD_INT` macro
      simply calls `get_overload(this, name)`; `get_overload()` then uses the
      inferred type of `this` to do a type lookup in `registered_types_cpp`.
      This is where it fails: `this` will be a `PyA<B> *`, but `PyA<B>` is
      neither the base type (`B`) nor the trampoline type (`PyB<B>`).  As a
      result, the overload fails and we get a failed overload lookup.
      
      The fix
      =======
      
      The fix is relatively simple: we can cast `this` passed to
      `get_overload()` to a `const B *`, which lets get_overload look up the
      correct class.  Since trampoline classes should be derived from `B`
      classes anyway, this cast should be perfectly safe.
      
      This does require adding the class name as an argument to the
      PYBIND11_OVERLOAD_INT macro, but leaves the public macro signatures
      unchanged.
      20978263
  29. 24 Aug, 2016 1 commit
  30. 19 Aug, 2016 2 commits
    • Dean Moldovan's avatar
      99dbdc16
    • Dean Moldovan's avatar
      Port tests to pytest · a0c1ccf0
      Dean Moldovan authored
      Use simple asserts and pytest's powerful introspection to make testing
      simpler. This merges the old .py/.ref file pairs into simple .py files
      where the expected values are right next to the code being tested.
      
      This commit does not touch the C++ part of the code and replicates the
      Python tests exactly like the old .ref-file-based approach.
      a0c1ccf0
  31. 11 Aug, 2016 2 commits
    • Wenzel Jakob's avatar
      quench warning on clang/OSX · 216df0dd
      Wenzel Jakob authored
      216df0dd
    • Jason Rhinelander's avatar
      Improve constructor/destructor tracking · 3f589379
      Jason Rhinelander authored
      This commit rewrites the examples that look for constructor/destructor
      calls to do so via static variable tracking rather than output parsing.
      
      The added ConstructorStats class provides methods to keep track of
      constructors and destructors, number of default/copy/move constructors,
      and number of copy/move assignments.  It also provides a mechanism for
      storing values (e.g. for value construction), and then allows all of
      this to be checked at the end of a test by getting the statistics for a
      C++ (or python mapping) class.
      
      By not relying on the precise pattern of constructions/destructions,
      but rather simply ensuring that every construction is matched with a
      destruction on the same object, we ensure that everything that gets
      created also gets destroyed as expected.
      
      This replaces all of the various "std::cout << whatever" code in
      constructors/destructors with
      `print_created(this)`/`print_destroyed(this)`/etc. functions which
      provide similar output, but now has a unified format across the
      different examples, including a new ### prefix that makes mixed example
      output and lifecycle events easier to distinguish.
      
      With this change, relaxed mode is no longer needed, which enables
      testing for proper destruction under MSVC, and under any other compiler
      that generates code calling extra constructors, or optimizes away any
      constructors.  GCC/clang are used as the baseline for move
      constructors; the tests are adapted to allow more move constructors to
      be evoked (but other types are constructors much have matching counts).
      
      This commit also disables output buffering of tests, as the buffering
      sometimes results in C++ output ending up in the middle of python
      output (or vice versa), depending on the OS/python version.
      3f589379