1. 04 Jan, 2017 2 commits
  2. 26 Dec, 2016 2 commits
  3. 19 Dec, 2016 4 commits
  4. 16 Dec, 2016 1 commit
    • Wenzel Jakob's avatar
      WIP: PyPy support (#527) · 1d1f81b2
      Wenzel Jakob authored
      This commit includes modifications that are needed to get pybind11 to work with PyPy. The full test suite compiles and runs except for a last few functions that are commented out (due to problems in PyPy that were reported on the PyPy bugtracker).
      
      Two somewhat intrusive changes were needed to make it possible: two new tags ``py::buffer_protocol()`` and ``py::metaclass()`` must now be specified to the ``class_`` constructor if the class uses the buffer protocol and/or requires a metaclass (e.g. for static properties).
      
      Note that this is only for the PyPy version based on Python 2.7 for now. When the PyPy 3.x has caught up in terms of cpyext compliance, a PyPy 3.x patch will follow.
      1d1f81b2
  5. 15 Dec, 2016 1 commit
  6. 14 Dec, 2016 3 commits
    • Jason Rhinelander's avatar
      Change all_of_t/any_of_t to all_of/any_of, add none_of · fa5d05e1
      Jason Rhinelander authored
      This replaces the current `all_of_t<Pred, Ts...>` with `all_of<Ts...>`,
      with previous use of `all_of_t<Pred, Ts...>` becoming
      `all_of<Pred<Ts>...>` (and similarly for `any_of_t`).  It also adds a
      `none_of<Ts...>`, a shortcut for `negation<any_of<Ts...>>`.
      
      This allows `all_of` and `any_of` to be used a bit more flexible, e.g.
      in cases where several predicates need to be tested for the same type
      instead of the same predicate for multiple types.
      
      This commit replaces the implementation with a more efficient version
      for non-MSVC.  For MSVC, this changes the workaround to use the
      built-in, recursive std::conjunction/std::disjunction instead.
      
      This also removes the `count_t` since `any_of_t` and `all_of_t` were the
      only things using it.
      
      This commit also rearranges some of the future std imports to use actual
      `std` implementations for C++14/17 features when under the appropriate
      compiler mode, as we were already doing for a few things (like
      index_sequence).  Most of these aren't saving much (the implementation
      for enable_if_t, for example, is trivial), but I think it makes the
      intention of the code instantly clear.  It also enables MSVC's native
      std::index_sequence support.
      fa5d05e1
    • Jason Rhinelander's avatar
      Support binding noexcept function/methods in C++17 · 6e036e78
      Jason Rhinelander authored
      When compiling in C++17 mode the noexcept specifier is part of the
      function type.  This causes a failure in pybind11 because, by omitting
      a noexcept specifier when deducing function return and argument types,
      we are implicitly making `noexcept(false)` part of the type.
      
      This means that functions with `noexcept` fail to match the function
      templates in cpp_function (and other places), and we get compilation
      failure (we end up trying to fit it into the lambda function version,
      which fails since a function pointer has no `operator()`).
      
      We can, however, deduce the true/false `B` in noexcept(B), so we don't
      need to add a whole other set of overloads, but need to deduce the extra
      argument when under C++17.  That will *not* work under pre-C++17,
      however.
      
      This commit adds two macros to fix the problem: under C++17 (with the
      appropriate feature macro set) they provide an extra `bool NoExceptions`
      template argument and provide the `noexcept(NoExceptions)` deduced
      specifier.  Under pre-C++17 they expand to nothing.
      
      This is needed to compile pybind11 with gcc7 under -std=c++17.
      6e036e78
    • Jason Rhinelander's avatar
      Fix test compilation when both optional's exist · 79de508e
      Jason Rhinelander authored
      gcc 7 has both std::experimental::optional and std::optional, but this
      breaks the test compilation as we are trying to use the same `opt_int`
      type alias for both.
      79de508e
  7. 13 Dec, 2016 1 commit
  8. 12 Dec, 2016 2 commits
    • Dean Moldovan's avatar
      76e993a3
    • 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
  9. 08 Dec, 2016 1 commit
  10. 07 Dec, 2016 2 commits
    • Jason Rhinelander's avatar
      std::valarray support for stl.h (#545) · ae185b7f
      Jason Rhinelander authored
      * Added ternary support with descr args
      
      Current the `_<bool>(a, b)` ternary support only works for `char[]` `a`
      and `b`; this commit allows it to work for `descr` `a` and `b` arguments
      as well.
      
      * Add support for std::valarray to stl.h
      
      This abstracts the std::array into a `array_caster` which can then be
      used with either std::array or std::valarray, the main difference being
      that std::valarray is resizable.  (It also lets the array_caster be
      potentially used for other std::array-like interfaces, much as the
      list_caster and map_caster currently provide).
      
      * Small stl.h cleanups
      
      - Remove redundant `type` typedefs
      - make internal list_caster methods private
      ae185b7f
    • Dean Moldovan's avatar
  11. 03 Dec, 2016 1 commit
  12. 25 Nov, 2016 1 commit
  13. 22 Nov, 2016 3 commits
  14. 20 Nov, 2016 3 commits
  15. 17 Nov, 2016 5 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 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
  16. 16 Nov, 2016 2 commits
  17. 15 Nov, 2016 4 commits
    • Jason Rhinelander's avatar
      2e76daa5
    • Ivan Smirnov's avatar
      Add type casters for nullopt_t, fix none refcount (#499) · 425b4970
      Ivan Smirnov authored
      * Incref returned None in std::optional type caster
      
      * Add type casters for nullopt_t
      
      * Add a test for nullopt_t
      425b4970
    • Alexander Stukowski's avatar
      Provide more control over automatic generation of docstrings (#486) · 9a110e6d
      Alexander Stukowski authored
      Added the docstring_options class, which gives global control over the generation of docstrings and function signatures.
      9a110e6d
    • Jason Rhinelander's avatar
      Fix stl_bind to support movable, non-copyable value types (#490) · 617fbcfc
      Jason Rhinelander authored
      This commit includes the following changes:
      
      * Don't provide make_copy_constructor for non-copyable container
      
      make_copy_constructor currently fails for various stl containers (e.g.
      std::vector, std::unordered_map, std::deque, etc.) when the container's
      value type (e.g. the "T" or the std::pair<K,T> for a map) is
      non-copyable.  This adds an override that, for types that look like
      containers, also requires that the value_type be copyable.
      
      * stl_bind.h: make bind_{vector,map} work for non-copy-constructible types
      
      Most stl_bind modifiers require copying, so if the type isn't copy
      constructible, we provide a read-only interface instead.
      
      In practice, this means that if the type is non-copyable, it will be,
      for all intents and purposes, read-only from the Python side (but
      currently it simply fails to compile with such a container).
      
      It is still possible for the caller to provide an interface manually
      (by defining methods on the returned class_ object), but this isn't
      something stl_bind can handle because the C++ code to construct values
      is going to be highly dependent on the container value_type.
      
      * stl_bind: copy only for arithmetic value types
      
      For non-primitive types, we may well be copying some complex type, when
      returning by reference is more appropriate.  This commit returns by
      internal reference for all but basic arithmetic types.
      
      * Return by reference whenever possible
      
      Only if we definitely can't--i.e. std::vector<bool>--because v[i]
      returns something that isn't a T& do we copy; for everything else, we
      return by reference.
      
      For the map case, we can always return by reference (at least for the
      default stl map/unordered_map).
      617fbcfc
  18. 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