1. 22 Nov, 2016 5 commits
  2. 20 Nov, 2016 6 commits
  3. 17 Nov, 2016 6 commits
    • Wenzel Jakob's avatar
      make arithmetic operators of enum_ optional (#508) · 405f6d1d
      Wenzel Jakob authored
      Following commit 90d278, the object code generated by the python
      bindings of nanogui (github.com/wjakob/nanogui) went up by a whopping
      12%. It turns out that that project has quite a few enums where we don't
      really care about arithmetic operators.
      
      This commit thus partially reverts the effects of #503 by introducing
      an additional attribute py::arithmetic() that must be specified if the
      arithmetic operators are desired.
      405f6d1d
    • Lori A. Burns's avatar
    • Dean Moldovan's avatar
      Improve consistency of array and array_t with regard to other pytypes · 4de27102
      Dean Moldovan authored
      * `array_t(const object &)` now throws on error
      * `array_t::ensure()` is intended for casters —- old constructor is
        deprecated
      * `array` and `array_t` get default constructors (empty array)
      * `array` gets a converting constructor
      * `py::isinstance<array_T<T>>()` checks the type (but not flags)
      
      There is only one special thing which must remain: `array_t` gets
      its own `type_caster` specialization which uses `ensure` instead
      of a simple check.
      4de27102
    • Dean Moldovan's avatar
      Add py::reinterpret_borrow<T>()/steal<T>() for low-level unchecked casts · c7ac16bb
      Dean Moldovan authored
      The pytype converting constructors are convenient and safe for user
      code, but for library internals the additional type checks and possible
      conversions are sometimes not desired. `reinterpret_borrow<T>()` and
      `reinterpret_steal<T>()` serve as the low-level unsafe counterparts
      of `cast<T>()`.
      
      This deprecates the `object(handle, bool)` constructor.
      
      Renamed `borrowed` parameter to `is_borrowed` to avoid shadowing
      warnings on MSVC.
      c7ac16bb
    • Dean Moldovan's avatar
      Add default and converting constructors for all concrete Python types · e18bc02f
      Dean Moldovan authored
      * Deprecate the `py::object::str()` member function since `py::str(obj)`
        is now equivalent and preferred
      
      * Make `py::repr()` a free function
      
      * Make sure obj.cast<T>() works as expected when T is a Python type
      
      `obj.cast<T>()` should be the same as `T(obj)`, i.e. it should convert
      the given object to a different Python type. However, `obj.cast<T>()`
      usually calls `type_caster::load()` which only checks the type without
      doing any actual conversion. That causes a very unexpected `cast_error`.
      This commit makes it so that `obj.cast<T>()` and `T(obj)` are the same
      when T is a Python type.
      
      * Simplify pytypes converting constructor implementation
      
      It's not necessary to maintain a full set of converting constructors
      and assignment operators + const& and &&. A single converting const&
      constructor will work and there is no impact on binary size. On the
      other hand, the conversion functions can be significantly simplified.
      e18bc02f
    • Dean Moldovan's avatar
      Add py::isinstance<T>(obj) for generalized Python type checking · b4498ef4
      Dean Moldovan authored
      Allows checking the Python types before creating an object instead of
      after. For example:
      ```c++
      auto l = list(ptr, true);
      if (l.check())
         // ...
      ```
      The above is replaced with:
      ```c++
      if (isinstance<list>(ptr)) {
          auto l = reinterpret_borrow(ptr);
          // ...
      }
      ```
      
      This deprecates `py::object::check()`. `py::isinstance()` covers the
      same use case, but it can also check for user-defined types:
      ```c++
      class Pet { ... };
      py::class_<Pet>(...);
      
      m.def("is_pet", [](py::object obj) {
          return py::isinstance<Pet>(obj); // works as expected
      });
      ```
      b4498ef4
  4. 16 Nov, 2016 4 commits
  5. 15 Nov, 2016 5 commits
  6. 13 Nov, 2016 2 commits
    • Jason Rhinelander's avatar
      07806558
    • Jason Rhinelander's avatar
      Add cmake option to override tests (#489) · 920e0e34
      Jason Rhinelander authored
      When working on some particular feature, it's nice to be able to disable
      all the tests except for the one I'm working on; this is currently
      possible by editing tests/CMakeLists.txt, and commenting out the tests
      you don't want.
      
      This commit goes a step further by letting you give a list of tests you
      do want when invoking cmake, e.g.:
      
          cmake -DPYBIND11_TEST_OVERRIDE="test_issues.cpp;test_pickling.cpp" ..
      
      changes the build to build just those two tests (and changes the `pytest`
      target to invoke just the two associated tests).
      
      This persists in the build directory until you disable it again by
      running cmake with `-DPYBIND11_TEST_OVERRIDE=`.  It also adds a message
      after the pytest output to remind you that it is in effect:
      
          Note: not all tests run: -DPYBIND11_TEST_OVERRIDE is in effect
      920e0e34
  7. 12 Nov, 2016 1 commit
  8. 11 Nov, 2016 1 commit
  9. 08 Nov, 2016 2 commits
  10. 07 Nov, 2016 1 commit
  11. 06 Nov, 2016 1 commit
    • Jason Rhinelander's avatar
      Don't construct unique_ptr around unowned pointers (#478) · c07ec31e
      Jason Rhinelander authored
      If we need to initialize a holder around an unowned instance, and the
      holder type is non-copyable (i.e. a unique_ptr), we currently construct
      the holder type around the value pointer, but then never actually
      destruct the holder: the holder destructor is called only for the
      instance that actually has `inst->owned = true` set.
      
      This seems no pointer, however, in creating such a holder around an
      unowned instance: we never actually intend to use anything that the
      unique_ptr gives us: and, in fact, do not want the unique_ptr (because
      if it ever actually got destroyed, it would cause destruction of the
      wrapped pointer, despite the fact that that wrapped pointer isn't
      owned).
      
      This commit changes the logic to only create a unique_ptr holder if we
      actually own the instance, and to destruct via the constructed holder
      whenever we have a constructed holder--which will now only be the case
      for owned-unique-holder or shared-holder types.
      
      Othe...
      c07ec31e
  12. 04 Nov, 2016 4 commits
    • Wenzel Jakob's avatar
    • Jason Rhinelander's avatar
      <optional> requires -std=c++17 (#479) · f1b44a05
      Jason Rhinelander authored
      There are now more places than just descr.h that make use of these.
      The new macro isn't quite the same: the old one only tested for a
      couple features, while the new one checks for the __cplusplus version
      (but doesn't even try to enable C++14 for MSVC/ICC).
      
      g++ 7 adds <optional>, but including it in C++14 mode isn't allowed
      (just as including <experimental/optional> isn't allowed in C++11 mode).
      (This wasn't triggered in g++-6 because it doesn't provide <optional>
      yet.)
      f1b44a05
    • Jason Rhinelander's avatar
      Add debugging info about .so size to build output (#477) · dc0b4bd2
      Jason Rhinelander authored
      * Add debugging info about so size to build output
      
      This adds a small python script to tools that captures before-and-after
      .so sizes between builds and outputs this in the build output via a
      string such as:
      
      ------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 924696 (decrease of 73680 bytes = 7.38%)
      
      ------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (increase of 73680 bytes = 7.97%)
      
      ------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (no change)
      
      Or, if there was no .so during the build, just the .so size by itself:
      
      ------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376
      
      This allows you to, for example, build, checkout a different branch,
      rebuild, and easily see exactly the change in the pybind11_tests.so
      size.
      
      It also allows looking at the travis and appveyor build logs to get an
      idea of .so/.dll sizes across different build systems.
      
      * Minor libsize.py script changes
      
      - Use RAII open
      - Remove unused libsize=-1
      - Report change as [+-]xyz bytes = [+-]a.bc%
      dc0b4bd2
    • Wenzel Jakob's avatar
      45e6e6f6
  13. 03 Nov, 2016 2 commits