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
37e1f61f
Commit
37e1f61f
authored
Jun 22, 2016
by
Wenzel Jakob
Browse files
allow passing a 'return value policy' to handle::operator()
parent
4a53d38b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
8 deletions
+15
-8
docs/advanced.rst
docs/advanced.rst
+3
-1
include/pybind11/cast.h
include/pybind11/cast.h
+6
-4
include/pybind11/common.h
include/pybind11/common.h
+3
-1
include/pybind11/pytypes.h
include/pybind11/pytypes.h
+3
-2
No files found.
docs/advanced.rst
View file @
37e1f61f
...
...
@@ -461,7 +461,9 @@ functions. The default policy is :enum:`return_value_policy::automatic`.
| | See below for a description of what all of these different policies do. |
+--------------------------------------------------+----------------------------------------------------------------------------+
| :enum:`return_value_policy::automatic_reference` | As above, but use policy :enum:`return_value_policy::reference` when the |
| | return value is a pointer. You probably won't need to use this. |
| | return value is a pointer. This is the default conversion policy for |
| | function arguments when calling Python functions manually from C++ code |
| | (i.e. via handle::operator()). You probably won't need to use this. |
+--------------------------------------------------+----------------------------------------------------------------------------+
| :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 |
...
...
include/pybind11/cast.h
View file @
37e1f61f
...
...
@@ -842,16 +842,18 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
return
result
;
}
template
<
typename
...
Args
>
object
handle
::
operator
()(
Args
&&
...
args
)
const
{
tuple
args_tuple
=
pybind11
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...);
template
<
return_value_policy
policy
,
typename
...
Args
>
object
handle
::
operator
()(
Args
&&
...
args
)
const
{
tuple
args_tuple
=
pybind11
::
make_tuple
<
policy
>
(
std
::
forward
<
Args
>
(
args
)...);
object
result
(
PyObject_CallObject
(
m_ptr
,
args_tuple
.
ptr
()),
false
);
if
(
!
result
)
throw
error_already_set
();
return
result
;
}
template
<
typename
...
Args
>
object
handle
::
call
(
Args
&&
...
args
)
const
{
return
operator
()(
std
::
forward
<
Args
>
(
args
)...);
template
<
return_value_policy
policy
,
typename
...
Args
>
object
handle
::
call
(
Args
&&
...
args
)
const
{
return
operator
()
<
policy
>
(
std
::
forward
<
Args
>
(
args
)...);
}
inline
object
handle
::
operator
()(
detail
::
args_proxy
args
)
const
{
...
...
include/pybind11/common.h
View file @
37e1f61f
...
...
@@ -151,7 +151,9 @@ enum class return_value_policy : uint8_t {
automatic
=
0
,
/** As above, but use policy return_value_policy::reference when the return
value is a pointer. You probably won't need to use this. */
value is a pointer. This is the default conversion policy for function
arguments when calling Python functions manually from C++ code (i.e. via
handle::operator()). You probably won't need to use this. */
automatic_reference
,
/** Reference an existing object (i.e. do not create a new copy) and take
...
...
include/pybind11/pytypes.h
View file @
37e1f61f
...
...
@@ -39,12 +39,13 @@ public:
inline
detail
::
accessor
attr
(
const
char
*
key
)
const
;
inline
pybind11
::
str
str
()
const
;
template
<
typename
T
>
T
cast
()
const
;
template
<
typename
...
Args
>
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
#if __cplusplus > 201103L
[[
deprecated
(
"call(...) was deprecated in favor of operator()(...)"
)]]
#endif
object
call
(
Args
&&
...
args
)
const
;
template
<
typename
...
Args
>
object
operator
()(
Args
&&
...
args
)
const
;
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
object
operator
()(
Args
&&
...
args
)
const
;
inline
object
operator
()(
detail
::
args_proxy
args
)
const
;
inline
object
operator
()(
detail
::
args_proxy
f_args
,
detail
::
kwargs_proxy
kwargs
)
const
;
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
...
...
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