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
b0b55f26
Commit
b0b55f26
authored
Jan 06, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shuffling existing TEST_CASEs into systematic matrix.
parent
7d43a752
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
41 deletions
+101
-41
include/pybind11/smart_holder_poc.h
+14
-14
tests/core/smart_holder_poc_test.cpp
+87
-27
No files found.
include/pybind11/smart_holder_poc.h
View file @
b0b55f26
...
@@ -91,6 +91,20 @@ struct smart_holder {
...
@@ -91,6 +91,20 @@ struct smart_holder {
}
}
template
<
typename
T
>
template
<
typename
T
>
void
from_raw_ptr_unowned
(
T
*
raw_ptr
)
{
clear
();
rtti_held
=
&
typeid
(
T
);
vptr
.
reset
(
raw_ptr
,
guarded_builtin_delete
<
T
>
(
&
vptr_deleter_guard_flag
));
}
template
<
typename
T
>
T
*
as_raw_ptr_unowned
()
const
{
static
const
char
*
context
=
"as_raw_ptr_unowned"
;
ensure_compatible_rtti_held
<
T
>
(
context
);
return
static_cast
<
T
*>
(
vptr
.
get
());
}
template
<
typename
T
>
const
T
&
const_value_ref
()
const
{
const
T
&
const_value_ref
()
const
{
static
const
char
*
context
=
"const_value_ref"
;
static
const
char
*
context
=
"const_value_ref"
;
ensure_compatible_rtti_held
<
T
>
(
context
);
ensure_compatible_rtti_held
<
T
>
(
context
);
...
@@ -108,13 +122,6 @@ struct smart_holder {
...
@@ -108,13 +122,6 @@ struct smart_holder {
}
}
template
<
typename
T
>
template
<
typename
T
>
void
from_raw_ptr_unowned
(
T
*
raw_ptr
)
{
clear
();
rtti_held
=
&
typeid
(
T
);
vptr
.
reset
(
raw_ptr
,
guarded_builtin_delete
<
T
>
(
&
vptr_deleter_guard_flag
));
}
template
<
typename
T
>
T
*
as_raw_ptr_release_ownership
(
T
*
as_raw_ptr_release_ownership
(
const
char
*
context
=
"as_raw_ptr_release_ownership"
)
{
const
char
*
context
=
"as_raw_ptr_release_ownership"
)
{
ensure_compatible_rtti_held
<
T
>
(
context
);
ensure_compatible_rtti_held
<
T
>
(
context
);
...
@@ -127,13 +134,6 @@ struct smart_holder {
...
@@ -127,13 +134,6 @@ struct smart_holder {
}
}
template
<
typename
T
>
template
<
typename
T
>
T
*
as_raw_ptr_unowned
()
const
{
static
const
char
*
context
=
"as_raw_ptr_unowned"
;
ensure_compatible_rtti_held
<
T
>
(
context
);
return
static_cast
<
T
*>
(
vptr
.
get
());
}
template
<
typename
T
>
void
from_unique_ptr
(
std
::
unique_ptr
<
T
>&&
unq_ptr
)
{
void
from_unique_ptr
(
std
::
unique_ptr
<
T
>&&
unq_ptr
)
{
clear
();
clear
();
rtti_held
=
&
typeid
(
T
);
rtti_held
=
&
typeid
(
T
);
...
...
tests/core/smart_holder_poc_test.cpp
View file @
b0b55f26
...
@@ -14,22 +14,36 @@ struct functor_builtin_delete {
...
@@ -14,22 +14,36 @@ struct functor_builtin_delete {
}
// namespace helpers
}
// namespace helpers
TEST_CASE
(
"from_raw_ptr_take_ownership+const_value_ref"
,
"[feasible]"
)
{
TEST_CASE
(
"from_raw_ptr_unowned+as_raw_ptr_unowned"
,
"[S]"
)
{
smart_holder
hld
;
REQUIRE
(
!
hld
.
has_pointee
());
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
REQUIRE
(
hld
.
has_pointee
());
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
}
TEST_CASE
(
"from_raw_ptr_unowned+const_value_ref"
,
"[
feasible
]"
)
{
TEST_CASE
(
"from_raw_ptr_unowned+const_value_ref"
,
"[
S
]"
)
{
static
int
value
=
19
;
static
int
value
=
19
;
smart_holder
hld
;
smart_holder
hld
;
hld
.
from_raw_ptr_unowned
(
&
value
);
hld
.
from_raw_ptr_unowned
(
&
value
);
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_raw_ptr_release_ownership"
,
"[feasible]"
)
{
TEST_CASE
(
"from_raw_ptr_unowned+as_raw_ptr_release_ownership"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_unowned+as_unique_ptr"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_unowned+as_unique_ptr_with_deleter"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_unowned+as_shared_ptr"
,
"[S]"
)
{
}
TEST_CASE
(
"from_raw_ptr_take_ownership+const_value_ref"
,
"[S]"
)
{
smart_holder
hld
;
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
REQUIRE
(
hld
.
has_pointee
());
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1"
,
"[S]"
)
{
smart_holder
hld
;
smart_holder
hld
;
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
auto
new_owner
=
auto
new_owner
=
...
@@ -37,15 +51,32 @@ TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership", "[feasible
...
@@ -37,15 +51,32 @@ TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership", "[feasible
REQUIRE
(
!
hld
.
has_pointee
());
REQUIRE
(
!
hld
.
has_pointee
());
}
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_raw_ptr_unowned"
,
"[feasible]"
)
{
TEST_CASE
(
"from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_unique_ptr1"
,
"[S]"
)
{
smart_holder
hld
;
smart_holder
hld
;
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
int
*
raw_ptr
=
hld
.
as_raw_ptr_unowned
<
int
>
();
auto
new_owner
=
hld
.
as_unique_ptr
<
int
>
();
REQUIRE
(
!
hld
.
has_pointee
());
REQUIRE
(
*
new_owner
==
19
);
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_unique_ptr2"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_unique_ptr_with_deleter"
,
"[E]"
)
{
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_shared_ptr"
,
"[S]"
)
{
smart_holder
hld
;
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
auto
new_owner
=
hld
.
as_shared_ptr
<
int
>
();
REQUIRE
(
hld
.
has_pointee
());
REQUIRE
(
hld
.
has_pointee
());
REQUIRE
(
*
raw_pt
r
==
19
);
REQUIRE
(
*
new_owne
r
==
19
);
}
}
TEST_CASE
(
"from_unique_ptr+const_value_ref
+const_value_ref"
,
"[feasible
]"
)
{
TEST_CASE
(
"from_unique_ptr+const_value_ref
"
,
"[S
]"
)
{
std
::
unique_ptr
<
int
>
orig_owner
(
new
int
(
19
));
std
::
unique_ptr
<
int
>
orig_owner
(
new
int
(
19
));
smart_holder
hld
;
smart_holder
hld
;
hld
.
from_unique_ptr
(
std
::
move
(
orig_owner
));
hld
.
from_unique_ptr
(
std
::
move
(
orig_owner
));
...
@@ -53,15 +84,25 @@ TEST_CASE("from_unique_ptr+const_value_ref+const_value_ref", "[feasible]") {
...
@@ -53,15 +84,25 @@ TEST_CASE("from_unique_ptr+const_value_ref+const_value_ref", "[feasible]") {
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_unique_ptr"
,
"[feasible]"
)
{
TEST_CASE
(
"from_unique_ptr+as_raw_ptr_release_ownership1"
,
"[S]"
)
{
smart_holder
hld
;
}
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
auto
new_owner
=
hld
.
as_unique_ptr
<
int
>
();
TEST_CASE
(
"from_unique_ptr+as_raw_ptr_release_ownership2"
,
"[E]"
)
{
REQUIRE
(
!
hld
.
has_pointee
());
}
REQUIRE
(
*
new_owner
==
19
);
TEST_CASE
(
"from_unique_ptr+as_unique_ptr1"
,
"[S]"
)
{
}
TEST_CASE
(
"from_unique_ptr+as_unique_ptr2"
,
"[E]"
)
{
}
TEST_CASE
(
"from_unique_ptr+as_unique_ptr_with_deleter"
,
"[E]"
)
{
}
TEST_CASE
(
"from_unique_ptr+as_shared_ptr"
,
"[S]"
)
{
}
}
TEST_CASE
(
"from_unique_ptr_with_deleter+const_value_ref"
,
"[
feasible
]"
)
{
TEST_CASE
(
"from_unique_ptr_with_deleter+const_value_ref"
,
"[
S
]"
)
{
std
::
unique_ptr
<
int
,
helpers
::
functor_builtin_delete
<
int
>>
orig_owner
(
std
::
unique_ptr
<
int
,
helpers
::
functor_builtin_delete
<
int
>>
orig_owner
(
new
int
(
19
));
new
int
(
19
));
smart_holder
hld
;
smart_holder
hld
;
...
@@ -70,7 +111,13 @@ TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[feasible]") {
...
@@ -70,7 +111,13 @@ TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[feasible]") {
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
}
TEST_CASE
(
"from_unique_ptr_with_deleter+as_unique_ptr_with_deleter"
,
"[feasible]"
)
{
TEST_CASE
(
"from_unique_ptr_with_deleter+as_raw_ptr_release_ownership"
,
"[E]"
)
{
}
TEST_CASE
(
"from_unique_ptr_with_deleter+as_unique_ptr"
,
"[E]"
)
{
}
TEST_CASE
(
"from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1"
,
"[S]"
)
{
std
::
unique_ptr
<
int
,
helpers
::
functor_builtin_delete
<
int
>>
orig_owner
(
std
::
unique_ptr
<
int
,
helpers
::
functor_builtin_delete
<
int
>>
orig_owner
(
new
int
(
19
));
new
int
(
19
));
smart_holder
hld
;
smart_holder
hld
;
...
@@ -82,7 +129,13 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter", "[feasible]
...
@@ -82,7 +129,13 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter", "[feasible]
REQUIRE
(
*
new_owner
==
19
);
REQUIRE
(
*
new_owner
==
19
);
}
}
TEST_CASE
(
"from_shared_ptr+const_value_ref"
,
"[feasible]"
)
{
TEST_CASE
(
"from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2"
,
"[E]"
)
{
}
TEST_CASE
(
"from_unique_ptr_with_deleter+as_shared_ptr"
,
"[S]"
)
{
}
TEST_CASE
(
"from_shared_ptr+const_value_ref"
,
"[S]"
)
{
std
::
shared_ptr
<
int
>
orig_owner
(
new
int
(
19
));
std
::
shared_ptr
<
int
>
orig_owner
(
new
int
(
19
));
smart_holder
hld
;
smart_holder
hld
;
hld
.
from_shared_ptr
(
orig_owner
);
hld
.
from_shared_ptr
(
orig_owner
);
...
@@ -90,10 +143,17 @@ TEST_CASE("from_shared_ptr+const_value_ref", "[feasible]") {
...
@@ -90,10 +143,17 @@ TEST_CASE("from_shared_ptr+const_value_ref", "[feasible]") {
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
REQUIRE
(
hld
.
const_value_ref
<
int
>
()
==
19
);
}
}
TEST_CASE
(
"from_raw_ptr_take_ownership+as_shared_ptr"
,
"[feasible]"
)
{
TEST_CASE
(
"from_shared_ptr+as_raw_ptr_release_ownership1"
,
"[S]"
)
{
smart_holder
hld
;
}
hld
.
from_raw_ptr_take_ownership
(
new
int
(
19
));
auto
new_owner
=
hld
.
as_shared_ptr
<
int
>
();
TEST_CASE
(
"from_shared_ptr+as_raw_ptr_release_ownership2"
,
"[E]"
)
{
REQUIRE
(
hld
.
has_pointee
());
}
REQUIRE
(
*
new_owner
==
19
);
TEST_CASE
(
"from_shared_ptr+as_unique_ptr"
,
"[E]"
)
{
}
TEST_CASE
(
"from_shared_ptr+as_unique_ptr_with_deleter"
,
"[E]"
)
{
}
TEST_CASE
(
"from_shared_ptr+as_shared_ptr"
,
"[S]"
)
{
}
}
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