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
8e40e389
Unverified
Commit
8e40e389
authored
Jul 28, 2020
by
Marcin Wojdyr
Committed by
GitHub
Jul 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cast pointer to std::tuple and std::pair (#2334)
parent
c51b3f43
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
include/pybind11/cast.h
+11
-0
tests/test_builtin_casters.cpp
+4
-0
tests/test_builtin_casters.py
+3
-0
No files found.
include/pybind11/cast.h
View file @
8e40e389
...
@@ -1421,6 +1421,17 @@ public:
...
@@ -1421,6 +1421,17 @@ public:
return
cast_impl
(
std
::
forward
<
T
>
(
src
),
policy
,
parent
,
indices
{});
return
cast_impl
(
std
::
forward
<
T
>
(
src
),
policy
,
parent
,
indices
{});
}
}
// copied from the PYBIND11_TYPE_CASTER macro
template
<
typename
T
>
static
handle
cast
(
T
*
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
!
src
)
return
none
().
release
();
if
(
policy
==
return_value_policy
::
take_ownership
)
{
auto
h
=
cast
(
std
::
move
(
*
src
),
policy
,
parent
);
delete
src
;
return
h
;
}
else
{
return
cast
(
*
src
,
policy
,
parent
);
}
}
static
constexpr
auto
name
=
_
(
"Tuple["
)
+
concat
(
make_caster
<
Ts
>::
name
...)
+
_
(
"]"
);
static
constexpr
auto
name
=
_
(
"Tuple["
)
+
concat
(
make_caster
<
Ts
>::
name
...)
+
_
(
"]"
);
template
<
typename
T
>
using
cast_op_type
=
type
;
template
<
typename
T
>
using
cast_op_type
=
type
;
...
...
tests/test_builtin_casters.cpp
View file @
8e40e389
...
@@ -117,12 +117,16 @@ TEST_SUBMODULE(builtin_casters, m) {
...
@@ -117,12 +117,16 @@ TEST_SUBMODULE(builtin_casters, m) {
return
std
::
make_pair
(
RValueCaster
{},
std
::
make_tuple
(
RValueCaster
{},
std
::
make_pair
(
RValueCaster
{},
RValueCaster
{})));
});
return
std
::
make_pair
(
RValueCaster
{},
std
::
make_tuple
(
RValueCaster
{},
std
::
make_pair
(
RValueCaster
{},
RValueCaster
{})));
});
m
.
def
(
"lvalue_nested"
,
[]()
->
const
decltype
(
lvnested
)
&
{
return
lvnested
;
});
m
.
def
(
"lvalue_nested"
,
[]()
->
const
decltype
(
lvnested
)
&
{
return
lvnested
;
});
static
std
::
pair
<
int
,
std
::
string
>
int_string_pair
{
2
,
"items"
};
m
.
def
(
"int_string_pair"
,
[]()
{
return
&
int_string_pair
;
});
// test_builtins_cast_return_none
// test_builtins_cast_return_none
m
.
def
(
"return_none_string"
,
[]()
->
std
::
string
*
{
return
nullptr
;
});
m
.
def
(
"return_none_string"
,
[]()
->
std
::
string
*
{
return
nullptr
;
});
m
.
def
(
"return_none_char"
,
[]()
->
const
char
*
{
return
nullptr
;
});
m
.
def
(
"return_none_char"
,
[]()
->
const
char
*
{
return
nullptr
;
});
m
.
def
(
"return_none_bool"
,
[]()
->
bool
*
{
return
nullptr
;
});
m
.
def
(
"return_none_bool"
,
[]()
->
bool
*
{
return
nullptr
;
});
m
.
def
(
"return_none_int"
,
[]()
->
int
*
{
return
nullptr
;
});
m
.
def
(
"return_none_int"
,
[]()
->
int
*
{
return
nullptr
;
});
m
.
def
(
"return_none_float"
,
[]()
->
float
*
{
return
nullptr
;
});
m
.
def
(
"return_none_float"
,
[]()
->
float
*
{
return
nullptr
;
});
m
.
def
(
"return_none_pair"
,
[]()
->
std
::
pair
<
int
,
int
>
*
{
return
nullptr
;
});
// test_none_deferred
// test_none_deferred
m
.
def
(
"defer_none_cstring"
,
[](
char
*
)
{
return
false
;
});
m
.
def
(
"defer_none_cstring"
,
[](
char
*
)
{
return
false
;
});
...
...
tests/test_builtin_casters.py
View file @
8e40e389
...
@@ -250,6 +250,8 @@ def test_tuple(doc):
...
@@ -250,6 +250,8 @@ def test_tuple(doc):
assert
m
.
rvalue_nested
()
==
(
"rvalue"
,
(
"rvalue"
,
(
"rvalue"
,
"rvalue"
)))
assert
m
.
rvalue_nested
()
==
(
"rvalue"
,
(
"rvalue"
,
(
"rvalue"
,
"rvalue"
)))
assert
m
.
lvalue_nested
()
==
(
"lvalue"
,
(
"lvalue"
,
(
"lvalue"
,
"lvalue"
)))
assert
m
.
lvalue_nested
()
==
(
"lvalue"
,
(
"lvalue"
,
(
"lvalue"
,
"lvalue"
)))
assert
m
.
int_string_pair
()
==
(
2
,
"items"
)
def
test_builtins_cast_return_none
():
def
test_builtins_cast_return_none
():
"""Casters produced with PYBIND11_TYPE_CASTER() should convert nullptr to None"""
"""Casters produced with PYBIND11_TYPE_CASTER() should convert nullptr to None"""
...
@@ -258,6 +260,7 @@ def test_builtins_cast_return_none():
...
@@ -258,6 +260,7 @@ def test_builtins_cast_return_none():
assert
m
.
return_none_bool
()
is
None
assert
m
.
return_none_bool
()
is
None
assert
m
.
return_none_int
()
is
None
assert
m
.
return_none_int
()
is
None
assert
m
.
return_none_float
()
is
None
assert
m
.
return_none_float
()
is
None
assert
m
.
return_none_pair
()
is
None
def
test_none_deferred
():
def
test_none_deferred
():
...
...
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