Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
bf099587
Commit
bf099587
authored
Aug 22, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation clarifications (fixes #346)
parent
192eb884
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
docs/advanced.rst
+22
-6
No files found.
docs/advanced.rst
View file @
bf099587
...
@@ -583,6 +583,19 @@ For this reason, pybind11 provides a several `return value policy` annotations
...
@@ -583,6 +583,19 @@ For this reason, pybind11 provides a several `return value policy` annotations
that can be passed to the :func:`module::def` and :func:`class_::def`
that can be passed to the :func:`module::def` and :func:`class_::def`
functions. The default policy is :enum:`return_value_policy::automatic`.
functions. The default policy is :enum:`return_value_policy::automatic`.
Return value policies can also be applied to properties, in which case the
arguments must be passed through the :class:`cpp_function` constructor:
.. code-block:: cpp
class_<MyClass>(m, "MyClass")
def_property("data"
py::cpp_function(&MyClass::getData, py::return_value_policy::copy),
py::cpp_function(&MyClass::setData)
);
The following table provides an overview of the available return value policies:
.. tabularcolumns:: |p{0.5\textwidth}|p{0.45\textwidth}|
.. tabularcolumns:: |p{0.5\textwidth}|p{0.45\textwidth}|
+--------------------------------------------------+----------------------------------------------------------------------------+
+--------------------------------------------------+----------------------------------------------------------------------------+
...
@@ -617,11 +630,14 @@ functions. The default policy is :enum:`return_value_policy::automatic`.
...
@@ -617,11 +630,14 @@ functions. The default policy is :enum:`return_value_policy::automatic`.
| | it is no longer used. Warning: undefined behavior will ensue when the C++ |
| | it is no longer used. Warning: undefined behavior will ensue when the C++ |
| | side deletes an object that is still referenced and used by Python. |
| | side deletes an object that is still referenced and used by Python. |
+--------------------------------------------------+----------------------------------------------------------------------------+
+--------------------------------------------------+----------------------------------------------------------------------------+
| :enum:`return_value_policy::reference_internal` | Like :enum:`return_value_policy::reference` but additionally applies a |
| :enum:`return_value_policy::reference_internal` | Indicates that the lifetime of the return value is tied to the lifetime |
| | ``keep_alive<0, 1>`` call policy (described next) that keeps the |
| | of a parent object, namely the implicit ``this``, or ``self`` argument of |
| | ``this`` argument of the function or property from being garbage collected |
| | the called method or property. Internally, this policy works just like |
| | as long as the return value remains referenced. See the |
| | :enum:`return_value_policy::reference` but additionally applies a |
| | :class:`keep_alive` call policy (described next) for details. |
| | ``keep_alive<0, 1>`` *call policy* (described in the next section) that |
| | prevents the parent object from being garbage collected as long as the |
| | return value is referenced by Python. This is the default policy for |
| | property getters created via ``def_property``, ``def_readwrite``, etc.) |
+--------------------------------------------------+----------------------------------------------------------------------------+
+--------------------------------------------------+----------------------------------------------------------------------------+
.. warning::
.. warning::
...
@@ -636,7 +652,7 @@ which pybind11 has *not* seen before, in which case the policy clarifies
...
@@ -636,7 +652,7 @@ which pybind11 has *not* seen before, in which case the policy clarifies
essential questions about the return value's lifetime and ownership. When
essential questions about the return value's lifetime and ownership. When
pybind11 knows the instance already (as identified by its type and address in
pybind11 knows the instance already (as identified by its type and address in
memory), it will return the existing Python object wrapper rather than creating
memory), it will return the existing Python object wrapper rather than creating
a copy.
a
new
copy.
.. note::
.. 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