1. 17 Aug, 2017 1 commit
    • Dean Moldovan's avatar
      Fix documentation build · 8665ee81
      Dean Moldovan authored
      * Doxygen needs `RECURSIVE = YES` in order to parse the `detail` subdir.
      
      * The `-W` warnings-as-errors option for sphinx doesn't work with the
        makefile build. Switched to calling sphinx directly.
      
      * Fix "citation [cppimport] is not referenced" warning.
      8665ee81
  2. 14 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Compile with hidden visibility always; set via cmake property rather than compiler flag · 97aa54fe
      Jason Rhinelander authored
      This updates the compilation to always apply hidden visibility to
      resolve the issues with default visibility causing problems under debug
      compilations.  Moreover using the cmake property makes it easier for a
      caller to override if absolutely needed for some reason.
      
      For `pybind11_add_module` we use cmake to set the property; for the
      targets, we append to compilation option to non-MSVC compilers.
      97aa54fe
  3. 12 Aug, 2017 1 commit
    • Dean Moldovan's avatar
      Add support for boost::variant in C++11 mode · 7918bcc9
      Dean Moldovan authored
      In C++11 mode, `boost::apply_visitor` requires an explicit `result_type`.
      This also adds optional tests for `boost::variant` in C++11/14, if boost
      is available. In C++17 mode, `std::variant` is tested instead.
      7918bcc9
  4. 07 Aug, 2017 2 commits
  5. 05 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Made module_local types take precedence over global types · 4b159230
      Jason Rhinelander authored
      Attempting to mix py::module_local and non-module_local classes results
      in some unexpected/undesirable behaviour:
      
      - if a class is registered non-local by some other module, a later
        attempt to register it locally fails.  It doesn't need to: it is
        perfectly acceptable for the local registration to simply override
        the external global registration.
      - going the other way (i.e. module `A` registers a type `T` locally,
        then `B` registers the same type `T` globally) causes a more serious
        issue: `A.T`'s constructors no longer work because the `self` argument
        gets converted to a `B.T`, which then fails to resolve.
      
      Changing the cast precedence to prefer local over global fixes this and
      makes it work more consistently, regardless of module load order.
      4b159230
  6. 04 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Add py::module_local() attribute for module-local type bindings · 7437c695
      Jason Rhinelander authored
      This commit adds a `py::module_local` attribute that lets you confine a
      registered type to the module (more technically, the shared object) in
      which it is defined, by registering it with:
      
          py::class_<C>(m, "C", py::module_local())
      
      This will allow the same C++ class `C` to be registered in different
      modules with independent sets of class definitions.  On the Python side,
      two such types will be completely distinct; on the C++ side, the C++
      type resolves to a different Python type in each module.
      
      This applies `py::module_local` automatically to `stl_bind.h` bindings
      when the container value type looks like something global: i.e. when it
      is a converting type (for example, when binding a `std::vector<int>`),
      or when it is a registered type itself bound with `py::module_local`.
      This should help resolve potential future conflicts (e.g. if two
      completely unrelated modules both try to bind a `std::vector<int>`.
      Users can override the automatic selection by adding a
      `py::module_local()` or `py::module_local(false)`.
      
      Note that this does mildly break backwards compatibility: bound stl
      containers of basic types like `std::vector<int>` cannot be bound in one
      module and returned in a different module.  (This can be re-enabled with
      `py::module_local(false)` as described above, but with the potential for
      eventual load conflicts).
      7437c695
  7. 23 Jul, 2017 1 commit
  8. 27 Jun, 2017 2 commits
  9. 25 Jun, 2017 1 commit
  10. 24 Jun, 2017 3 commits
  11. 15 Jun, 2017 1 commit
  12. 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
  13. 08 Jun, 2017 1 commit
  14. 31 May, 2017 1 commit
  15. 29 May, 2017 1 commit
    • Dean Moldovan's avatar
      Replace PYBIND11_PLUGIN with PYBIND11_MODULE · 443ab594
      Dean Moldovan authored
      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".
      443ab594
  16. 28 May, 2017 2 commits
  17. 27 May, 2017 2 commits
  18. 25 May, 2017 1 commit
    • Jason Rhinelander's avatar
      vectorize: pass-through of non-vectorizable args · f3ce00ea
      Jason Rhinelander authored
      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.
      f3ce00ea
  19. 24 May, 2017 1 commit
  20. 10 May, 2017 2 commits
    • Bruce Merry's avatar
      Allow std::complex field with PYBIND11_NUMPY_DTYPE (#831) · b82c0f0a
      Bruce Merry authored
      This exposed a few underlying issues:
      
      1. is_pod_struct was too strict to allow this. I've relaxed it to
      require only trivially copyable and standard layout, rather than POD
      (which additionally requires a trivial constructor, which std::complex
      violates).
      
      2. format_descriptor<std::complex<T>>::format() returned numpy format
      strings instead of PEP3118 format strings, but register_dtype
      feeds format codes of its fields to _dtype_from_pep3118. I've changed it
      to return PEP3118 format codes. format_descriptor is a public type, so
      this may be considered an incompatible change.
      
      3. register_structured_dtype tried to be smart about whether to mark
      fields as unaligned (with ^). However, it's examining the C++ alignment,
      rather than what numpy (or possibly PEP3118) thinks the alignment should
      be. For complex values those are different. I've made it mark all fields
      as ^ unconditionally, which should always be safe even if they are
      aligned, because we explicitly mark the padding.
      b82c0f0a
    • Bruce Merry's avatar
      Support arrays inside PYBIND11_NUMPY_DTYPE (#832) · 8e0d832c
      Bruce Merry authored
      Resolves #800.
      
      Both C++ arrays and std::array are supported, including mixtures like
      std::array<int, 2>[4]. In a multi-dimensional array of char, the last
      dimension is used to construct a numpy string type.
      8e0d832c
  21. 09 May, 2017 1 commit
    • Jason Rhinelander's avatar
      Make PYBIND11_CPP_STANDARD work under MSVC · 77710ff0
      Jason Rhinelander authored
      Under MSVC we were ignoring PYBIND11_CPP_STANDARD and simply not
      passing any standard (which makes MSVC default to its C++14 mode).
      
      MSVC 2015u3 added the `/std:c++14` and `/std:c++latest` flags; the
      latter, under MSVC 2017, enables some C++17 features (such as
      `std::optional` and `std::variant`), so it is something we need to
      start supporting under MSVC.
      
      This makes the PYBIND11_CPP_STANDARD cmake variable work under MSVC,
      defaulting it to /std:c++14 (matching the default -std=c++14 for
      non-MSVC).
      
      It also adds a new appveyor test running under MSVC 2017 with
      /std:c++latest, which runs (and passes) the
      `std::optional`/`std::variant` tests.
      
      Also updated the documentation to clarify the c++ flags and add show
      MSVC flag examples.
      77710ff0
  22. 08 May, 2017 1 commit
  23. 07 May, 2017 3 commits
    • Cris Luengo's avatar
    • Jason Rhinelander's avatar
      Use numpy rather than Eigen for copying · b68959e8
      Jason Rhinelander authored
      We're current copy by creating an Eigen::Map into the input numpy
      array, then assigning that to the basic eigen type, effectively having
      Eigen do the copy.  That doesn't work for negative strides, though:
      Eigen doesn't allow them.
      
      This commit makes numpy do the copying instead by allocating the eigen
      type, then having numpy copy from the input array into a numpy reference
      into the eigen object's data.  This also saves a copy when type
      conversion is required: numpy can do the conversion on-the-fly as part
      of the copy.
      
      Finally this commit also makes non-reference parameters respect the
      convert flag, declining the load when called in a noconvert pass with a
      convertible, but non-array input or an array with the wrong dtype.
      b68959e8
    • Cris Luengo's avatar
      d400f60c
  24. 29 Apr, 2017 1 commit
  25. 07 Apr, 2017 1 commit
  26. 02 Apr, 2017 1 commit
    • Dean Moldovan's avatar
      Add a scope guard call policy · 1ac19036
      Dean Moldovan authored
      ```c++
      m.def("foo", foo, py::call_guard<T>());
      ```
      
      is equivalent to:
      
      ```c++
      m.def("foo", [](args...) {
          T scope_guard;
          return foo(args...); // forwarded arguments
      });
      ```
      1ac19036
  27. 28 Mar, 2017 1 commit
  28. 22 Mar, 2017 4 commits