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
39577e8c
Commit
39577e8c
authored
Sep 08, 2016
by
Wenzel Jakob
Committed by
GitHub
Sep 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #396 from aldanor/feature/is_none
Add handle::is_none()
parents
8706fb90
984c7624
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
13 deletions
+14
-13
include/pybind11/cast.h
+10
-10
include/pybind11/functional.h
+2
-2
include/pybind11/pybind11.h
+1
-1
include/pybind11/pytypes.h
+1
-0
No files found.
include/pybind11/cast.h
View file @
39577e8c
...
@@ -155,7 +155,7 @@ public:
...
@@ -155,7 +155,7 @@ public:
PYBIND11_NOINLINE
bool
load
(
handle
src
,
bool
convert
)
{
PYBIND11_NOINLINE
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
src
||
!
typeinfo
)
if
(
!
src
||
!
typeinfo
)
return
false
;
return
false
;
if
(
src
.
ptr
()
==
Py_None
)
{
if
(
src
.
is_none
()
)
{
value
=
nullptr
;
value
=
nullptr
;
return
true
;
return
true
;
}
else
if
(
PyType_IsSubtype
(
Py_TYPE
(
src
.
ptr
()),
typeinfo
->
type
))
{
}
else
if
(
PyType_IsSubtype
(
Py_TYPE
(
src
.
ptr
()),
typeinfo
->
type
))
{
...
@@ -180,7 +180,7 @@ public:
...
@@ -180,7 +180,7 @@ public:
const
void
*
existing_holder
=
nullptr
)
{
const
void
*
existing_holder
=
nullptr
)
{
void
*
src
=
const_cast
<
void
*>
(
_src
);
void
*
src
=
const_cast
<
void
*>
(
_src
);
if
(
src
==
nullptr
)
if
(
src
==
nullptr
)
return
handle
(
Py_None
).
inc_ref
();
return
none
();
auto
&
internals
=
get_internals
();
auto
&
internals
=
get_internals
();
...
@@ -408,7 +408,7 @@ template <> class type_caster<void_type> {
...
@@ -408,7 +408,7 @@ template <> class type_caster<void_type> {
public
:
public
:
bool
load
(
handle
,
bool
)
{
return
false
;
}
bool
load
(
handle
,
bool
)
{
return
false
;
}
static
handle
cast
(
void_type
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
void_type
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
handle
(
Py_None
).
inc_ref
();
return
none
();
}
}
PYBIND11_TYPE_CASTER
(
void_type
,
_
(
"None"
));
PYBIND11_TYPE_CASTER
(
void_type
,
_
(
"None"
));
};
};
...
@@ -420,7 +420,7 @@ public:
...
@@ -420,7 +420,7 @@ public:
bool
load
(
handle
h
,
bool
)
{
bool
load
(
handle
h
,
bool
)
{
if
(
!
h
)
{
if
(
!
h
)
{
return
false
;
return
false
;
}
else
if
(
h
.
ptr
()
==
Py_None
)
{
}
else
if
(
h
.
is_none
()
)
{
value
=
nullptr
;
value
=
nullptr
;
return
true
;
return
true
;
}
}
...
@@ -446,7 +446,7 @@ public:
...
@@ -446,7 +446,7 @@ public:
if
(
ptr
)
if
(
ptr
)
return
capsule
(
ptr
).
release
();
return
capsule
(
ptr
).
release
();
else
else
return
handle
(
Py_None
).
inc_ref
();
return
none
();
}
}
template
<
typename
T
>
using
cast_op_type
=
void
*&
;
template
<
typename
T
>
using
cast_op_type
=
void
*&
;
...
@@ -558,12 +558,12 @@ protected:
...
@@ -558,12 +558,12 @@ protected:
template
<>
class
type_caster
<
char
>
:
public
type_caster
<
std
::
string
>
{
template
<>
class
type_caster
<
char
>
:
public
type_caster
<
std
::
string
>
{
public
:
public
:
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
if
(
src
.
ptr
()
==
Py_None
)
return
true
;
if
(
src
.
is_none
()
)
return
true
;
return
type_caster
<
std
::
string
>::
load
(
src
,
convert
);
return
type_caster
<
std
::
string
>::
load
(
src
,
convert
);
}
}
static
handle
cast
(
const
char
*
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
char
*
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
if
(
src
==
nullptr
)
return
handle
(
Py_None
).
inc_ref
();
if
(
src
==
nullptr
)
return
none
();
return
PyUnicode_FromString
(
src
);
return
PyUnicode_FromString
(
src
);
}
}
...
@@ -581,12 +581,12 @@ public:
...
@@ -581,12 +581,12 @@ public:
template
<>
class
type_caster
<
wchar_t
>
:
public
type_caster
<
std
::
wstring
>
{
template
<>
class
type_caster
<
wchar_t
>
:
public
type_caster
<
std
::
wstring
>
{
public
:
public
:
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
if
(
src
.
ptr
()
==
Py_None
)
return
true
;
if
(
src
.
is_none
()
)
return
true
;
return
type_caster
<
std
::
wstring
>::
load
(
src
,
convert
);
return
type_caster
<
std
::
wstring
>::
load
(
src
,
convert
);
}
}
static
handle
cast
(
const
wchar_t
*
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
wchar_t
*
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
if
(
src
==
nullptr
)
return
handle
(
Py_None
).
inc_ref
();
if
(
src
==
nullptr
)
return
none
();
return
PyUnicode_FromWideChar
(
src
,
(
ssize_t
)
wcslen
(
src
));
return
PyUnicode_FromWideChar
(
src
,
(
ssize_t
)
wcslen
(
src
));
}
}
...
@@ -757,7 +757,7 @@ public:
...
@@ -757,7 +757,7 @@ public:
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
src
||
!
typeinfo
)
{
if
(
!
src
||
!
typeinfo
)
{
return
false
;
return
false
;
}
else
if
(
src
.
ptr
()
==
Py_None
)
{
}
else
if
(
src
.
is_none
()
)
{
value
=
nullptr
;
value
=
nullptr
;
return
true
;
return
true
;
}
else
if
(
PyType_IsSubtype
(
Py_TYPE
(
src
.
ptr
()),
typeinfo
->
type
))
{
}
else
if
(
PyType_IsSubtype
(
Py_TYPE
(
src
.
ptr
()),
typeinfo
->
type
))
{
...
...
include/pybind11/functional.h
View file @
39577e8c
...
@@ -20,7 +20,7 @@ template <typename Return, typename... Args> struct type_caster<std::function<Re
...
@@ -20,7 +20,7 @@ template <typename Return, typename... Args> struct type_caster<std::function<Re
typedef
typename
std
::
conditional
<
std
::
is_same
<
Return
,
void
>::
value
,
void_type
,
Return
>::
type
retval_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
Return
,
void
>::
value
,
void_type
,
Return
>::
type
retval_type
;
public
:
public
:
bool
load
(
handle
src_
,
bool
)
{
bool
load
(
handle
src_
,
bool
)
{
if
(
src_
.
ptr
()
==
Py_None
)
if
(
src_
.
is_none
()
)
return
true
;
return
true
;
src_
=
detail
::
get_function
(
src_
);
src_
=
detail
::
get_function
(
src_
);
...
@@ -62,7 +62,7 @@ public:
...
@@ -62,7 +62,7 @@ public:
template
<
typename
Func
>
template
<
typename
Func
>
static
handle
cast
(
Func
&&
f_
,
return_value_policy
policy
,
handle
/* parent */
)
{
static
handle
cast
(
Func
&&
f_
,
return_value_policy
policy
,
handle
/* parent */
)
{
if
(
!
f_
)
if
(
!
f_
)
return
handle
(
Py_None
).
inc_ref
();
return
none
();
auto
result
=
f_
.
template
target
<
Return
(
*
)(
Args
...)
>
();
auto
result
=
f_
.
template
target
<
Return
(
*
)(
Args
...)
>
();
if
(
result
)
if
(
result
)
...
...
include/pybind11/pybind11.h
View file @
39577e8c
...
@@ -1143,7 +1143,7 @@ inline void keep_alive_impl(handle nurse, handle patient) {
...
@@ -1143,7 +1143,7 @@ inline void keep_alive_impl(handle nurse, handle patient) {
if
(
!
nurse
||
!
patient
)
if
(
!
nurse
||
!
patient
)
pybind11_fail
(
"Could not activate keep_alive!"
);
pybind11_fail
(
"Could not activate keep_alive!"
);
if
(
patient
.
ptr
()
==
Py_None
||
nurse
.
ptr
()
==
Py_None
)
if
(
patient
.
is_none
()
||
nurse
.
is_none
()
)
return
;
/* Nothing to keep alive or nothing to be kept alive by */
return
;
/* Nothing to keep alive or nothing to be kept alive by */
cpp_function
disable_lifesupport
(
cpp_function
disable_lifesupport
(
...
...
include/pybind11/pytypes.h
View file @
39577e8c
...
@@ -40,6 +40,7 @@ public:
...
@@ -40,6 +40,7 @@ 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
;
inline
pybind11
::
str
repr
()
const
;
inline
pybind11
::
str
repr
()
const
;
bool
is_none
()
const
{
return
m_ptr
==
Py_None
;
}
template
<
typename
T
>
T
cast
()
const
;
template
<
typename
T
>
T
cast
()
const
;
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
#if __cplusplus > 201103L
#if __cplusplus > 201103L
...
...
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