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
dc10e8a9
Commit
dc10e8a9
authored
Feb 15, 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
5cf93a08
a569281f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
29 deletions
+37
-29
include/pybind11/cast.h
+9
-9
tests/test_class.cpp
+6
-1
tests/test_multiple_inheritance.cpp
+22
-19
tests/test_smart_ptr.cpp
+0
-0
No files found.
include/pybind11/cast.h
View file @
dc10e8a9
...
...
@@ -1237,7 +1237,7 @@ struct smart_holder_type_caster_load {
}
T
*
loaded_as_raw_ptr_unowned
()
const
{
void
*
void_ptr
=
load_impl
.
unowned_void_ptr_from_direct_conversion
;
// UNTESTED.
void
*
void_ptr
=
load_impl
.
unowned_void_ptr_from_direct_conversion
;
if
(
void_ptr
==
nullptr
)
{
if
(
have_holder
())
{
throw_if_uninitialized_or_disowned_holder
();
...
...
@@ -1259,7 +1259,7 @@ struct smart_holder_type_caster_load {
std
::
shared_ptr
<
T
>
loaded_as_shared_ptr
()
const
{
if
(
load_impl
.
unowned_void_ptr_from_direct_conversion
!=
nullptr
)
throw
cast_error
(
"Unowned pointer from direct conversion cannot be converted to a"
" std::shared_ptr."
);
// UNTESTED.
" std::shared_ptr."
);
if
(
!
have_holder
())
return
nullptr
;
throw_if_uninitialized_or_disowned_holder
();
std
::
shared_ptr
<
void
>
void_ptr
=
holder
().
template
as_shared_ptr
<
void
>
();
...
...
@@ -1270,13 +1270,13 @@ struct smart_holder_type_caster_load {
std
::
unique_ptr
<
T
,
D
>
loaded_as_unique_ptr
(
const
char
*
context
=
"loaded_as_unique_ptr"
)
{
if
(
load_impl
.
unowned_void_ptr_from_direct_conversion
!=
nullptr
)
throw
cast_error
(
"Unowned pointer from direct conversion cannot be converted to a"
" std::unique_ptr."
);
// UNTESTED.
" std::unique_ptr."
);
if
(
!
have_holder
())
return
nullptr
;
throw_if_uninitialized_or_disowned_holder
();
holder
().
template
ensure_compatible_rtti_uqp_del
<
T
,
D
>
(
context
);
holder
().
ensure_use_count_1
(
context
);
auto
raw_void_ptr
=
holder
().
template
as_raw_ptr_unowned
<
void
>
();
// MISSING: Safety checks for type conversions
//
SMART_HOLDER_WIP:
MISSING: Safety checks for type conversions
// (T must be polymorphic or meet certain other conditions).
T
*
raw_type_ptr
=
convert_type
(
raw_void_ptr
);
...
...
@@ -1325,7 +1325,7 @@ private:
}
};
// IMPROVABLE: Formally factor out of type_caster_base.
//
SMART_HOLDER_WIP:
IMPROVABLE: Formally factor out of type_caster_base.
struct
make_constructor
:
private
type_caster_base
<
int
>
{
// Any type, nothing special about int.
using
type_caster_base
<
int
>::
Constructor
;
using
type_caster_base
<
int
>::
make_copy_constructor
;
...
...
@@ -1501,7 +1501,7 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
static
handle
cast
(
const
std
::
shared_ptr
<
T
>
&
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
policy
!=
return_value_policy
::
automatic
&&
policy
!=
return_value_policy
::
reference_internal
)
{
// IMPROVABLE: Error message.
//
SMART_HOLDER_WIP:
IMPROVABLE: Error message.
throw
cast_error
(
"Invalid return_value_policy for shared_ptr."
);
}
...
...
@@ -1513,8 +1513,8 @@ 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
);
const
detail
::
type_info
*
tinfo
=
st
.
second
;
if
(
handle
existing_inst
=
find_registered_python_instance
(
src_raw_void_ptr
,
tinfo
))
// MISSING: Enforcement of consistency with existing smart_holder.
// MISSING: keep_alive.
//
SMART_HOLDER_WIP:
MISSING: Enforcement of consistency with existing smart_holder.
//
SMART_HOLDER_WIP:
MISSING: keep_alive.
return
existing_inst
;
auto
inst
=
reinterpret_steal
<
object
>
(
make_new_instance
(
tinfo
->
type
));
...
...
@@ -1566,7 +1566,7 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
if
(
policy
!=
return_value_policy
::
automatic
&&
policy
!=
return_value_policy
::
reference_internal
&&
policy
!=
return_value_policy
::
move
)
{
// IMPROVABLE: Error message.
//
SMART_HOLDER_WIP:
IMPROVABLE: Error message.
throw
cast_error
(
"Invalid return_value_policy for unique_ptr."
);
}
...
...
tests/test_class.cpp
View file @
dc10e8a9
...
...
@@ -23,6 +23,8 @@
# pragma warning(disable: 4324) // warning C4324: structure was padded due to alignment specifier
#endif
namespace
{
// test_brace_initialization
struct
NoBraceInitialization
{
NoBraceInitialization
(
std
::
vector
<
int
>
v
)
:
vec
{
std
::
move
(
v
)}
{}
...
...
@@ -32,14 +34,17 @@ struct NoBraceInitialization {
std
::
vector
<
int
>
vec
;
};
// test_mismatched_holder
struct
MismatchBase1
{
};
struct
MismatchDerived1
:
MismatchBase1
{
};
struct
MismatchBase2
{
};
struct
MismatchDerived2
:
MismatchBase2
{
};
// test_multiple_instances_with_same_pointer
struct
SamePointer
{};
}
// namespace
PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS
(
MismatchBase1
,
std
::
shared_ptr
<
MismatchBase1
>
)
PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS
(
MismatchDerived1
,
std
::
unique_ptr
<
MismatchDerived1
>
)
PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS
(
MismatchBase2
,
std
::
unique_ptr
<
MismatchBase2
>
)
...
...
tests/test_multiple_inheritance.cpp
View file @
dc10e8a9
...
...
@@ -11,6 +11,8 @@
#include "pybind11_tests.h"
#include "constructor_stats.h"
namespace
{
// Many bases for testing that multiple inheritance from many classes (i.e. requiring extra
// space for holder constructed flags) works.
template
<
int
N
>
struct
BaseN
{
...
...
@@ -43,26 +45,27 @@ int WithStatic2::static_value2 = 2;
int
VanillaStaticMix1
::
static_value
=
12
;
int
VanillaStaticMix2
::
static_value
=
12
;
namespace
{
struct
Base1a
{
Base1a
(
int
i
)
:
i
(
i
)
{
}
int
foo
()
{
return
i
;
}
int
i
;
};
struct
Base2a
{
Base2a
(
int
i
)
:
i
(
i
)
{
}
int
bar
()
{
return
i
;
}
int
i
;
};
struct
Base12a
:
Base1a
,
Base2a
{
Base12a
(
int
i
,
int
j
)
:
Base1a
(
i
),
Base2a
(
j
)
{
}
};
// test_multiple_inheritance_virtbase
struct
Base1a
{
Base1a
(
int
i
)
:
i
(
i
)
{
}
int
foo
()
{
return
i
;
}
int
i
;
};
struct
Base2a
{
Base2a
(
int
i
)
:
i
(
i
)
{
}
int
bar
()
{
return
i
;
}
int
i
;
};
struct
Base12a
:
Base1a
,
Base2a
{
Base12a
(
int
i
,
int
j
)
:
Base1a
(
i
),
Base2a
(
j
)
{
}
};
struct
I801B1
{
int
a
=
1
;
I801B1
()
=
default
;
I801B1
(
const
I801B1
&
)
=
default
;
virtual
~
I801B1
()
=
default
;
};
struct
I801B2
{
int
b
=
2
;
I801B2
()
=
default
;
I801B2
(
const
I801B2
&
)
=
default
;
virtual
~
I801B2
()
=
default
;
};
struct
I801C
:
I801B1
,
I801B2
{};
struct
I801D
:
I801C
{};
// Indirect MI
// test_mi_unaligned_base
// test_mi_base_return
struct
I801B1
{
int
a
=
1
;
I801B1
()
=
default
;
I801B1
(
const
I801B1
&
)
=
default
;
virtual
~
I801B1
()
=
default
;
};
struct
I801B2
{
int
b
=
2
;
I801B2
()
=
default
;
I801B2
(
const
I801B2
&
)
=
default
;
virtual
~
I801B2
()
=
default
;
};
struct
I801C
:
I801B1
,
I801B2
{};
struct
I801D
:
I801C
{};
// Indirect MI
}
// namespace
...
...
tests/test_smart_ptr.cpp
View file @
dc10e8a9
This diff is collapsed.
Click to expand it.
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