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
8581584e
Commit
8581584e
authored
Feb 07, 2022
by
Ralf W. Grosse-Kunstleve
Committed by
Ralf W. Grosse-Kunstleve
Feb 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Manual fix-ups in preparation for clang-tidy readability-braces-around-statements.
Informed by experiments under PR #3698.
parent
af056b65
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
14 deletions
+25
-14
include/pybind11/cast.h
+10
-6
include/pybind11/detail/init.h
+3
-2
include/pybind11/detail/type_caster_base.h
+10
-5
include/pybind11/pybind11.h
+2
-1
No files found.
include/pybind11/cast.h
View file @
8581584e
...
@@ -915,7 +915,7 @@ template <> inline void handle::cast() const { return; }
...
@@ -915,7 +915,7 @@ template <> inline void handle::cast() const { return; }
template
<
typename
T
>
template
<
typename
T
>
detail
::
enable_if_t
<!
detail
::
move_never
<
T
>::
value
,
T
>
move
(
object
&&
obj
)
{
detail
::
enable_if_t
<!
detail
::
move_never
<
T
>::
value
,
T
>
move
(
object
&&
obj
)
{
if
(
obj
.
ref_count
()
>
1
)
if
(
obj
.
ref_count
()
>
1
)
{
#if defined(NDEBUG)
#if defined(NDEBUG)
throw
cast_error
(
"Unable to cast Python instance to C++ rvalue: instance has multiple references"
throw
cast_error
(
"Unable to cast Python instance to C++ rvalue: instance has multiple references"
" (compile in debug mode for details)"
);
" (compile in debug mode for details)"
);
...
@@ -923,6 +923,7 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
...
@@ -923,6 +923,7 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
throw
cast_error
(
"Unable to move from Python "
+
(
std
::
string
)
str
(
type
::
handle_of
(
obj
))
+
throw
cast_error
(
"Unable to move from Python "
+
(
std
::
string
)
str
(
type
::
handle_of
(
obj
))
+
" instance to C++ "
+
type_id
<
T
>
()
+
" instance: instance has multiple references"
);
" instance to C++ "
+
type_id
<
T
>
()
+
" instance: instance has multiple references"
);
#endif
#endif
}
// Move into a temporary and return that, because the reference may be a local value of `conv`
// Move into a temporary and return that, because the reference may be a local value of `conv`
T
ret
=
std
::
move
(
detail
::
load_type
<
T
>
(
obj
).
operator
T
&
());
T
ret
=
std
::
move
(
detail
::
load_type
<
T
>
(
obj
).
operator
T
&
());
...
@@ -1192,12 +1193,15 @@ private:
...
@@ -1192,12 +1193,15 @@ private:
template
<
size_t
...
Is
>
template
<
size_t
...
Is
>
bool
load_impl_sequence
(
function_call
&
call
,
index_sequence
<
Is
...
>
)
{
bool
load_impl_sequence
(
function_call
&
call
,
index_sequence
<
Is
...
>
)
{
#ifdef __cpp_fold_expressions
#ifdef __cpp_fold_expressions
if
((...
||
!
std
::
get
<
Is
>
(
argcasters
).
load
(
call
.
args
[
Is
],
call
.
args_convert
[
Is
])))
if
((...
||
!
std
::
get
<
Is
>
(
argcasters
).
load
(
call
.
args
[
Is
],
call
.
args_convert
[
Is
])))
{
return
false
;
return
false
;
}
#else
#else
for
(
bool
r
:
{
std
::
get
<
Is
>
(
argcasters
).
load
(
call
.
args
[
Is
],
call
.
args_convert
[
Is
])...})
for
(
bool
r
:
{
std
::
get
<
Is
>
(
argcasters
).
load
(
call
.
args
[
Is
],
call
.
args_convert
[
Is
])...})
{
if
(
!
r
)
if
(
!
r
)
{
return
false
;
return
false
;
}
}
#endif
#endif
return
true
;
return
true
;
}
}
...
@@ -1286,13 +1290,13 @@ private:
...
@@ -1286,13 +1290,13 @@ private:
}
}
void
process
(
list
&
/*args_list*/
,
arg_v
a
)
{
void
process
(
list
&
/*args_list*/
,
arg_v
a
)
{
if
(
!
a
.
name
)
if
(
!
a
.
name
)
{
#if defined(NDEBUG)
#if defined(NDEBUG)
nameless_argument_error
();
nameless_argument_error
();
#else
#else
nameless_argument_error
(
a
.
type
);
nameless_argument_error
(
a
.
type
);
#endif
#endif
}
if
(
m_kwargs
.
contains
(
a
.
name
))
{
if
(
m_kwargs
.
contains
(
a
.
name
))
{
#if defined(NDEBUG)
#if defined(NDEBUG)
multiple_values_error
();
multiple_values_error
();
...
...
include/pybind11/detail/init.h
View file @
8581584e
...
@@ -276,12 +276,13 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
...
@@ -276,12 +276,13 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
cl
.
def
(
"__init__"
,
[
class_func
,
alias_func
]
cl
.
def
(
"__init__"
,
[
class_func
,
alias_func
]
#endif
#endif
(
value_and_holder
&
v_h
,
CArgs
...
args
)
{
(
value_and_holder
&
v_h
,
CArgs
...
args
)
{
if
(
Py_TYPE
(
v_h
.
inst
)
==
v_h
.
type
->
type
)
if
(
Py_TYPE
(
v_h
.
inst
)
==
v_h
.
type
->
type
)
{
// If the instance type equals the registered type we don't have inheritance, so
// If the instance type equals the registered type we don't have inheritance, so
// don't need the alias and can construct using the class function:
// don't need the alias and can construct using the class function:
construct
<
Class
>
(
v_h
,
class_func
(
std
::
forward
<
CArgs
>
(
args
)...),
false
);
construct
<
Class
>
(
v_h
,
class_func
(
std
::
forward
<
CArgs
>
(
args
)...),
false
);
else
}
else
{
construct
<
Class
>
(
v_h
,
alias_func
(
std
::
forward
<
CArgs
>
(
args
)...),
true
);
construct
<
Class
>
(
v_h
,
alias_func
(
std
::
forward
<
CArgs
>
(
args
)...),
true
);
}
},
is_new_style_constructor
(),
extra
...);
},
is_new_style_constructor
(),
extra
...);
}
}
};
};
...
...
include/pybind11/detail/type_caster_base.h
View file @
8581584e
...
@@ -625,12 +625,15 @@ public:
...
@@ -625,12 +625,15 @@ public:
vptr
=
type
->
operator_new
(
type
->
type_size
);
vptr
=
type
->
operator_new
(
type
->
type_size
);
}
else
{
}
else
{
#if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
#if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
if
(
type
->
type_align
>
__STDCPP_DEFAULT_NEW_ALIGNMENT__
)
if
(
type
->
type_align
>
__STDCPP_DEFAULT_NEW_ALIGNMENT__
)
{
vptr
=
::
operator
new
(
type
->
type_size
,
vptr
=
::
operator
new
(
type
->
type_size
,
std
::
align_val_t
(
type
->
type_align
));
std
::
align_val_t
(
type
->
type_align
));
else
}
else
{
vptr
=
::
operator
new
(
type
->
type_size
);
}
#else
vptr
=
::
operator
new
(
type
->
type_size
);
#endif
#endif
vptr
=
::
operator
new
(
type
->
type_size
);
}
}
}
}
value
=
vptr
;
value
=
vptr
;
...
@@ -778,8 +781,9 @@ public:
...
@@ -778,8 +781,9 @@ public:
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
PYBIND11_NOINLINE
static
std
::
pair
<
const
void
*
,
const
type_info
*>
src_and_type
(
PYBIND11_NOINLINE
static
std
::
pair
<
const
void
*
,
const
type_info
*>
src_and_type
(
const
void
*
src
,
const
std
::
type_info
&
cast_type
,
const
std
::
type_info
*
rtti_type
=
nullptr
)
{
const
void
*
src
,
const
std
::
type_info
&
cast_type
,
const
std
::
type_info
*
rtti_type
=
nullptr
)
{
if
(
auto
*
tpi
=
get_type_info
(
cast_type
))
if
(
auto
*
tpi
=
get_type_info
(
cast_type
))
{
return
{
src
,
const_cast
<
const
type_info
*>
(
tpi
)};
return
{
src
,
const_cast
<
const
type_info
*>
(
tpi
)};
}
// Not found, set error:
// Not found, set error:
std
::
string
tname
=
rtti_type
?
rtti_type
->
name
()
:
cast_type
.
name
();
std
::
string
tname
=
rtti_type
?
rtti_type
->
name
()
:
cast_type
.
name
();
...
@@ -928,8 +932,9 @@ public:
...
@@ -928,8 +932,9 @@ public:
// except via a user-provided specialization of polymorphic_type_hook,
// except via a user-provided specialization of polymorphic_type_hook,
// and the user has promised that no this-pointer adjustment is
// and the user has promised that no this-pointer adjustment is
// required in that case, so it's OK to use static_cast.
// required in that case, so it's OK to use static_cast.
if
(
const
auto
*
tpi
=
get_type_info
(
*
instance_type
))
if
(
const
auto
*
tpi
=
get_type_info
(
*
instance_type
))
{
return
{
vsrc
,
tpi
};
return
{
vsrc
,
tpi
};
}
}
}
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
// don't do a cast
// don't do a cast
...
...
include/pybind11/pybind11.h
View file @
8581584e
...
@@ -183,12 +183,13 @@ protected:
...
@@ -183,12 +183,13 @@ protected:
#endif
#endif
// UB without std::launder, but without breaking ABI and/or
// UB without std::launder, but without breaking ABI and/or
// a significant refactoring it's "impossible" to solve.
// a significant refactoring it's "impossible" to solve.
if
(
!
std
::
is_trivially_destructible
<
capture
>::
value
)
if
(
!
std
::
is_trivially_destructible
<
capture
>::
value
)
{
rec
->
free_data
=
[](
function_record
*
r
)
{
rec
->
free_data
=
[](
function_record
*
r
)
{
auto
data
=
PYBIND11_STD_LAUNDER
((
capture
*
)
&
r
->
data
);
auto
data
=
PYBIND11_STD_LAUNDER
((
capture
*
)
&
r
->
data
);
(
void
)
data
;
(
void
)
data
;
data
->~
capture
();
data
->~
capture
();
};
};
}
#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER)
#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER)
# pragma GCC diagnostic pop
# pragma GCC diagnostic pop
#endif
#endif
...
...
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