1. 27 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Fix downcasting of base class pointers · 14e70650
      Jason Rhinelander authored
      When we are returned a base class pointer (either directly or via
      shared_from_this()) we detect its runtime type (using `typeid`), then
      end up essentially reinterpret_casting the pointer to the derived type.
      This is invalid when the base class pointer was a non-first base, and we
      end up with an invalid pointer.  We could dynamic_cast to the
      most-derived type, but if *that* type isn't pybind11-registered, the
      resulting pointer given to the base `cast` implementation isn't necessarily valid
      to be reinterpret_cast'ed back to the backup type.
      
      This commit removes the "backup" type argument from the many-argument
      `cast(...)` and instead does the derived-or-pointer type decision and
      type lookup in type_caster_base, where the dynamic_cast has to be to
      correctly get the derived pointer, but also has to do the type lookup to
      ensure that we don't pass the wrong (derived) pointer when the backup
      type (i.e. the type caster intrinsic type) pointer is needed.
      
      Since the lookup is needed before calling the base cast(), this also
      changes the input type to a detail::type_info rather than doing a
      (second) lookup in cast().
      14e70650
  2. 01 Feb, 2017 1 commit
    • Jason Rhinelander's avatar
      Add warning about binding multiple modules (#635) · 0558a9a7
      Jason Rhinelander authored
      Issue #633 suggests people might be tempted to copy the test scripts
      self-binding code, but that's a bad idea for pretty much anything other
      than a test suite with self-contained test code.
      
      This commit adds a comment as such with a reference to the
      documentation that tells people how to do it instead.
      0558a9a7
  3. 31 Jan, 2017 1 commit
    • Jason Rhinelander's avatar
      Minor fixes (#613) · 12494525
      Jason Rhinelander authored
      * Minor doc syntax fix
      
      The numpy documentation had a bad :file: reference (was using double
      backticks instead of single backticks).
      
      * Changed long-outdated "example" -> "tests" wording
      
      The ConstructorStats internal docs still had "from example import", and
      the main testing cpp file still used "example" in the module
      description.
      12494525
  4. 12 Dec, 2016 1 commit
    • Jason Rhinelander's avatar
      Adds automatic casting on assignment of non-pyobject types (#551) · 3f1ff3f4
      Jason Rhinelander authored
      This adds automatic casting when assigning to python types like dict,
      list, and attributes.  Instead of:
      
          dict["key"] = py::cast(val);
          m.attr("foo") = py::cast(true);
          list.append(py::cast(42));
      
      you can now simply write:
      
          dict["key"] = val;
          m.attr("foo") = true;
          list.append(42);
      
      Casts needing extra parameters (e.g. for a non-default rvp) still
      require the py::cast() call. set::add() is also supported.
      
      All usage is channeled through a SFINAE implementation which either just returns or casts. 
      
      Combined non-converting handle and autocasting template methods via a
      helper method that either just returns (handle) or casts (C++ type).
      3f1ff3f4
  5. 22 Sep, 2016 1 commit
  6. 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
  7. 24 Aug, 2016 1 commit
  8. 19 Aug, 2016 2 commits
    • Dean Moldovan's avatar
      Move enum tests into a new file · a9a37b4e
      Dean Moldovan authored
      There are more enum tests than 'constants and functions'.
      a9a37b4e
    • 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
  9. 13 Aug, 2016 2 commits
  10. 11 Aug, 2016 1 commit
    • 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
  11. 18 Jul, 2016 1 commit
    • Jason Rhinelander's avatar
      Rename examples files, as per #288 · b3f3d79f
      Jason Rhinelander authored
      This renames example files from `exampleN` to `example-description`.
      
      Specifically, the following renaming is applied:
      
      example1 -> example-methods-and-attributes
      example2 -> example-python-types
      example3 -> example-operator-overloading
      example4 -> example-constants-and-functions
      example5 -> example-callbacks (*)
      example6 -> example-sequence-and-iterators
      example7 -> example-buffers
      example8 -> example-custom-ref-counting
      example9 -> example-modules
      example10 -> example-numpy-vectorize
      example11 -> example-arg-keywords-and-defaults
      example12 -> example-virtual-functions
      example13 -> example-keep-alive
      example14 -> example-opaque-types
      example15 -> example-pickling
      example16 -> example-inheritance
      example17 -> example-stl-binders
      example18 -> example-eval
      example19 -> example-custom-exceptions
      
      * the inheritance parts of example5 are moved into example-inheritance
      (previously example16), and the remainder is left as example-callbacks.
      
      This commit also renames the internal variables ("Example1",
      "Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
      "ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
      file renaming.
      
      The order of tests is preserved, but this can easily be changed if
      there is some more natural ordering by updating the list in
      examples/CMakeLists.txt.
      b3f3d79f
  12. 11 Jul, 2016 1 commit
  13. 08 Jul, 2016 1 commit
  14. 15 May, 2016 1 commit
  15. 05 May, 2016 1 commit
  16. 18 Apr, 2016 1 commit
  17. 13 Apr, 2016 2 commits
  18. 15 Mar, 2016 1 commit
  19. 10 Mar, 2016 1 commit
  20. 17 Jan, 2016 1 commit
  21. 18 Oct, 2015 1 commit
  22. 13 Oct, 2015 1 commit
  23. 01 Oct, 2015 1 commit
  24. 29 Jul, 2015 1 commit
  25. 28 Jul, 2015 1 commit
  26. 09 Jul, 2015 1 commit