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
86dc9bd0
Commit
86dc9bd0
authored
Jan 27, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Making use of the new find_existing_python_instance() function factored out with PR #2822.
parent
ef3f789b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
22 deletions
+5
-22
include/pybind11/detail/smart_holder_type_casters.h
+5
-22
No files found.
include/pybind11/detail/smart_holder_type_casters.h
View file @
86dc9bd0
...
@@ -24,20 +24,6 @@ using pybindit::memory::smart_holder;
...
@@ -24,20 +24,6 @@ using pybindit::memory::smart_holder;
namespace
detail
{
namespace
detail
{
inline
std
::
pair
<
bool
,
handle
>
find_existing_python_instance
(
void
*
src_void_ptr
,
const
detail
::
type_info
*
tinfo
)
{
// Loop copied from type_caster_generic::cast.
// IMPROVABLE: Factor out of type_caster_generic::cast.
auto
it_instances
=
get_internals
().
registered_instances
.
equal_range
(
src_void_ptr
);
for
(
auto
it_i
=
it_instances
.
first
;
it_i
!=
it_instances
.
second
;
++
it_i
)
{
for
(
auto
instance_type
:
detail
::
all_type_info
(
Py_TYPE
(
it_i
->
second
)))
{
if
(
instance_type
&&
same_type
(
*
instance_type
->
cpptype
,
*
tinfo
->
cpptype
))
return
std
::
make_pair
(
true
,
handle
((
PyObject
*
)
it_i
->
second
).
inc_ref
());
}
}
return
std
::
make_pair
(
false
,
handle
());
}
// The modified_type_caster_generic_load_impl could replace type_caster_generic::load_impl but not
// The modified_type_caster_generic_load_impl could replace type_caster_generic::load_impl but not
// vice versa. The main difference is that the original code only propagates a reference to the
// vice versa. The main difference is that the original code only propagates a reference to the
// held value, while the modified implementation propagates value_and_holder.
// held value, while the modified implementation propagates value_and_holder.
...
@@ -401,9 +387,8 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T> {
...
@@ -401,9 +387,8 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T> {
if
(
src
==
nullptr
)
if
(
src
==
nullptr
)
return
none
().
release
();
return
none
().
release
();
auto
existing_inst
=
find_existing_python_instance
(
src
,
tinfo
);
if
(
handle
existing_inst
=
find_registered_python_instance
(
src
,
tinfo
))
if
(
existing_inst
.
first
)
return
existing_inst
;
return
existing_inst
.
second
;
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
auto
wrapper
=
reinterpret_cast
<
instance
*>
(
inst
.
ptr
());
auto
wrapper
=
reinterpret_cast
<
instance
*>
(
inst
.
ptr
());
...
@@ -494,11 +479,10 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
...
@@ -494,11 +479,10 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
void
*
src_raw_void_ptr
=
static_cast
<
void
*>
(
src_raw_ptr
);
void
*
src_raw_void_ptr
=
static_cast
<
void
*>
(
src_raw_ptr
);
const
detail
::
type_info
*
tinfo
=
st
.
second
;
const
detail
::
type_info
*
tinfo
=
st
.
second
;
auto
existing_inst
=
find_existing_python_instance
(
src_raw_void_ptr
,
tinfo
);
if
(
handle
existing_inst
=
find_registered_python_instance
(
src_raw_void_ptr
,
tinfo
))
if
(
existing_inst
.
first
)
// MISSING: Enforcement of consistency with existing smart_holder.
// MISSING: Enforcement of consistency with existing smart_holder.
// MISSING: keep_alive.
// MISSING: keep_alive.
return
existing_inst
.
second
;
return
existing_inst
;
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
auto
*
inst_raw_ptr
=
reinterpret_cast
<
instance
*>
(
inst
.
ptr
());
auto
*
inst_raw_ptr
=
reinterpret_cast
<
instance
*>
(
inst
.
ptr
());
...
@@ -557,8 +541,7 @@ struct smart_holder_type_caster<std::unique_ptr<T>> : smart_holder_type_caster_l
...
@@ -557,8 +541,7 @@ struct smart_holder_type_caster<std::unique_ptr<T>> : smart_holder_type_caster_l
void
*
src_raw_void_ptr
=
static_cast
<
void
*>
(
src_raw_ptr
);
void
*
src_raw_void_ptr
=
static_cast
<
void
*>
(
src_raw_ptr
);
const
detail
::
type_info
*
tinfo
=
st
.
second
;
const
detail
::
type_info
*
tinfo
=
st
.
second
;
auto
existing_inst
=
find_existing_python_instance
(
src_raw_void_ptr
,
tinfo
);
if
(
find_registered_python_instance
(
src_raw_void_ptr
,
tinfo
))
if
(
existing_inst
.
first
)
throw
cast_error
(
"Invalid unique_ptr: another instance owns this pointer already."
);
throw
cast_error
(
"Invalid unique_ptr: another instance owns this pointer already."
);
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
...
...
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