Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
f53e300f
Commit
f53e300f
authored
Jun 30, 2016
by
Wenzel Jakob
Browse files
doc updates
parent
09e22b4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
docs/advanced.rst
docs/advanced.rst
+8
-9
No files found.
docs/advanced.rst
View file @
f53e300f
...
...
@@ -468,7 +468,7 @@ functions. The default policy is :enum:`return_value_policy::automatic`.
| :enum:`return_value_policy::take_ownership` | Reference an existing object (i.e. do not create a new copy) and take |
| | ownership. Python will call the destructor and delete operator when the |
| | object's reference count reaches zero. Undefined behavior ensues when the |
| | C++ side does the same. |
| | C++ side does the same.
|
+--------------------------------------------------+----------------------------------------------------------------------------+
| :enum:`return_value_policy::copy` | Create a new copy of the returned object, which will be owned by Python. |
| | This policy is comparably safe because the lifetimes of the two instances |
...
...
@@ -526,14 +526,13 @@ The following example snippet shows a use case of the
non-determinism and segmentation faults, hence it is worth spending the
time to understand all the different options in the table above.
.. warning::
pybind11 tries to eliminate duplicate addresses by returning the same reference object.
If two addresses are the same, though they do not point to the same object semantically,
this may cause unexpected behaviour. An explicit policy should be used instead of
relying on `automatic`.
A common example is a reference to the first member of a class which has the same memory
location as its owning class.
It is worth highlighting one common issue where a method (e.g. a getter)
returns a reference (or pointer) to the first attribute of a class. In this
case, the class and attribute will be located at the same address in
memory, which pybind11 will recongnize and return the parent instance
instead of creating a new Python object that represents the attribute.
Here, the :enum:`return_value_policy::reference_internal` policy should be
used rather than relying on the automatic one.
.. note::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment