1. 27 Jun, 2017 1 commit
  2. 12 Jun, 2017 1 commit
    • Jason Rhinelander's avatar
      Support multiple inheritance from python · e45c2114
      Jason Rhinelander authored
      This commit allows multiple inheritance of pybind11 classes from
      Python, e.g.
      
          class MyType(Base1, Base2):
              def __init__(self):
                  Base1.__init__(self)
                  Base2.__init__(self)
      
      where Base1 and Base2 are pybind11-exported classes.
      
      This requires collapsing the various builtin base objects
      (pybind11_object_56, ...) introduced in 2.1 into a single
      pybind11_object of a fixed size; this fixed size object allocates enough
      space to contain either a simple object (one base class & small* holder
      instance), or a pointer to a new allocation that can contain an
      arbitrary number of base classes and holders, with holder size
      unrestricted.
      
      * "small" here means having a sizeof() of at most 2 pointers, which is
      enough to fit unique_ptr (sizeof is 1 ptr) and shared_ptr (sizeof is 2
      ptrs).
      
      To minimize the performance impact, this repurposes
      `internals::registered_types_py` to store a vector of pybind-registered
      base types.  For direct-use pybind types (e.g. the `PyA` for a C++ `A`)
      this is simply storing the same thing as before, but now in a vector;
      for Python-side inherited types, the map lets us avoid having to do a
      base class traversal as long as we've seen the class before.  The
      change to vector is needed for multiple inheritance: Python types
      inheriting from multiple registered bases have one entry per base.
      e45c2114
  3. 22 May, 2017 1 commit
    • Jason Rhinelander's avatar
      Use dynamic cast for shared_from_this holder init · b8ac4383
      Jason Rhinelander authored
      Using a dynamic_cast instead of a static_cast is needed to safely cast
      from a base to a derived type.  The previous static_pointer_cast isn't
      safe, however, when downcasting (and fails to compile when downcasting
      with virtual inheritance).
      
      Switching this to always use a dynamic_pointer_cast shouldn't incur any
      additional overhead when a static_pointer_cast is safe (i.e. when
      upcasting, or self-casting): compilers don't need RTTI checks in those
      cases.
      b8ac4383
  4. 21 Mar, 2017 1 commit
    • Dean Moldovan's avatar
      Throw an exception when attempting to load an incompatible holder · cd3d1fc7
      Dean Moldovan authored
      Instead of a segfault. Fixes #751.
      
      This covers the case of loading a custom holder from a default-holder
      instance. Attempting to load one custom holder from a different custom
      holder (i.e. not `std::unique_ptr`) yields undefined behavior, just as
      #588 established for inheritance.
      cd3d1fc7
  5. 31 Jan, 2017 1 commit
    • Dean Moldovan's avatar
      Improve custom holder support (#607) · ec009a7c
      Dean Moldovan authored
      * Abstract away some holder functionality (resolve #585)
      
      Custom holder types which don't have `.get()` can select the correct
      function to call by specializing `holder_traits`.
      
      * Add support for move-only holders (fix #605)
      ec009a7c
  6. 15 Dec, 2016 1 commit
  7. 07 Dec, 2016 1 commit
  8. 20 Oct, 2016 1 commit
    • Dean Moldovan's avatar
      Support std::shared_ptr holder type out of the box · 5d28dd11
      Dean Moldovan authored
      With this there is no more need for manual user declarations like
      `PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)`. Existing ones
      will still compile without error -- they will just be ignored silently.
      
      Resolves #446.
      5d28dd11
  9. 06 Sep, 2016 1 commit
  10. 04 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Make unique_ptr's with non-default deleters work · a6495af8
      Jason Rhinelander authored
      Currently pybind11 only supports std::unique_ptr<T> holders by default
      (other holders can, of course, be declared using the macro).  PR #368
      added a `py::nodelete` that is intended to be used as:
      
          py::class_<Type, std::unique_ptr<Type, py::nodelete>> c("Type");
      
      but this doesn't work out of the box.  (You could add an explicit
      holder type declaration, but this doesn't appear to have been the
      intention of the commit).
      
      This commit fixes it by generalizing the unique_ptr type_caster to take
      both the type and deleter as template arguments, so that *any*
      unique_ptr instances are now automatically handled by pybind.  It also
      adds a test to test_smart_ptr, testing both that py::nodelete (now)
      works, and that the object is indeed not deleted as intended.
      a6495af8
  11. 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
  12. 19 Aug, 2016 1 commit
    • 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
  13. 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
  14. 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
  15. 18 Apr, 2016 1 commit
  16. 17 Jan, 2016 1 commit
    • Wenzel Jakob's avatar
      improved handling of shared/smart pointers · b2c2c792
      Wenzel Jakob authored
      Previously, pybind11 required classes using std::shared_ptr<> to derive
      from std::enable_shared_from_this<> (or compilation failures would ensue).
      
      Everything now also works for classes that don't do this, assuming that
      some basic rules are followed (e.g. never passing "raw" pointers of
      instances manged by shared pointers). The safer
      std::enable_shared_from_this<> approach continues to be supported.
      b2c2c792
  17. 24 Nov, 2015 1 commit
  18. 18 Oct, 2015 1 commit
  19. 15 Oct, 2015 1 commit
  20. 29 Jul, 2015 1 commit
  21. 09 Jul, 2015 1 commit