- 20 Oct, 2016 1 commit
-
-
Ivan Smirnov authored
-
- 14 Oct, 2016 1 commit
-
-
Dean Moldovan authored
`PyType_Ready` would usually perform the inheritance for us, but it can't adjust `tp_basicsize` appropriately.
-
- 13 Oct, 2016 1 commit
-
-
Wenzel Jakob authored
-
- 12 Oct, 2016 3 commits
-
-
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.
-
Wenzel Jakob authored
- This actually works with no changes, I just wasn't 100% convinced and decided to write a test to see if it's true.
-
Pim Schellart authored
-
- 11 Oct, 2016 1 commit
-
-
Dean Moldovan authored
-
- 09 Oct, 2016 2 commits
-
-
Wenzel Jakob authored
-
Wenzel Jakob authored
-
- 29 Sep, 2016 1 commit
-
-
Wenzel Jakob authored
-
- 27 Sep, 2016 1 commit
-
-
Trent Houliston authored
-
- 23 Sep, 2016 3 commits
-
-
Dean Moldovan authored
`auto var = l[0]` has a strange quirk: `var` is actually an accessor and not an object, so any later assignment of `var = ...` would modify l[0] instead of `var`. This is surprising compared to the non-auto assignment `py::object var = l[0]; var = ...`. By overloading `operator=` on lvalue/rvalue, the expected behavior is restored even for `auto` variables.
-
Dean Moldovan authored
-
Dean Moldovan authored
-
- 22 Sep, 2016 1 commit
-
-
Dean Moldovan authored
This also adds the `hasattr` and `getattr` functions which are needed with the new attribute behavior. The new functions behave exactly like their Python counterparts. Similarly `object` gets a `contains` method which calls `__contains__`, i.e. it's the same as the `in` keyword in Python.
-
- 20 Sep, 2016 1 commit
-
-
Dean Moldovan authored
-
- 19 Sep, 2016 2 commits
-
-
Wenzel Jakob authored
-
Wenzel Jakob authored
-
- 17 Sep, 2016 1 commit
-
-
Wenzel Jakob authored
-
- 16 Sep, 2016 1 commit
-
-
Jason Rhinelander authored
The custom exception handling added in PR #273 is robust, but is overly complex for declaring the most common simple C++ -> Python exception mapping that needs only to copy `what()`. This add a simpler `py::register_exception<CppExp>(module, "PyExp");` function that greatly simplifies the common basic case of translation of a simple CppException into a simple PythonException, while not removing the more advanced capabilities of defining custom exception handlers.
-
- 13 Sep, 2016 3 commits
-
-
Trent Houliston authored
Allowed durations and non system clocks to be set from floats.
-
Trent Houliston authored
-
Trent Houliston authored
Add unit tests and documentation for the chrono cast.
-
- 11 Sep, 2016 3 commits
-
-
Jason Rhinelander authored
The current inheritance testing isn't sufficient to detect a cache failure; the test added here breaks PR #390, which caches the run-time-determined return type the first time a function is called, then reuses that cached type even though the run-time type could be different for a future call.
-
Jason Rhinelander authored
This adds a static local variable (in dead code unless actually needed) in the overload code that is used for storage if the overload is for some convert-by-value type (such as numeric values or std::string). This has limitations (as written up in the advanced doc), but is better than simply not being able to overload reference or pointer methods.
-
Jason Rhinelander authored
Minor change that makes this example more compliant with the C++ Core Guidelines.
-
- 10 Sep, 2016 5 commits
-
-
Ivan Smirnov authored
-
Ivan Smirnov authored
-
Dean Moldovan authored
This clears the Python error at the error_already_set throw site, thus allowing Python calls to be made in destructors which are triggered by the exception. This is preferable to the alternative, which would be guarding every Python API call with an error_scope. This effectively flips the behavior of error_already_set. Previously, it was assumed that the error stays in Python, so handling the exception in C++ would require explicitly calling PyErr_Clear(), but nothing was needed to propagate the error to Python. With this change, handling the error in C++ does not require a PyErr_Clear() call, but propagating the error to Python requires an explicit error_already_set::restore(). The change does not break old code which explicitly calls PyErr_Clear() for cleanup, which should be the majority of user code. The need for an explicit restore() call does break old code, but this should be mostly confined to the library and not user code.
-
Wenzel Jakob authored
-
Wenzel Jakob authored
-
- 09 Sep, 2016 1 commit
-
-
Jason Rhinelander authored
This commit adds support for forcing alias type initialization by defining constructors with `py::init_alias<arg1, arg2>()` instead of `py::init<arg1, arg2>()`. Currently py::init<> only results in Alias initialization if the type is extended in python, or the given arguments can't be used to construct the base type, but can be used to construct the alias. py::init_alias<>, in contrast, always invokes the constructor of the alias type. It looks like this was already the intention of `py::detail::init_alias`, which was forward-declared in 86d825f3, but was apparently never finished: despite the existance of a .def method accepting it, the `detail::init_alias` class isn't actually defined anywhere. This commit completes the feature (or possibly repurposes it), allowing declaration of classes that will always initialize the trampoline which is (as I argued in #397) sometimes useful.
-
- 08 Sep, 2016 1 commit
-
-
Jason Rhinelander authored
Type alias for alias classes with members didn't work properly: space was only allocated for sizeof(type), but if we want to be able to put a type_alias instance there, we need sizeof(type_alias), but sizeof(type_alias) > sizeof(type) whenever type_alias has members.
-
- 07 Sep, 2016 4 commits
-
-
Ivan Smirnov authored
-
Jason Rhinelander authored
The previous commit to address #392 triggers a compiler warning about returning a reference to a local variable, which is *not* a false alarm: the following: py::cast<int &>(o) (which happens internally in an overload declaration) really is returning a reference to a local, because the cast operators for the type_caster for numeric types returns a reference to its own member. This commit adds a static_assert to make that a compilation failure rather than returning a reference into about-to-be-freed memory. Incidentally, this is also a fix for #219, which is exactly the same issue: we can't reference numeric primitives that are cast from wrappers around python numeric types. -
Jason Rhinelander authored
Need to use the intrinsic type, not the raw type. Fixes #392.
-
Jason Rhinelander authored
This allows a slightly cleaner base type specification of: py::class_<Type, Base>("Type") as an alternative to py::class_<Type>("Type", py::base<Base>()) As with the other template parameters, the order relative to the holder or trampoline types doesn't matter. This also includes a compile-time assertion failure if attempting to specify more than one base class (but is easily extendible to support multiple inheritance, someday, by updating the class_selector::set_bases function to set multiple bases).
-
- 06 Sep, 2016 3 commits
-
-
Dean Moldovan authored
With this change both C++ and Python write to sys.stdout which resolves the capture issues noted in #351. Therefore, the related workarounds are removed.
-
Jason Rhinelander authored
The current pybind11::class_<Type, Holder, Trampoline> fixed template ordering results in a requirement to repeat the Holder with its default value (std::unique_ptr<Type>) argument, which is a little bit annoying: it needs to be specified not because we want to override the default, but rather because we need to specify the third argument. This commit removes this limitation by making the class_ template take the type name plus a parameter pack of options. It then extracts the first valid holder type and the first subclass type for holder_type and trampoline type_alias, respectively. (If unfound, both fall back to their current defaults, `std::unique_ptr<type>` and `type`, respectively). If any unmatched template arguments are provided, a static assertion fails. What this means is that you can specify or omit the arguments in any order: py::class_<A, PyA> c1(m, "A"); py::class_<B, PyB, std::shared_ptr<B>> c2(m, "B"); py::class_<C, std::shared_ptr<C>, PyB> c3(m, "C"); It also allows future class attributes (such as base types in the next commit) to be passed as class template types rather than needing to use a py::base<> wrapper. -
Wenzel Jakob authored
-