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
8627dc7e
You need to sign in or sign up before continuing.
Commit
8627dc7e
authored
Feb 14, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test_unique_ptr_member' into pr2672_use_smart_holder_as_default
parents
2a58b535
d3999906
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
34 deletions
+17
-34
include/pybind11/cast.h
+15
-19
include/pybind11/pybind11.h
+1
-2
include/pybind11/smart_holder.h
+0
-8
tests/test_class_sh_unique_ptr_member.cpp
+1
-5
No files found.
include/pybind11/cast.h
View file @
8627dc7e
...
@@ -1256,12 +1256,6 @@ struct smart_holder_type_caster_load {
...
@@ -1256,12 +1256,6 @@ struct smart_holder_type_caster_load {
return
*
raw_ptr
;
return
*
raw_ptr
;
}
}
T
&&
loaded_as_rvalue_ref
()
const
{
T
*
raw_ptr
=
loaded_as_raw_ptr_unowned
();
if
(
raw_ptr
==
nullptr
)
throw
reference_cast_error
();
return
std
::
move
(
*
raw_ptr
);
}
std
::
shared_ptr
<
T
>
loaded_as_shared_ptr
()
const
{
std
::
shared_ptr
<
T
>
loaded_as_shared_ptr
()
const
{
if
(
load_impl
.
unowned_void_ptr_from_direct_conversion
!=
nullptr
)
if
(
load_impl
.
unowned_void_ptr_from_direct_conversion
!=
nullptr
)
throw
cast_error
(
"Unowned pointer from direct conversion cannot be converted to a"
throw
cast_error
(
"Unowned pointer from direct conversion cannot be converted to a"
...
@@ -1383,12 +1377,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
...
@@ -1383,12 +1377,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
return
cast
(
const_cast
<
T
const
*>
(
src
),
policy
,
parent
);
// Mutbl2Const
return
cast
(
const_cast
<
T
const
*>
(
src
),
policy
,
parent
);
// Mutbl2Const
}
}
// clang-format off
#if defined(_MSC_VER) && _MSC_VER < 1910
#if defined(_MSC_VER) && _MSC_VER < 1910
// Working around MSVC 2015 bug.
`const` sensitivity
is lost.
// Working around MSVC 2015 bug.
const-correctness
is lost.
// SMART_HOLDER_WIP: IMPROVABLE: make common code work with MSVC 2015.
// SMART_HOLDER_WIP: IMPROVABLE: make common code work with MSVC 2015.
template
<
typename
T_
>
using
cast_op_type
=
detail
::
cast_op_type
<
T_
>
;
template
<
typename
T_
>
using
cast_op_type
=
detail
::
cast_op_type
<
T_
>
;
#else
#else
template
<
typename
T_
>
template
<
typename
T_
>
using
cast_op_type
=
conditional_t
<
using
cast_op_type
=
conditional_t
<
...
@@ -1396,17 +1389,20 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
...
@@ -1396,17 +1389,20 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
T
const
*
,
T
const
*
,
conditional_t
<
std
::
is_same
<
remove_reference_t
<
T_
>
,
T
*>::
value
,
conditional_t
<
std
::
is_same
<
remove_reference_t
<
T_
>
,
T
*>::
value
,
T
*
,
T
*
,
conditional_t
<
std
::
is_same
<
T_
,
T
const
&>::
value
,
conditional_t
<
std
::
is_same
<
T_
,
T
const
&>::
value
,
T
const
&
,
T
&>>>
;
T
const
&
,
T
&>>>
;
#endif
#endif
operator
T
const
&
()
{
return
this
->
loaded_as_lvalue_ref
();
}
// The const operators here prove that the existing type_caster mechanism already supports
operator
T
&
()
{
return
this
->
loaded_as_lvalue_ref
();
}
// const-correctness. However, fully implementing const-correctness inside this type_caster
operator
T
const
*
()
{
return
this
->
loaded_as_raw_ptr_unowned
();
}
// is still a major project.
operator
T
*
()
{
return
this
->
loaded_as_raw_ptr_unowned
();
}
operator
T
const
&
()
const
{
return
const_cast
<
smart_holder_type_caster
*>
(
this
)
->
loaded_as_lvalue_ref
();
// clang-format on
}
operator
T
const
*
()
const
{
return
const_cast
<
smart_holder_type_caster
*>
(
this
)
->
loaded_as_raw_ptr_unowned
();
}
operator
T
&
()
{
return
this
->
loaded_as_lvalue_ref
();
}
operator
T
*
()
{
return
this
->
loaded_as_raw_ptr_unowned
();
}
// Originally type_caster_generic::cast.
// Originally type_caster_generic::cast.
PYBIND11_NOINLINE
static
handle
cast_const_raw_ptr
(
const
void
*
_src
,
PYBIND11_NOINLINE
static
handle
cast_const_raw_ptr
(
const
void
*
_src
,
...
...
include/pybind11/pybind11.h
View file @
8627dc7e
...
@@ -1429,8 +1429,7 @@ public:
...
@@ -1429,8 +1429,7 @@ public:
template
<
typename
Return
,
typename
Class
,
typename
...
Args
>
template
<
typename
Return
,
typename
Class
,
typename
...
Args
>
class_
&
def_buffer
(
Return
(
Class
::*
func
)(
Args
...)
const
)
{
class_
&
def_buffer
(
Return
(
Class
::*
func
)(
Args
...)
const
)
{
// NEEDED: Explanation why the const needs to be removed, or fix elsewhere.
return
def_buffer
([
func
]
(
const
type
&
obj
)
{
return
(
obj
.
*
func
)();
});
return
def_buffer
([
func
]
(
/*const*/
type
&
obj
)
{
return
(
obj
.
*
func
)();
});
}
}
template
<
typename
C
,
typename
D
,
typename
...
Extra
>
template
<
typename
C
,
typename
D
,
typename
...
Extra
>
...
...
include/pybind11/smart_holder.h
View file @
8627dc7e
...
@@ -18,12 +18,4 @@ public:
...
@@ -18,12 +18,4 @@ public:
using
class_
<
type_
,
smart_holder
,
options
...
>::
class_
;
using
class_
<
type_
,
smart_holder
,
options
...
>::
class_
;
};
};
// Similar in idea to `py::classh`, but for `std::unique_ptr<U>` holder, to support
// an easier transition to `py::smart_holder` as default holder.
template
<
typename
type_
,
typename
...
options
>
class
classu
:
public
class_
<
type_
,
std
::
unique_ptr
<
type_
>
,
options
...
>
{
public
:
using
class_
<
type_
,
std
::
unique_ptr
<
type_
>
,
options
...
>::
class_
;
};
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
tests/test_class_sh_unique_ptr_member.cpp
View file @
8627dc7e
...
@@ -41,9 +41,6 @@ private:
...
@@ -41,9 +41,6 @@ private:
}
// namespace pybind11_tests
}
// namespace pybind11_tests
PYBIND11_SMART_HOLDER_TYPE_CASTERS
(
pybind11_tests
::
class_sh_unique_ptr_member
::
pointee
)
PYBIND11_SMART_HOLDER_TYPE_CASTERS
(
pybind11_tests
::
class_sh_unique_ptr_member
::
pointee
)
PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS
(
pybind11_tests
::
class_sh_unique_ptr_member
::
ptr_owner
,
std
::
unique_ptr
<
pybind11_tests
::
class_sh_unique_ptr_member
::
ptr_owner
>
)
namespace
pybind11_tests
{
namespace
pybind11_tests
{
namespace
class_sh_unique_ptr_member
{
namespace
class_sh_unique_ptr_member
{
...
@@ -53,8 +50,7 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) {
...
@@ -53,8 +50,7 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) {
m
.
def
(
"make_unique_pointee"
,
make_unique_pointee
);
m
.
def
(
"make_unique_pointee"
,
make_unique_pointee
);
// Could also be class_, but can conveniently be used for testing classu.
py
::
class_
<
ptr_owner
>
(
m
,
"ptr_owner"
)
py
::
classu
<
ptr_owner
>
(
m
,
"ptr_owner"
)
.
def
(
py
::
init
<
std
::
unique_ptr
<
pointee
>>
(),
py
::
arg
(
"ptr"
))
.
def
(
py
::
init
<
std
::
unique_ptr
<
pointee
>>
(),
py
::
arg
(
"ptr"
))
.
def
(
"is_owner"
,
&
ptr_owner
::
is_owner
)
.
def
(
"is_owner"
,
&
ptr_owner
::
is_owner
)
.
def
(
"give_up_ownership_via_unique_ptr"
,
&
ptr_owner
::
give_up_ownership_via_unique_ptr
)
.
def
(
"give_up_ownership_via_unique_ptr"
,
&
ptr_owner
::
give_up_ownership_via_unique_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