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
6d395855
Commit
6d395855
authored
Jan 06, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding in vptr_deleter_guard_flag.
parent
62ba083d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
include/pybind11/smart_holder_poc.h
+13
-9
No files found.
include/pybind11/smart_holder_poc.h
View file @
6d395855
...
...
@@ -33,18 +33,21 @@ struct smart_holder {
const
std
::
type_info
*
rtti_uqp_del
;
std
::
shared_ptr
<
void
>
vptr
;
bool
vptr_deleter_guard_flag
;
bool
vptr_is_using_builtin_delete
;
void
clear
()
{
vptr
.
reset
();
vptr_deleter_guard_flag
=
false
;
rtti_held
=
nullptr
;
rtti_uqp_del
=
nullptr
;
vptr
.
reset
();
vptr_deleter_guard_flag
=
false
;
vptr_is_using_builtin_delete
=
false
;
}
smart_holder
()
:
rtti_held
{
nullptr
},
rtti_uqp_del
{
nullptr
},
vptr_deleter_guard_flag
{
false
}
{}
vptr_deleter_guard_flag
{
false
},
vptr_is_using_builtin_delete
{
false
}
{}
bool
has_pointee
()
const
{
return
vptr
.
get
()
!=
nullptr
;
}
...
...
@@ -52,7 +55,7 @@ struct smart_holder {
void
ensure_compatible_rtti_held
(
const
char
*
context
)
const
{
const
std
::
type_info
*
rtti_requested
=
&
typeid
(
T
);
if
(
!
(
*
rtti_requested
==
*
rtti_held
))
{
throw
std
::
runtime_error
(
std
::
string
(
"Incompatible
RTTI
("
)
+
context
+
throw
std
::
runtime_error
(
std
::
string
(
"Incompatible
type
("
)
+
context
+
")."
);
}
}
...
...
@@ -73,9 +76,9 @@ struct smart_holder {
}
}
void
ensure_vptr_
deleter_guard_flag_tru
e
(
const
char
*
context
)
const
{
if
(
rtti_uqp_del
!=
nullptr
)
{
throw
std
::
runtime_error
(
std
::
string
(
"Cannot disown
this shared_pt
r ("
)
+
void
ensure_vptr_
is_using_builtin_delet
e
(
const
char
*
context
)
const
{
if
(
!
vptr_is_using_builtin_delete
)
{
throw
std
::
runtime_error
(
std
::
string
(
"Cannot disown
custom delete
r ("
)
+
context
+
")."
);
}
}
...
...
@@ -100,6 +103,7 @@ struct smart_holder {
clear
();
rtti_held
=
&
typeid
(
T
);
vptr_deleter_guard_flag
=
true
;
vptr_is_using_builtin_delete
=
true
;
vptr
.
reset
(
raw_ptr
,
guarded_builtin_delete
<
T
>
(
&
vptr_deleter_guard_flag
));
}
...
...
@@ -107,7 +111,6 @@ struct smart_holder {
void
from_raw_ptr_unowned
(
T
*
raw_ptr
)
{
clear
();
rtti_held
=
&
typeid
(
T
);
vptr_deleter_guard_flag
=
false
;
vptr
.
reset
(
raw_ptr
,
guarded_builtin_delete
<
T
>
(
&
vptr_deleter_guard_flag
));
}
...
...
@@ -115,7 +118,7 @@ struct smart_holder {
T
*
as_raw_ptr_release_ownership
(
const
char
*
context
=
"as_raw_ptr_release_ownership"
)
{
ensure_compatible_rtti_held
<
T
>
(
context
);
ensure_vptr_
deleter_guard_flag_tru
e
(
context
);
ensure_vptr_
is_using_builtin_delet
e
(
context
);
ensure_use_count_1
(
context
);
T
*
raw_ptr
=
static_cast
<
T
*>
(
vptr
.
get
());
vptr_deleter_guard_flag
=
false
;
...
...
@@ -135,6 +138,7 @@ struct smart_holder {
clear
();
rtti_held
=
&
typeid
(
T
);
vptr_deleter_guard_flag
=
true
;
vptr_is_using_builtin_delete
=
true
;
vptr
.
reset
(
unq_ptr
.
get
(),
guarded_builtin_delete
<
T
>
(
&
vptr_deleter_guard_flag
));
unq_ptr
.
release
();
...
...
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