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
acb2c331
Commit
acb2c331
authored
Jan 20, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimal changes needed to pass test_classh_inheritance.
parent
cc50eaa9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
15 deletions
+29
-15
include/pybind11/detail/classh_type_casters.h
+29
-15
No files found.
include/pybind11/detail/classh_type_casters.h
View file @
acb2c331
...
...
@@ -35,7 +35,7 @@ public:
PYBIND11_NOINLINE
modified_type_caster_generic_load_impl
(
const
std
::
type_info
&
type_info
)
:
typeinfo
(
get_type_info
(
type_info
)),
cpptype
(
&
type_info
)
{
}
modified_type_caster_generic_load_impl
(
const
type_info
*
typeinfo
)
explicit
modified_type_caster_generic_load_impl
(
const
type_info
*
typeinfo
=
nullptr
)
:
typeinfo
(
typeinfo
),
cpptype
(
typeinfo
?
typeinfo
->
cpptype
:
nullptr
)
{
}
bool
load
(
handle
src
,
bool
convert
)
{
...
...
@@ -133,7 +133,7 @@ public:
}
// Case 2: We have a derived class
else
if
(
PyType_IsSubtype
(
srctype
,
typeinfo
->
type
))
{
auto
&
bases
=
all_type_info
(
srctype
);
auto
&
bases
=
all_type_info
(
srctype
);
// subtype bases
bool
no_cpp_mi
=
typeinfo
->
simple_type
;
// Case 2a: the python type is a Python-inherited derived class that inherits from just
...
...
@@ -144,6 +144,8 @@ public:
// pointer lookup overhead)
if
(
bases
.
size
()
==
1
&&
(
no_cpp_mi
||
bases
.
front
()
->
type
==
typeinfo
->
type
))
{
this_
.
load_value_and_holder
(
reinterpret_cast
<
instance
*>
(
src
.
ptr
())
->
get_value_and_holder
());
subtype_typeinfo
=
bases
.
front
();
reinterpret_cast_ok
=
true
;
return
true
;
}
// Case 2b: the python type inherits from multiple C++ bases. Check the bases to see if
...
...
@@ -153,6 +155,8 @@ public:
for
(
auto
base
:
bases
)
{
if
(
no_cpp_mi
?
PyType_IsSubtype
(
base
->
type
,
typeinfo
->
type
)
:
base
->
type
==
typeinfo
->
type
)
{
this_
.
load_value_and_holder
(
reinterpret_cast
<
instance
*>
(
src
.
ptr
())
->
get_value_and_holder
(
base
));
subtype_typeinfo
=
base
;
reinterpret_cast_ok
=
true
;
return
true
;
}
}
...
...
@@ -161,8 +165,9 @@ public:
// Case 2c: C++ multiple inheritance is involved and we couldn't find an exact type match
// in the registered bases, above, so try implicit casting (needed for proper C++ casting
// when MI is involved).
if
(
this_
.
try_implicit_casts
(
src
,
convert
))
if
(
this_
.
try_implicit_casts
(
src
,
convert
))
{
return
true
;
}
}
// Perform an implicit conversion
...
...
@@ -192,7 +197,9 @@ public:
const
type_info
*
typeinfo
=
nullptr
;
const
std
::
type_info
*
cpptype
=
nullptr
;
const
type_info
*
subtype_typeinfo
=
nullptr
;
value_and_holder
loaded_v_h
;
bool
reinterpret_cast_ok
=
false
;
};
// clang-format on
...
...
@@ -203,25 +210,32 @@ struct smart_holder_type_caster_load {
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
isinstance
<
T
>
(
src
))
return
false
;
modified_type_caster_generic_load_impl
tcgli
(
typeid
(
T
));
tcgli
.
load
(
src
,
convert
);
loaded_v_h
=
tcgli
.
loaded_v_h
;
loaded_smhldr_ptr
=
&
loaded_v_h
.
holder
<
holder_type
>
();
load_impl
=
modified_type_caster_generic_load_impl
(
typeid
(
T
));
if
(
!
load_impl
.
load
(
src
,
convert
))
return
false
;
loaded_smhldr_ptr
=
&
load
_impl
.
load
ed_v_h
.
holder
<
holder_type
>
();
return
true
;
}
T
*
as_raw_ptr_unowned
()
{
if
(
load_impl
.
subtype_typeinfo
!=
nullptr
&&
load_impl
.
reinterpret_cast_ok
)
{
return
reinterpret_cast
<
T
*>
(
loaded_smhldr_ptr
->
vptr
.
get
());
}
return
loaded_smhldr_ptr
->
as_raw_ptr_unowned
<
T
>
();
}
std
::
unique_ptr
<
T
>
loaded_as_unique_ptr
()
{
void
*
value_void_ptr
=
loaded_v_h
.
value_ptr
();
void
*
value_void_ptr
=
load
_impl
.
load
ed_v_h
.
value_ptr
();
auto
unq_ptr
=
loaded_smhldr_ptr
->
as_unique_ptr
<
T
>
();
loaded_v_h
.
holder
<
holder_type
>
().
~
holder_type
();
loaded_v_h
.
set_holder_constructed
(
false
);
loaded_v_h
.
value_ptr
()
=
nullptr
;
deregister_instance
(
load
ed_v_h
.
inst
,
value_void_ptr
,
loaded_v_h
.
type
);
load
_impl
.
load
ed_v_h
.
holder
<
holder_type
>
().
~
holder_type
();
load
_impl
.
load
ed_v_h
.
set_holder_constructed
(
false
);
load
_impl
.
load
ed_v_h
.
value_ptr
()
=
nullptr
;
deregister_instance
(
load
_impl
.
loaded_v_h
.
inst
,
value_void_ptr
,
load_impl
.
loaded_v_h
.
type
);
return
unq_ptr
;
}
protected
:
value_and_holder
loaded_v_h
;
modified_type_caster_generic_load_impl
load_impl
;
holder_type
*
loaded_smhldr_ptr
=
nullptr
;
};
...
...
@@ -316,8 +330,8 @@ struct classh_type_caster : smart_holder_type_caster_load<T> {
operator
T
&&
()
&&
{
return
this
->
loaded_smhldr_ptr
->
template
rvalue_ref
<
T
>
();
}
operator
T
const
&
()
{
return
this
->
loaded_smhldr_ptr
->
template
lvalue_ref
<
T
>
();
}
operator
T
&
()
{
return
this
->
loaded_smhldr_ptr
->
template
lvalue_ref
<
T
>
();
}
operator
T
const
*
()
{
return
this
->
loaded_smhldr_ptr
->
template
as_raw_ptr_unowned
<
T
>
();
}
operator
T
*
()
{
return
this
->
loaded_smhldr_ptr
->
template
as_raw_ptr_unowned
<
T
>
();
}
operator
T
const
*
()
{
return
this
->
as_raw_ptr_unowned
();
}
operator
T
*
()
{
return
this
->
as_raw_ptr_unowned
();
}
// clang-format on
...
...
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