Commit Graph

964 Commits

Author SHA1 Message Date
Jason Rhinelander
dc0b4bd2c9 Add debugging info about .so size to build output (#477)
* Add debugging info about so size to build output

This adds a small python script to tools that captures before-and-after
.so sizes between builds and outputs this in the build output via a
string such as:

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 924696 (decrease of 73680 bytes = 7.38%)

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (increase of 73680 bytes = 7.97%)

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (no change)

Or, if there was no .so during the build, just the .so size by itself:

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376

This allows you to, for example, build, checkout a different branch,
rebuild, and easily see exactly the change in the pybind11_tests.so
size.

It also allows looking at the travis and appveyor build logs to get an
idea of .so/.dll sizes across different build systems.

* Minor libsize.py script changes

- Use RAII open
- Remove unused libsize=-1
- Report change as [+-]xyz bytes = [+-]a.bc%
2016-11-04 14:47:41 +01:00
Wenzel Jakob
45e6e6f6eb add note about custom type casters (fixes #480) 2016-11-04 11:06:22 +01:00
Jason Rhinelander
12edaaa66a Only enable std::optional if compiling in >= C++14 (#476) 2016-11-03 16:17:11 +01:00
Ivan Smirnov
44a69f78cf std::experimental::optional (#475)
* Add type caster for std::experimental::optional

* Add tests for std::experimental::optional

* Support both <optional> / <experimental/optional>

* Mention std{::experimental,}::optional in the docs
2016-11-03 13:42:46 +01:00
Wenzel Jakob
bd560acf40 smart pointer refcount fix by @dean0x7d with slight modifications (fixes #471) 2016-11-03 11:53:35 +01:00
Wenzel Jakob
0a9ef9c300 Merge pull request #472 from aldanor/feature/shared-dtypes
Support for sharing dtypes across extensions + public shared data API
2016-11-03 11:08:50 +01:00
Ivan Smirnov
cc8ff16547 Move register_dtype() outside of the template
(avoid code bloat if possible)
2016-11-03 09:35:05 +00:00
Ivan Smirnov
f95fda0eb2 Add docs re: shared data API 2016-11-03 09:35:05 +00:00
Ivan Smirnov
2dbf029705 Add public shared_data API
NumPy internals are stored under "_numpy_internals" key.
2016-11-03 09:35:05 +00:00
Ivan Smirnov
c546655dc2 Use pytest fixtures in numpy dtypes test module 2016-11-03 09:35:05 +00:00
Ivan Smirnov
2184f6d4d6 NumPy dtypes are now shared across extensions 2016-11-03 09:35:05 +00:00
Wenzel Jakob
a743ead455 Merge pull request #474 from aldanor/feature/numpy-dtype-ex
Overriding field names when binding structured dtypes
2016-11-03 09:44:30 +01:00
Ivan Smirnov
abd3429ce9 Add a test for numpy dtypes with custom names 2016-11-01 13:29:32 +00:00
Ivan Smirnov
e8b50360fe Add dtype binding macro that allows setting names
PYBIND11_NUMPY_DTYPE_EX(Type, F1, "N1", F2, "N2", ...)
2016-11-01 13:27:35 +00:00
Dean Moldovan
03f627ebb1 Make reference(_internal) the default return value policy for properties (#473)
* Make reference(_internal) the default return value policy for properties

Before this, all `def_property*` functions used `automatic` as their
default return value policy. This commit makes it so that:

 * Non-static properties use `reference_interal` by default, thus
   matching `def_readonly` and `def_readwrite`.

 * Static properties use `reference` by default, thus matching
   `def_readonly_static` and `def_readwrite_static`.

In case `cpp_function` is passed to any `def_property*`, its policy will
be used instead of any defaults. User-defined arguments in `extras`
still have top priority and will override both the default policies and
the ones from `cpp_function`.

Resolves #436.

* Almost always use return_value_policy::move for rvalues

For functions which return rvalues or rvalue references, the only viable
return value policies are `copy` and `move`. `reference(_internal)` and
`take_ownership` would take the address of a temporary which is always
an error.

This commit prevents possible user errors by overriding the bad rvalue
policies with `move`. Besides `move`, only `copy` is allowed, and only
if it's explicitly selected by the user.

This is also a necessary safety feature to support the new default
return value policies for properties: `reference(_internal)`.
2016-11-01 11:44:57 +01:00
Wenzel Jakob
030d10e826 minor style fix 2016-10-28 01:23:42 +02:00
Wenzel Jakob
496feacfd0 pybind11: implicitly convert NumPy integer scalars
The current integer caster was unnecessarily strict and rejected
various kinds of NumPy integer types when calling C++ functions
expecting normal integers. This relaxes the current behavior.
2016-10-28 01:02:46 +02:00
Wenzel Jakob
a6f85eb985 Merge pull request #465 from jagerman/prevent-object-overwriting
Prevent overwriting previous declarations
2016-10-25 10:03:53 +02:00
Jason Rhinelander
6873c202b3 Prevent overwriting previous declarations
Currently pybind11 doesn't check when you define a new object (e.g. a
class, function, or exception) that overwrites an existing one.  If the
thing being overwritten is a class, this leads to a segfault (because
pybind still thinks the type is defined, even though Python no longer
has the type).  In other cases this is harmless (e.g. replacing a
function with an exception), but even in that case it's most likely a
bug.

This code doesn't prevent you from actively doing something harmful,
like deliberately overwriting a previous definition, but detects
overwriting with a run-time error if it occurs in the standard
class/function/exception/def registration interfaces.

All of the additions are in non-template code; the result is actually a
tiny decrease in .so size compared to master without the new test code
(977304 to 977272 bytes), and about 4K higher with the new tests.
2016-10-24 22:45:51 -04:00
Wenzel Jakob
dd9bd7778f Merge pull request #453 from aldanor/feature/numpy-scalars
NumPy scalars to ctypes conversion support
2016-10-25 01:15:25 +02:00
Ivan Smirnov
8f3e045deb Use detail::get_type_info() wherever sensible
This reduces direct access to internals.registered_types_cpp to
just a few places.
2016-10-24 23:55:52 +01:00
Wenzel Jakob
6ba98650e2 a bit of work on the new documentation structure 2016-10-24 23:48:20 +02:00
Ivan Smirnov
a6e6a8b108 Require existing typeinfo for direct conversions
This avoid a hashmap lookup since the pointer to the list of
direct converters is now cached in the typeinfo.
2016-10-23 15:29:10 +01:00
Wenzel Jakob
c0d19192d2 minor indentation change 2016-10-22 13:08:44 -04:00
Wenzel Jakob
f4eec65526 Merge pull request #455 from bennorth/bugfix/bad-delete-if-no-copy-ctor
Bugfix: bad delete if no copy ctor
2016-10-22 19:06:50 +02:00
Ivan Smirnov
43a88f4574 Reraise existing exception if dtype ctor fails 2016-10-22 18:57:07 +02:00
Ivan Smirnov
694269435b Allow implicit casts from literal strings to dtype 2016-10-22 18:57:07 +02:00
Ivan Smirnov
ef5a38044c A few dtype method docstrings 2016-10-22 18:57:07 +02:00
Ivan Smirnov
f70cc112f0 Make dtype from string ctor accept const ref 2016-10-22 18:57:07 +02:00
Jason Rhinelander
fb7c9fd326 Remove obsolete example reference (#457)
* Remove obsolete example reference
* Make example fully-working (except for #includes)

Fixes #456.
2016-10-22 18:54:33 +02:00
Wenzel Jakob
18e9590ca9 Merge pull request #458 from dean0x7d/fix-property
Fix def_property and related functions
2016-10-22 18:53:29 +02:00
Dean Moldovan
5b7e190fa2 Fix def_property and related functions
Making `cppfunction` explicit broke `def_property` and friends.
The added tests would not compile without an implicit `cppfunction`.
2016-10-21 18:51:14 +02:00
Ben North
bbe45082f4 Test uncopyable static member
Without the previous commit, this test generates a core dump.
2016-10-20 21:32:55 +01:00
Ben North
24a2054dbc Fix wrapper's 'value' and 'owned' if ctor missing
type_caster_generic::cast(): The values of

    wrapper->value
    wrapper->owned

are incorrect in the case that a return value policy of 'copy' is
requested but there is no copy-constructor.  (Similarly 'move'.)  In
particular, if the source object is a static instance, the destructor of
the 'object' 'inst' leads to class_::dealloc() which incorrectly
attempts to 'delete' the static instance.

This commit re-arranges the code to be clearer as to what the values of
'value' and 'owned' should be in the various cases.  Behaviour is
different to previous code only in two situations:

policy = copy but no copy-ctor: Old code leaves 'value = src, owned =
true', which leads to trouble.  New code leaves 'value = nullptr, owned
= false', which is correct.

policy = move but no move- or copy-ctor: old code leaves 'value = src,
owned = true', which leads to trouble.  New code leaves 'value =
nullptr, owned = false', which is correct.
2016-10-20 21:32:55 +01:00
Wenzel Jakob
77898af0f8 Merge pull request #454 from dean0x7d/shared_ptr
Support std::shared_ptr holder type out of the box
2016-10-20 19:16:32 +02:00
Ivan Smirnov
7edd72db24 Disallow registering dtypes multiple times 2016-10-20 16:57:12 +01:00
Ivan Smirnov
ccc69f91f4 Cache direct converters in the generic type caster 2016-10-20 16:52:24 +01:00
Wenzel Jakob
4f30446164 Merge pull request #448 from dean0x7d/docs
Reorganize documentation
2016-10-20 17:51:30 +02:00
Ivan Smirnov
cbbb7830f2 Add a test for NumPy scalar conversion 2016-10-20 16:47:29 +01:00
Ivan Smirnov
85e16262d6 Enable direct conversions with no typeinfo present 2016-10-20 16:46:40 +01:00
Ivan Smirnov
7bf90e8008 Add a direct converter for numpy scalars 2016-10-20 16:11:08 +01:00
Ivan Smirnov
c275ee6b46 Add support for "direct" converters 2016-10-20 16:09:31 +01:00
Ivan Smirnov
ba08db4da5 Import a few more numpy extern symbols 2016-10-20 16:09:10 +01:00
Dean Moldovan
5d28dd1194 Support std::shared_ptr holder type out of the box
With this there is no more need for manual user declarations like
`PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)`. Existing ones
will still compile without error -- they will just be ignored silently.

Resolves #446.
2016-10-20 16:19:58 +02:00
Dean Moldovan
f0b0df58a9 Directly compare 3 ways of moving data between C++ and Python 2016-10-20 15:21:34 +02:00
Dean Moldovan
67b52d808e Reorganize documentation 2016-10-20 15:21:34 +02:00
Wenzel Jakob
3eb569f4df Merge pull request #452 from aldanor/feature/numpy-enum
Auto-implement format/numpy descriptors for enum types
2016-10-20 14:41:38 +02:00
Ivan Smirnov
2f3f3687dc Add tests for numpy enum descriptors 2016-10-20 12:51:56 +01:00
Ivan Smirnov
fb74df50c9 Implement format/numpy descriptors for enums 2016-10-20 12:38:43 +01:00
Wenzel Jakob
35995856dd Merge pull request #450 from dean0x7d/explicit-bool
Make operator bool() explicit
2016-10-17 11:59:29 +02:00