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
3a303ee2
Commit
3a303ee2
authored
Feb 23, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renaming is_smart_holder_type_caster -> type_uses_smart_holder_type_caster for clarity.
parent
658cf3ba
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
29 deletions
+34
-29
include/pybind11/cast.h
+3
-3
include/pybind11/detail/init.h
+15
-11
include/pybind11/detail/smart_holder_sfinae_hooks_only.h
+2
-2
include/pybind11/detail/smart_holder_type_casters.h
+1
-1
include/pybind11/pybind11.h
+13
-12
No files found.
include/pybind11/cast.h
View file @
3a303ee2
...
...
@@ -66,7 +66,7 @@ template <typename type>
using
make_caster
=
type_caster
<
intrinsic_t
<
type
>>
;
template
<
typename
T
>
struct
i
s_smart_holder_type_caster
{
struct
type_use
s_smart_holder_type_caster
{
static
constexpr
bool
value
=
std
::
is_base_of
<
is_smart_holder_type_caster_base_tag
,
make_caster
<
T
>>::
value
;
};
...
...
@@ -846,7 +846,7 @@ template <typename T> using move_never = none_of<move_always<T>, move_if_unrefer
template
<
typename
type
>
using
cast_is_temporary_value_reference
=
bool_constant
<
(
std
::
is_reference
<
type
>::
value
||
std
::
is_pointer
<
type
>::
value
)
&&
!
std
::
is_base_of
<
type_caster_generic
,
make_caster
<
type
>>::
value
&&
!
i
s_smart_holder_type_caster
<
intrinsic_t
<
type
>>::
value
&&
!
type_use
s_smart_holder_type_caster
<
intrinsic_t
<
type
>>::
value
&&
!
std
::
is_same
<
intrinsic_t
<
type
>
,
void
>::
value
>
;
...
...
@@ -1391,7 +1391,7 @@ template<typename T>
handle
type
::
handle_of
()
{
static_assert
(
detail
::
any_of
<
std
::
is_base_of
<
detail
::
type_caster_generic
,
detail
::
make_caster
<
T
>>
,
detail
::
i
s_smart_holder_type_caster
<
T
>>::
value
,
detail
::
type_use
s_smart_holder_type_caster
<
T
>>::
value
,
"py::type::of<T> only supports the case where T is a registered C++ types."
);
return
detail
::
get_type_handle
(
typeid
(
T
),
true
);
...
...
include/pybind11/detail/init.h
View file @
3a303ee2
...
...
@@ -133,7 +133,7 @@ void construct(value_and_holder &v_h, Alias<Class> *alias_ptr, bool) {
// holder. This also handles types like std::shared_ptr<T> and std::unique_ptr<T> where T is a
// derived type (through those holder's implicit conversion from derived class holder constructors).
template
<
typename
Class
,
detail
::
enable_if_t
<!
detail
::
i
s_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
detail
::
enable_if_t
<!
detail
::
type_use
s_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
void
construct
(
value_and_holder
&
v_h
,
Holder
<
Class
>
holder
,
bool
need_alias
)
{
auto
*
ptr
=
holder_helper
<
Holder
<
Class
>>::
get
(
holder
);
no_nullptr
(
ptr
);
...
...
@@ -171,9 +171,10 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
}
// clang-format on
template
<
typename
Class
,
typename
D
=
std
::
default_delete
<
Cpp
<
Class
>>
,
detail
::
enable_if_t
<
detail
::
is_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
template
<
typename
Class
,
typename
D
=
std
::
default_delete
<
Cpp
<
Class
>>
,
detail
::
enable_if_t
<
detail
::
type_uses_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
void
construct
(
value_and_holder
&
v_h
,
std
::
unique_ptr
<
Cpp
<
Class
>
,
D
>
&&
unq_ptr
,
bool
need_alias
)
{
auto
*
ptr
=
unq_ptr
.
get
();
no_nullptr
(
ptr
);
...
...
@@ -186,9 +187,10 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
template
<
typename
Class
,
typename
D
=
std
::
default_delete
<
Alias
<
Class
>>
,
detail
::
enable_if_t
<
detail
::
is_smart_holder_type_caster
<
Alias
<
Class
>>::
value
,
int
>
=
0
>
template
<
typename
Class
,
typename
D
=
std
::
default_delete
<
Alias
<
Class
>>
,
detail
::
enable_if_t
<
detail
::
type_uses_smart_holder_type_caster
<
Alias
<
Class
>>::
value
,
int
>
=
0
>
void
construct
(
value_and_holder
&
v_h
,
std
::
unique_ptr
<
Alias
<
Class
>
,
D
>
&&
unq_ptr
,
bool
/*need_alias*/
)
{
...
...
@@ -200,8 +202,9 @@ void construct(value_and_holder &v_h,
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
template
<
typename
Class
,
detail
::
enable_if_t
<
detail
::
is_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
template
<
typename
Class
,
detail
::
enable_if_t
<
detail
::
type_uses_smart_holder_type_caster
<
Cpp
<
Class
>>::
value
,
int
>
=
0
>
void
construct
(
value_and_holder
&
v_h
,
std
::
shared_ptr
<
Cpp
<
Class
>>
&&
shd_ptr
,
bool
need_alias
)
{
auto
*
ptr
=
shd_ptr
.
get
();
no_nullptr
(
ptr
);
...
...
@@ -213,8 +216,9 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
template
<
typename
Class
,
detail
::
enable_if_t
<
detail
::
is_smart_holder_type_caster
<
Alias
<
Class
>>::
value
,
int
>
=
0
>
template
<
typename
Class
,
detail
::
enable_if_t
<
detail
::
type_uses_smart_holder_type_caster
<
Alias
<
Class
>>::
value
,
int
>
=
0
>
void
construct
(
value_and_holder
&
v_h
,
std
::
shared_ptr
<
Alias
<
Class
>>
&&
shd_ptr
,
bool
/*need_alias*/
)
{
...
...
include/pybind11/detail/smart_holder_sfinae_hooks_only.h
View file @
3a303ee2
...
...
@@ -19,11 +19,11 @@ PYBIND11_NAMESPACE_BEGIN(detail)
template
<
typename
T
>
struct
is_smart_holder_type
:
std
::
false_type
{};
// Tag to be used as base class, inspected by
i
s_smart_holder_type_caster<T> test.
// Tag to be used as base class, inspected by
type_use
s_smart_holder_type_caster<T> test.
struct
is_smart_holder_type_caster_base_tag
{};
template
<
typename
T
>
struct
i
s_smart_holder_type_caster
;
struct
type_use
s_smart_holder_type_caster
;
PYBIND11_NAMESPACE_END
(
detail
)
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
include/pybind11/detail/smart_holder_type_casters.h
View file @
3a303ee2
...
...
@@ -287,7 +287,7 @@ struct smart_holder_type_caster_load {
using
holder_type
=
pybindit
::
memory
::
smart_holder
;
bool
load
(
handle
src
,
bool
convert
)
{
static_assert
(
i
s_smart_holder_type_caster
<
T
>::
value
,
"Internal consistency error."
);
static_assert
(
type_use
s_smart_holder_type_caster
<
T
>::
value
,
"Internal consistency error."
);
load_impl
=
modified_type_caster_generic_load_impl
(
typeid
(
T
));
if
(
!
load_impl
.
load
(
src
,
convert
))
return
false
;
...
...
include/pybind11/pybind11.h
View file @
3a303ee2
...
...
@@ -1275,10 +1275,11 @@ class class_ : public detail::generic_type {
template
<
typename
T
>
using
is_base
=
detail
::
is_strict_base_of
<
T
,
type_
>
;
template
<
typename
T
>
// clang-format on
using
is_holder
=
detail
::
any_of
<
detail
::
is_holder_type
<
type_
,
T
>
,
detail
::
all_of
<
detail
::
negation
<
is_base
<
T
>>
,
detail
::
negation
<
is_subtype
<
T
>>
,
detail
::
is_smart_holder_type_caster
<
type_
>>>
;
using
is_holder
=
detail
::
any_of
<
detail
::
is_holder_type
<
type_
,
T
>
,
detail
::
all_of
<
detail
::
negation
<
is_base
<
T
>>
,
detail
::
negation
<
is_subtype
<
T
>>
,
detail
::
type_uses_smart_holder_type_caster
<
type_
>>>
;
// clang-format off
// struct instead of using here to help MSVC:
template
<
typename
T
>
struct
is_valid_class_option
:
...
...
@@ -1314,7 +1315,7 @@ public:
static
constexpr
bool
holder_is_smart_holder
=
detail
::
is_smart_holder_type
<
holder_type
>::
value
;
static
constexpr
bool
type_caster_type_is_smart_holder_type_caster
=
detail
::
i
s_smart_holder_type_caster
<
type
>::
value
;
=
detail
::
type_use
s_smart_holder_type_caster
<
type
>::
value
;
static
constexpr
bool
type_caster_type_is_type_caster_base_subtype
=
std
::
is_base_of
<
detail
::
type_caster_base
<
type
>
,
detail
::
type_caster
<
type
>>::
value
;
// Necessary conditions, but not strict.
...
...
@@ -1573,14 +1574,14 @@ public:
private
:
// clang-format on
template
<
typename
T
=
type
,
detail
::
enable_if_t
<!
detail
::
i
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
template
<
typename
T
=
type
,
detail
::
enable_if_t
<!
detail
::
type_use
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
void
generic_type_initialize
(
const
detail
::
type_record
&
record
)
{
generic_type
::
initialize
(
record
,
&
detail
::
type_caster_generic
::
local_load
);
}
template
<
typename
T
=
type
,
detail
::
enable_if_t
<
detail
::
i
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
template
<
typename
T
=
type
,
detail
::
enable_if_t
<
detail
::
type_use
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
void
generic_type_initialize
(
const
detail
::
type_record
&
record
)
{
generic_type
::
initialize
(
record
,
detail
::
type_caster
<
T
>::
get_local_load_function_ptr
());
}
...
...
@@ -1632,7 +1633,7 @@ private:
/// `.owned`, a new holder will be constructed to manage the value pointer.
template
<
typename
T
=
type
,
detail
::
enable_if_t
<!
detail
::
i
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
detail
::
enable_if_t
<!
detail
::
type_use
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
static
void
init_instance
(
detail
::
instance
*
inst
,
const
void
*
holder_ptr
)
{
auto
v_h
=
inst
->
get_value_and_holder
(
detail
::
get_type_info
(
typeid
(
type
)));
if
(
!
v_h
.
instance_registered
())
{
...
...
@@ -1643,8 +1644,8 @@ private:
}
// clang-format on
template
<
typename
T
=
type
,
detail
::
enable_if_t
<
detail
::
i
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
template
<
typename
T
=
type
,
detail
::
enable_if_t
<
detail
::
type_use
s_smart_holder_type_caster
<
T
>::
value
,
int
>
=
0
>
static
void
init_instance
(
detail
::
instance
*
inst
,
const
void
*
holder_ptr
)
{
detail
::
type_caster
<
T
>::
template
init_instance_for_type
<
type
>
(
inst
,
holder_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