- 24 Feb, 2017 1 commit
-
-
* Make string conversion stricter The string conversion logic added in PR #624 for all std::basic_strings was derived from the old std::wstring logic, but that was underused and turns out to have had a bug in accepting almost anything convertible to unicode, while the previous std::string logic was much stricter. This restores the previous std::string logic by only allowing actual unicode or string types. Fixes #685. * Added missing 'requires numpy' decorator (I forgot that the change to a global decorator here is in the not-yet-merged Eigen PR)
Jason Rhinelander committed
-
- 23 Feb, 2017 4 commits
-
-
Now that only one shared metaclass is ever allocated, it's extremely cheap to enable it for all pybind11 types. * Deprecate the default py::metaclass() since it's not needed anymore. * Allow users to specify a custom metaclass via py::metaclass(handle).
Dean Moldovan committed -
In order to fully satisfy Python's inheritance type layout requirements, all types should have a common 'solid' base. A solid base is one which has the same instance size as the derived type (not counting the space required for the optional `dict_ptr` and `weakrefs_ptr`). Thus, `object` does not qualify as a solid base for pybind11 types and this can lead to issues with multiple inheritance. To get around this, new base types are created: one per unique instance size. There is going to be very few of these bases. They ensure Python's MRO checks will pass when multiple bases are involved.
Dean Moldovan committed -
Instead of creating a new unique metaclass for each type, the builtin `property` type is subclassed to support static properties. The new setter/getters always pass types instead of instances in their `self` argument. A metaclass is still required to support this behavior, but it doesn't store any data anymore, so a new one doesn't need to be created for each class. There is now only one common metaclass which is shared by all pybind11 types.
Dean Moldovan committed -
* Switch breathe to stable releases. It was previously pulling directly from master because a required bugfix was not in a stable release yet. * Force update sphinx and RTD theme. When using conda, readthedocs pins sphinx==1.3.5 and sphinx_rtd_theme==0.1.7, which is a bit older than the ones used in the RTD regular (non-conda) build. The newer theme has nicer sidebar navigation (4-level depth vs. only 2-level on the older version). Note that the python==3.5 requirement must stay because RTD still installs the older sphinx at one point which isn't available with Python 3.6. [skip ci]
Dean Moldovan committed
-
- 22 Feb, 2017 1 commit
-
-
* Fixed compilation error when defining function accepting some forms of std::function. The compilation error happens only when the functional.h header is present, and the build is done in debug mode, with NDEBUG being undefined. In addition, the std::function must accept an abstract base class by reference. The compilation error occurred in cast.h, when trying to construct a std::tuple<AbstractBase>, rather than a std::tuple<AbstractBase&>. This was caused by functional.h using std::move rather than std::forward, changing the signature of the function being used. This commit contains the fix, along with a test that exhibits the issue when compiled in debug mode without the fix applied. * Moved new std::function tests into test_callbacks, added callback_with_movable test.
Lunderberg committed
-
- 18 Feb, 2017 1 commit
-
-
* fix warning when Python.h was included before pybind11.h * remove trailing whitespace
Matthias Möller committed
-
- 17 Feb, 2017 3 commits
-
-
Wenzel Jakob committed
-
* changed return_value:: to return_value_policy:: * Update functions.rst
thorink committed -
noexcept deduction, added in PR #555, doesn't work with clang's -std=c++1z; and while it works with g++, it isn't entirely clear to me that it is required to work in C++17. What should work, however, is that C++17 allows implicit conversion of a `noexcept(true)` function pointer to a `noexcept(false)` (i.e. default, noexcept-not-specified) function pointer. That was breaking in pybind11 because the cpp_function template used for lambdas provided a better match (i.e. without requiring an implicit conversion), but it then failed. This commit takes a different approach of using SFINAE on the lambda function to prevent it from matching a non-lambda object, which then gets implicit conversion from a `noexcept` function pointer to a `noexcept(false)` function pointer. This much nicer solution also gets rid of the C++17 NOEXCEPT macros, and works in both clang and g++.
Jason Rhinelander committed
-
- 14 Feb, 2017 10 commits
-
-
Dean Moldovan committed
-
* Add flag for installation of headers under python include directory * Allow the disabling of distutils install_headers
Sylvain Corlay committed -
Fixes #667 The sphinx version is pinned by readthedocs, but sphinx 1.3.5 is not available with conda python 3.6. The workaround is to pin the python version to 3.5 (it doesn't really matter for the docs build).
Dean Moldovan committed -
This reverts commit bee8827a.
Dean Moldovan committed -
* Propagate unicode conversion failure If returning a std::string with invalid utf-8 data, we currently fail with an uninformative TypeError instead of propagating the UnicodeDecodeError that Python sets on failure. * Add support for u16/u32strings and literals This adds support for wchar{16,32}_t character literals and the associated std::u{16,32}string types. It also folds the character/string conversion into a single type_caster template, since the type casters for string and wstring were mostly the same anyway. * Added too-long and too-big character conversion errors With this commit, when casting to a single character, as opposed to a C-style string, we make sure the input wasn't a multi-character string or a single character with codepoint too large for the character type. This also changes the character cast op to CharT instead of CharT& (we need to be able to return a temporary decoded char value, but also because there's little gained by bothering with an lvalue return here). Finally it changes the char caster to 'has-a-string-caster' instead of 'is-a-string-caster' because, with the cast_op change above, there's nothing at all gained from inheritance. This also lets us remove the `success` from the string caster (which was only there for the char caster) into the char caster itself. (I also renamed it to 'none' and inverted its value to better reflect its purpose). The None -> nullptr loading also now takes place only under a `convert = true` load pass. Although it's unlikely that a function taking a char also has overloads that can take a None, it seems marginally more correct to treat it as a conversion. This commit simplifies the size assumptions about character sizes with static_asserts to back them up.Jason Rhinelander committed -
Recent gcc snapshots (both gcc 7 snapshots and recent gcc 6 stable branch snapshots) are triggering an upstream gcc bug when -flto is enabled (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79296). This has been hitting the gcc-7 builds for a while now, but is going to start hitting the debian testing builds in a few days as well. The issue is triggered by using -flto in combination with structs or classes declared in a function, as done in test_alias_initialization, test_isses, test_methods_and_attributes (and possibly more). I'm subscribed to the upstream bug, and will submit another PR to reenable LTO once a fixed gcc is available. The gcc-7 build also generates some warnings; just ignore them for now (by turning off -Werror).
Jason Rhinelander committed -
This both lets us not bother rechecking LTO flags when cmake reinvokes itself, and also lets the cmake invoker override to specify custom or no LTO flags by setting the cache variable with -DPYBIND11_LTO_CXX_FLAGS= when invoking cmake.
Jason Rhinelander committed -
Clang on linux currently fails to run cmake: $ CC=clang CXX=clang++ cmake .. ... -- Configuring done CMake Error at tools/pybind11Tools.cmake:135 (target_compile_options): Error evaluating generator expression: $<:-flto> Expression did not evaluate to a known generator expression Call Stack (most recent call first): tests/CMakeLists.txt:68 (pybind11_add_module) But investigating this led to various other -flto detection problems; this commit thus overhauls LTO flag detection: - -flto needs to be passed to the linker as well - Also compile with -fno-fat-lto-objects under GCC - Pass the equivalent flags to MSVC - Enable LTO flags for via generator expressions (for non-debug builds only), so that multi-config builds (like on Windows) still work properly. This seems reasonable, however, even on single-config builds (and simplifies the cmake code a bit). - clang's lto linker plugins don't accept '-Os', so replace it with '-O3' when doing a MINSIZEREL build - Enable trying ThinLTO by default for test suite (only affects clang) - Match Clang$ rather than ^Clang$ because, for cmake with 3.0+ policies in effect, the compiler ID will be AppleClang on macOS.Jason Rhinelander committed -
Sylvain Corlay committed
-
Dean Moldovan committed
-
- 08 Feb, 2017 5 commits
-
-
Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR as the base of the path to libsize.py. This fixes an error if pybind11 is being built directly within another project.
Matthew Woehlke committed -
* Avoid C-style const casts Replace C-style casts that discard `const` with `const_cast` (and, where necessary, `reinterpret_cast` as well). * Warn about C-style const-discarding casts Change pybind11_enable_warnings to also enable `-Wcast-qual` (warn if a C-style cast discards `const`) by default. The previous commit should have gotten rid of all of these (at least, all the ones that tripped in my build, which included the tests), and this should discourage more from newly appearing.
Matthew Woehlke committed -
Fixes #656. Before this commit, the problematic sequence was: 1. `catch (const std::exception &e)` gets a Python exception, i.e. `error_already_set`. 2. `PyErr_SetString(PyExc_ImportError, e.what())` sets an `ImportError`. 3. `~error_already_set()` now runs, but `gil_scoped_acquire` fails due to an unhandled `ImportError` (which was just set in step 2). This commit adds a separate catch block for Python exceptions which just clears the Python error state a little earlier and replaces it with an `ImportError`, thus making sure that there is only a single Python exception in flight at a time. (After step 2 in the sequence above, there were effectively two Python expections set.)
Dean Moldovan committed -
* Fix debugging output for nameless py::arg annotations This fixes a couple bugs with nameless py::arg() (introduced in #634) annotations: - the argument name was being used in debug mode without checking that it exists (which would result in the std::string construction throwing an exception for being invoked with a nullptr) - the error output says "keyword arguments", but py::arg_v() can now also be used for positional argument defaults. - the debugging output "in function named 'blah'" was overly verbose: changed it to just "in function 'blah'". * Fix missing space in debug test string * Moved tests from issues to methods_and_attributes
Jason Rhinelander committed -
Add a GitHub issue template
Wenzel Jakob committed
-
- 07 Feb, 2017 1 commit
-
-
[skip ci]
Dean Moldovan committed
-
- 06 Feb, 2017 1 commit
-
-
(Identifiers starting with underscores are reserved by the standard) Also fixed a typo in a comment.
Wenzel Jakob committed
-
- 05 Feb, 2017 2 commits
-
-
Prefer non-converting argument overloads
Wenzel Jakob committed -
Add support for non-converting arguments
Wenzel Jakob committed
-
- 04 Feb, 2017 3 commits
-
-
This changes the function dispatching code for overloaded functions into a two-pass procedure where we first try all overloads with `convert=false` for all arguments. If no function calls succeeds in the first pass, we then try a second pass where we allow arguments to have `convert=true` (unless, of course, the argument was explicitly specified with `py::arg().noconvert()`). For non-overloaded methods, the two-pass procedure is skipped (we just make the overload-allowed call). The second pass is also skipped if it would result in the same thing (i.e. where all arguments are `.noconvert()` arguments).
Jason Rhinelander committed -
This adds support for controlling the `convert` flag of arguments through the py::arg annotation. This then allows arguments to be flagged as non-converting, which the type_caster is able to use to request different behaviour. Currently, AFAICS `convert` is only used for type converters of regular pybind11-registered types; all of the other core type_casters ignore it. We can, however, repurpose it to control internal conversion of converters like Eigen and `array`: most usefully to give callers a way to disable the conversion that would otherwise occur when a `Eigen::Ref<const Eigen::Matrix>` argument is passed a numpy array that requires conversion (either because it has an incompatible stride or the wrong dtype). Specifying a noconvert looks like one of these: m.def("f1", &f, "a"_a.noconvert() = "default"); // Named, default, noconvert m.def("f2", &f, "a"_a.noconvert()); // Named, no default, no converting m.def("f3", &f, py::arg().noconvert()); // Unnamed, no default, no converting (The last part--being able to declare a py::arg without a name--is new: previous py::arg() only accepted named keyword arguments). Such an non-convert argument is then passed `convert = false` by the type caster when loading the argument. Whether this has an effect is up to the type caster itself, but as mentioned above, this would be extremely helpful for the Eigen support to give a nicer way to specify a "no-copy" mode than the custom wrapper in the current PR, and moreover isn't an Eigen-specific hack.Jason Rhinelander committed -
Arithmetic and complex casters now only do a converting cast when `convert=true`; previously they would convert always (e.g. when passing an int to a float-accepting function, or a float to complex-accepting function).
Jason Rhinelander committed
-
- 02 Feb, 2017 1 commit
-
-
* Add documentation for strings and Unicode issues * More Unicode documentation on character literals and wide characters
jbarlow83 committed
-
- 01 Feb, 2017 1 commit
-
-
Issue #633 suggests people might be tempted to copy the test scripts self-binding code, but that's a bad idea for pretty much anything other than a test suite with self-contained test code. This commit adds a comment as such with a reference to the documentation that tells people how to do it instead.
Jason Rhinelander committed
-
- 31 Jan, 2017 6 commits
-
-
* Minor doc syntax fix The numpy documentation had a bad :file: reference (was using double backticks instead of single backticks). * Changed long-outdated "example" -> "tests" wording The ConstructorStats internal docs still had "from example import", and the main testing cpp file still used "example" in the module description.
Jason Rhinelander committed -
Wenzel Jakob committed
-
This cleans up the previous commit slightly by further reducing the function call arguments to a single struct (containing the function_record, arguments vector, and parent). Although this doesn't currently change anything, it does allow for future functionality to have a place for precalls to store temporary objects that need to be destroyed after a function call (whether or not the call succeeds). As a concrete example, with this change #625 could be easily implemented (I think) by adding a std::unique_ptr<gil_scoped_release> member to the `function_call` struct with a precall that actually constructs it. Without this, the precall can't do that: the postcall won't be invoked if the call throws an exception. This doesn't seems to affect the .so size noticeably (either way).
Jason Rhinelander committed -
Jason Rhinelander committed
-
This keeps it with constexpr_sum and the other metafunctions.
Jason Rhinelander committed -
Passing a negative value wasn't valid anyway, and moreover this avoids a little bit of extra code to avoid signed/unsigned argument warnings.
Jason Rhinelander committed
-