1. 17 Nov, 2016 4 commits
    • 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
  2. 16 Nov, 2016 1 commit
  3. 08 Nov, 2016 1 commit
  4. 03 Nov, 2016 3 commits
  5. 01 Nov, 2016 1 commit
  6. 23 Oct, 2016 1 commit
  7. 22 Oct, 2016 4 commits
  8. 20 Oct, 2016 4 commits
  9. 16 Oct, 2016 1 commit
    • Jason Rhinelander's avatar
      Disable most implicit conversion constructors · 12d76600
      Jason Rhinelander authored
      We have various classes that have non-explicit constructors that accept
      a single argument, which is implicitly making them implicitly
      convertible from the argument.  In a few cases, this is desirable (e.g.
      implicit conversion of std::string to py::str, or conversion of double
      to py::float_); in many others, however, it is unintended (e.g. implicit
      conversion of size_t to some pre-declared py::array_t<T> type).
      
      This disables most of the unwanted implicit conversions by marking them
      `explicit`, and comments the ones that are deliberately left implicit.
      12d76600
  10. 13 Oct, 2016 2 commits
  11. 12 Oct, 2016 1 commit
    • Wenzel Jakob's avatar
      Permit creation of NumPy arrays with a "base" object that owns the data · 369e9b39
      Wenzel Jakob authored
      This patch adds an extra base handle parameter to most ``py::array`` and
      ``py::array_t<>`` constructors. If specified along with a pointer to
      data, the base object will be registered within NumPy, which increases
      the base's reference count. This feature is useful to create shallow
      copies of C++ or Python arrays while ensuring that the owners of the
      underlying can't be garbage collected while referenced by NumPy.
      
      The commit also adds a simple test function involving a ``wrap()``
      function that creates shallow copies of various N-D arrays.
      369e9b39
  12. 07 Oct, 2016 1 commit
  13. 23 Sep, 2016 1 commit
  14. 22 Sep, 2016 2 commits
  15. 19 Sep, 2016 1 commit
  16. 10 Sep, 2016 2 commits
  17. 27 Aug, 2016 1 commit
  18. 25 Aug, 2016 2 commits
  19. 24 Aug, 2016 1 commit
  20. 15 Aug, 2016 2 commits
  21. 14 Aug, 2016 1 commit
    • Ivan Smirnov's avatar
      format_descriptor::format() now yields std::string · 03fb4885
      Ivan Smirnov authored
      This is required since format descriptors for string types that
      were using PYBIND11_DESCR were causing problems on C++14 on Linux.
      
      Although this is technically a breaking change, it shouldn't cause
      problems since the only use of format strings is passing them to
      buffer_info constructor which expects std::string.
      
      Note: for non-structured types, the const char * value is still
      accessible via ::value for compatibility purpose.
      03fb4885
  22. 13 Aug, 2016 3 commits