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
37e1f61f
Commit
37e1f61f
authored
Jun 22, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow passing a 'return value policy' to handle::operator()
parent
4a53d38b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
8 deletions
+15
-8
docs/advanced.rst
+3
-1
include/pybind11/cast.h
+6
-4
include/pybind11/common.h
+3
-1
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`.
...
@@ -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. |
| | 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 |
| :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 |
| :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 |
| | 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,
...
@@ -842,16 +842,18 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
return
result
;
return
result
;
}
}
template
<
typename
...
Args
>
object
handle
::
operator
()(
Args
&&
...
args
)
const
{
template
<
return_value_policy
policy
,
tuple
args_tuple
=
pybind11
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...);
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
);
object
result
(
PyObject_CallObject
(
m_ptr
,
args_tuple
.
ptr
()),
false
);
if
(
!
result
)
if
(
!
result
)
throw
error_already_set
();
throw
error_already_set
();
return
result
;
return
result
;
}
}
template
<
typename
...
Args
>
object
handle
::
call
(
Args
&&
...
args
)
const
{
template
<
return_value_policy
policy
,
return
operator
()(
std
::
forward
<
Args
>
(
args
)...);
typename
...
Args
>
object
handle
::
call
(
Args
&&
...
args
)
const
{
return
operator
()
<
policy
>
(
std
::
forward
<
Args
>
(
args
)...);
}
}
inline
object
handle
::
operator
()(
detail
::
args_proxy
args
)
const
{
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 {
...
@@ -151,7 +151,9 @@ enum class return_value_policy : uint8_t {
automatic
=
0
,
automatic
=
0
,
/** As above, but use policy return_value_policy::reference when the return
/** 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
,
automatic_reference
,
/** Reference an existing object (i.e. do not create a new copy) and take
/** 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:
...
@@ -39,12 +39,13 @@ public:
inline
detail
::
accessor
attr
(
const
char
*
key
)
const
;
inline
detail
::
accessor
attr
(
const
char
*
key
)
const
;
inline
pybind11
::
str
str
()
const
;
inline
pybind11
::
str
str
()
const
;
template
<
typename
T
>
T
cast
()
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
#if __cplusplus > 201103L
[[
deprecated
(
"call(...) was deprecated in favor of operator()(...)"
)]]
[[
deprecated
(
"call(...) was deprecated in favor of operator()(...)"
)]]
#endif
#endif
object
call
(
Args
&&
...
args
)
const
;
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
args
)
const
;
inline
object
operator
()(
detail
::
args_proxy
f_args
,
detail
::
kwargs_proxy
kwargs
)
const
;
inline
object
operator
()(
detail
::
args_proxy
f_args
,
detail
::
kwargs_proxy
kwargs
)
const
;
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
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