1. 07 Jun, 2017 2 commits
  2. 06 Jun, 2017 1 commit
    • Explicitly define copy/move constructors for accessor · 91bbe2f2
      `accessor` currently relies on an implicit default copy constructor, but that is deprecated in C++11 when a copy assignment operator is present and can, in some cases, raise deprecation warnings (see #888).  This commit explicitly specifies the default copy constructor and also adds a default move constructor.
      eirrgang committed
  3. 31 May, 2017 1 commit
  4. 30 May, 2017 3 commits
    • std::reference_wrapper: non-generic types; no None · acedd6c7
      This reimplements the std::reference_wrapper<T> caster to be a shell
      around the underlying T caster (rather than assuming T is a generic
      type), which lets it work for things like `std::reference_wrapper<int>`
      or anything else custom type caster with a lvalue cast operator.
      
      This also makes it properly fail when None is provided, just as an
      ordinary lvalue reference argument would similarly fail.
      
      This also adds a static assert to test that T has an appropriate type
      caster.  It triggers for casters like `std::pair`, which have
      return-by-value cast operators.  (In theory this could be supported by
      storing a local temporary for such types, but that's beyond the scope
      of this PR).
      
      This also replaces `automatic` or `take_ownership` return value policies
      with `automatic_reference` as taking ownership of a reference inside a
      reference_wrapper is not valid.
      Jason Rhinelander committed
    • Move reference_wrapper test from test_issues to test_python_types · 7cdf9f1a
      test_issues is deprecated, and the following commit adds other, related
      reference_wrapper tests.
      Jason Rhinelander committed
    • Filter warnings on pytest >= v3.1 · 005fde6a
      The new version of pytest now reports Python warnings by default. This
      commit filters out some third-party extension warnings which are not
      useful for pybind11 tests.
      Dean Moldovan committed
  5. 29 May, 2017 3 commits
    • Replace PYBIND11_PLUGIN with PYBIND11_MODULE · 443ab594
      This commit also adds `doc()` to `object_api` as a shortcut for the
      `attr("__doc__")` accessor.
      
      The module macro changes from:
      ```c++
      PYBIND11_PLUGIN(example) {
          pybind11::module m("example", "pybind11 example plugin");
          m.def("add", [](int a, int b) { return a + b; });
          return m.ptr();
      }
      ```
      
      to:
      
      ```c++
      PYBIND11_MODULE(example, m) {
          m.doc() = "pybind11 example plugin";
          m.def("add", [](int a, int b) { return a + b; });
      }
      ```
      
      Using the old macro results in a deprecation warning. The warning
      actually points to the `pybind11_init` function (since attributes
      don't bind to macros), but the message should be quite clear:
      "PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE".
      Dean Moldovan committed
    • Convenience constructor templates for buffer_info (#860) · b700c5d6
      * Added template constructors to buffer_info that can deduce the item size, format string, and number of dimensions from the pointer type and the shape container
      
      * Implemented actual buffer_info constructor as private delegate constructor taking rvalue reference as a workaround for the evaluation order move problem on GCC 4.8
      Yannick Jadoul committed
    • Fix buffer protocol inheritance · 427e4afc
      Fixes #878.
      Dean Moldovan committed
  6. 28 May, 2017 5 commits
  7. 27 May, 2017 3 commits
  8. 25 May, 2017 7 commits
    • Fix invalid memory access in vector insert method · eee4f4fc
      The stl_bind.h wrapper for `Vector.insert` neglected to do a bounds
      check.
      Bruce Merry committed
    • Fix quadratic-time behaviour of vector extend · 6a0f6c40
      The "extend" method for vectors defined in stl_bind.h used `reserve` to
      allocate space for the extra growth. While this can sometimes make a
      constant-factor improvement in performance, it can also cause
      construction of a vector by repeated extension to take quadratic rather
      than linear time, as memory is reallocated in small increments rather
      than on an exponential schedule. For example, this Python code would
      take time proportional to the square of the trip count:
      
      ```python
      a = VectorInt([1, 2, 3])
      b = VectorInt()
      for i in range(100000):
          b.extend(a)
      ```
      
      This commit removes the `reserve` call. The alternative would be to try
      to add some smarter heuristics, but the standard library may well have
      its own heuristics (the iterators are random access iterators, so it can
      easily determine the number of items being added) and trying to add more
      heuristics on top of that seems like a bad idea.
      Bruce Merry committed
    • Force MSVC to compile in utf-8 mode · 8dc63ba9
      MSVC by default uses the local codepage, which fails when it sees the
      utf-8 in test_python_types.cpp.  This adds the /utf-8 flag to the test
      suite compilation to force it to interpret source code as utf-8.
      
      Fixes #869
      Jason Rhinelander committed
    • vectorize: pass-through of non-vectorizable args · f3ce00ea
      This extends py::vectorize to automatically pass through
      non-vectorizable arguments.  This removes the need for the documented
      "explicitly exclude an argument" workaround.
      
      Vectorization now applies to arithmetic, std::complex, and POD types,
      passed as plain value or by const lvalue reference (previously only
      pass-by-value types were supported).  Non-const lvalue references and
      any other types are passed through as-is.
      
      Functions with rvalue reference arguments (whether vectorizable or not)
      are explicitly prohibited: an rvalue reference is inherently not
      something that can be passed multiple times and is thus unsuitable to
      being in a vectorized function.
      
      The vectorize returned value is also now more sensitive to inputs:
      previously it would return by value when all inputs are of size 1; this
      is now amended to having all inputs of size 1 *and* 0 dimensions.  Thus
      if you pass in, for example, [[1]], you get back a 1x1, 2D array, while
      previously you got back just the resulting single value.
      
      Vectorization of member function specializations is now also supported
      via `py::vectorize(&Class::method)`; this required passthrough support
      for the initial object pointer on the wrapping function pointer.
      Jason Rhinelander committed
    • array_t: make c_style/f_style work for array creation · 41f8da4a
      Currently if you construct an `array_t<T, array::f_style>` with a shape
      but not strides you get a C-style array; the only way to get F-style
      strides was to calculate the strides manually.  This commit fixes that
      by adding logic to use f_style strides when the flag is set.
      
      This also simplifies the existing c_style stride logic.
      Jason Rhinelander committed
    • Add and use detail::remove_reference_t · 129a7256
      Adds `remove_reference_t` and converts various `typename
      std::remove_reference<...>::type` to using it.
      Jason Rhinelander committed
    • Add PYBIND11_EXPAND_SIDE_EFFECTS macro · 926e2cf3
      This allows calling of functions (typically void) over a parameter
      pack, replacing usage such as:
      
          bool unused[] = { (voidfunc(param_pack_arg), false)..., false };
          (void) unused;
      
      with a much cleaner:
      
          PYBIND11_EXPAND_SIDE_EFFECTS(voidfunc(param_pack_arg));
      Jason Rhinelander committed
  9. 24 May, 2017 2 commits
    • Allow py::arg().none(false) argument attribute · 4e1e4a58
      This attribute lets you disable (or explicitly enable) passing None to
      an argument that otherwise would allow it by accepting
      a value by raw pointer or shared_ptr.
      Jason Rhinelander committed
    • Add movable cast support to type casters · 813d7e86
      This commit allows type_casters to allow their local values to be moved
      away, rather than copied, when the type caster instance itself is an rvalue.
      
      This only applies (automatically) to type casters using
      PYBIND11_TYPE_CASTER; the generic type type casters don't own their own
      pointer, and various value casters (e.g. std::string, std::pair,
      arithmetic types) already cast to an rvalue (i.e. they return by value).
      
      This updates various calling code to attempt to get a movable value
      whenever the value is itself coming from a type caster about to be
      destroyed: for example, when constructing an std::pair or various stl.h
      containers.  For types that don't support value moving, the cast_op
      falls back to an lvalue cast.
      
      There wasn't an obvious place to add the tests, so I added them to
      test_copy_move_policies, but also renamed it to drop the _policies as it
      now tests more than just policies.
      Jason Rhinelander committed
  10. 22 May, 2017 3 commits
  11. 21 May, 2017 3 commits
    • Define both __div__ and __truediv__ for Python 2 · 35998a03
      Python 2 requires both `__div__` and `__truediv__` (and variants) for
      compatibility with both regular Python 2 and Python 2 under `from
      __future__ import division`.  Without both, division fails in one or the
      other case.
      Jason Rhinelander committed
    • Minor operators.h style cleanups · 1ac51a02
      - realign \ at end of macro lines
      - use 'using A = B;' rather than 'typedef B A;'
      - use conditional_t
      Jason Rhinelander committed
    • Fix /= operator under Python 3 · acad05cb
      The Python method for /= was set as `__idiv__`, which should be
      `__itruediv__` under Python 3.
      
      This wasn't totally broken in that without it defined, Python constructs
      a new object by calling __truediv__.  The operator tests, however,
      didn't actually test the /= operator: when I added it, I saw an extra
      construction, leading to the problem.  This commit also includes tests
      for the previously untested *= operator, and adds some element-wise
      vector multiplication and division operators.
      Jason Rhinelander committed
  12. 20 May, 2017 1 commit
  13. 18 May, 2017 1 commit
  14. 16 May, 2017 1 commit
  15. 11 May, 2017 1 commit
  16. 10 May, 2017 3 commits
    • Improve constructor resolution in variant_caster · 94d0a9f7
      Currently, `py::int_(1).cast<variant<double, int>>()` fills the `double`
      slot of the variant. This commit switches the loader to a 2-pass scheme
      in order to correctly fill the `int` slot.
      Dean Moldovan committed
    • Defer None loading to second pass · 93e3eac6
      Many of our `is_none()` checks in type caster loading return true, but
      this should really be considered a deferral so that, for example, an
      overload with a `py::none` argument would win over one that takes
      `py::none` as a null option.
      
      This keeps None-accepting for the `!convert` pass only for std::optional
      and void casters.  (The `char` caster already deferred None; this just
      extends that behaviour to other casters).
      Jason Rhinelander committed
    • Fix gcc 7 warning · 7fb01ecd
      Under gcc 7 with -std=c++11, compilation results in several of the
      following warnings:
      
          In file included from /home/jagerman/src/pybind11/tests/test_sequences_and_iterators.cpp:13:0:
          /home/jagerman/src/pybind11/include/pybind11/operators.h: In function ‘pybind11::detail::op_<(pybind11::detail::op_id)0, (pybind11::detail::op_type)0, pybind11::detail::self_t, pybind11::detail::self_t> pybind11::detail::operator+(const pybind11::detail::self_t&, const pybind11::detail::self_t&)’:
          /home/jagerman/src/pybind11/include/pybind11/operators.h:78:76: warning: inline declaration of ‘pybind11::detail::op_<(pybind11::detail::op_id)0, (pybind11::detail::op_type)0, pybind11::detail::self_t, pybind11::detail::self_t> pybind11::detail::operator+(const pybind11::detail::self_t&, const pybind11::detail::self_t&)’ follows declaration with attribute noinline [-Wattributes]
           inline op_<op_##id, op_l, self_t, self_t> op(const self_t &, const self_t &) {         \
                                                                                      ^
          /home/jagerman/src/pybind11/include/pybind11/operators.h:109:1: note: in expansion of macro ‘PYBIND11_BINARY_OPERATOR’
           PYBIND11_BINARY_OPERATOR(add,       radd,         operator+,    l + r)
           ^~~~~~~~~~~~~~~~~~~~~~~~
          In file included from /home/jagerman/src/pybind11/include/pybind11/cast.h:15:0,
                           from /home/jagerman/src/pybind11/include/pybind11/attr.h:13,
                           from /home/jagerman/src/pybind11/include/pybind11/pybind11.h:36,
                           from /home/jagerman/src/pybind11/tests/pybind11_tests.h:2,
                           from /home/jagerman/src/pybind11/tests/test_sequences_and_iterators.cpp:11:
          /home/jagerman/src/pybind11/include/pybind11/descr.h:116:36: note: previous definition of ‘pybind11::detail::descr pybind11::detail::operator+(pybind11::detail::descr&&, pybind11::detail::descr&&)’ was here
               PYBIND11_NOINLINE descr friend operator+(descr &&d1, descr &&d2) {
                                              ^~~~~~~~
      
      This appears to be happening because gcc is considering implicit
      construction of `descr` in some places using addition of two
      `descr`-compatible arguments in the `descr.h` c++11 fallback code.
      There's no particular reason that this operator needs to be a friend
      function: this commit changes it to an rvalue-context member function
      operator, which avoids the warning.
      Jason Rhinelander committed