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
eb7c0b82
Commit
eb7c0b82
authored
Nov 16, 2015
by
Wenzel Jakob
Browse files
functional.h: support more kinds of Python functions
parent
3ee91b2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
include/pybind11/functional.h
include/pybind11/functional.h
+2
-1
include/pybind11/pytypes.h
include/pybind11/pytypes.h
+14
-10
No files found.
include/pybind11/functional.h
View file @
eb7c0b82
...
...
@@ -20,7 +20,8 @@ template <typename Return, typename... Args> struct type_caster<std::function<Re
public:
bool
load
(
PyObject
*
src_
,
bool
)
{
if
(
!
PyFunction_Check
(
src_
))
src_
=
detail
::
get_function
(
src_
);
if
(
!
src_
||
!
(
PyFunction_Check
(
src_
)
||
PyCFunction_Check
(
src_
)))
return
false
;
object
src
(
src_
,
true
);
value
=
[
src
](
Args
...
args
)
->
Return
{
...
...
include/pybind11/pytypes.h
View file @
eb7c0b82
...
...
@@ -94,6 +94,18 @@ private:
};
NAMESPACE_BEGIN
(
detail
)
inline
PyObject
*
get_function
(
PyObject
*
value
)
{
if
(
value
==
nullptr
)
return
nullptr
;
#if PY_MAJOR_VERSION >= 3
if
(
PyInstanceMethod_Check
(
value
))
value
=
PyInstanceMethod_GET_FUNCTION
(
value
);
#endif
if
(
PyMethod_Check
(
value
))
value
=
PyMethod_GET_FUNCTION
(
value
);
return
value
;
}
class
accessor
{
public:
accessor
(
PyObject
*
obj
,
PyObject
*
key
,
bool
attr
)
...
...
@@ -346,16 +358,8 @@ public:
PYBIND11_OBJECT_DEFAULT
(
function
,
object
,
PyFunction_Check
)
bool
is_cpp_function
()
{
PyObject
*
ptr
=
m_ptr
;
if
(
ptr
==
nullptr
)
return
false
;
#if PY_MAJOR_VERSION >= 3
if
(
PyInstanceMethod_Check
(
ptr
))
ptr
=
PyInstanceMethod_GET_FUNCTION
(
ptr
);
#endif
if
(
PyMethod_Check
(
ptr
))
ptr
=
PyMethod_GET_FUNCTION
(
ptr
);
return
PyCFunction_Check
(
ptr
);
PyObject
*
ptr
=
detail
::
get_function
(
m_ptr
);
return
ptr
!=
nullptr
&&
PyCFunction_Check
(
ptr
);
}
};
...
...
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