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
ce88e940
Commit
ce88e940
authored
Sep 10, 2020
by
Henry Schreiner
Committed by
Henry Schreiner
Sep 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: clang-tidy: modernize-use-auto
parent
b491b465
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
19 additions
and
18 deletions
+19
-18
.clang-tidy
+1
-0
include/pybind11/cast.h
+4
-4
include/pybind11/numpy.h
+2
-2
include/pybind11/pybind11.h
+6
-6
include/pybind11/pytypes.h
+1
-1
include/pybind11/stl_bind.h
+1
-1
tests/test_numpy_array.cpp
+2
-2
tests/test_opaque_types.cpp
+1
-1
tests/test_sequences_and_iterators.cpp
+1
-1
No files found.
.clang-tidy
View file @
ce88e940
...
@@ -7,6 +7,7 @@ modernize-use-override,
...
@@ -7,6 +7,7 @@ modernize-use-override,
readability-container-size-empty,
readability-container-size-empty,
modernize-use-using,
modernize-use-using,
modernize-use-equals-default,
modernize-use-equals-default,
modernize-use-auto,
'
'
HeaderFilterRegex: 'pybind11/.*h'
HeaderFilterRegex: 'pybind11/.*h'
include/pybind11/cast.h
View file @
ce88e940
...
@@ -432,7 +432,7 @@ PYBIND11_NOINLINE inline std::string error_string() {
...
@@ -432,7 +432,7 @@ PYBIND11_NOINLINE inline std::string error_string() {
#if !defined(PYPY_VERSION)
#if !defined(PYPY_VERSION)
if
(
scope
.
trace
)
{
if
(
scope
.
trace
)
{
PyTracebackObject
*
trace
=
(
PyTracebackObject
*
)
scope
.
trace
;
auto
*
trace
=
(
PyTracebackObject
*
)
scope
.
trace
;
/* Get the deepest trace possible */
/* Get the deepest trace possible */
while
(
trace
->
tb_next
)
while
(
trace
->
tb_next
)
...
@@ -1244,7 +1244,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
...
@@ -1244,7 +1244,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
load_src
.
ptr
(),
UTF_N
==
8
?
"utf-8"
:
UTF_N
==
16
?
"utf-16"
:
"utf-32"
,
nullptr
));
load_src
.
ptr
(),
UTF_N
==
8
?
"utf-8"
:
UTF_N
==
16
?
"utf-16"
:
"utf-32"
,
nullptr
));
if
(
!
utfNbytes
)
{
PyErr_Clear
();
return
false
;
}
if
(
!
utfNbytes
)
{
PyErr_Clear
();
return
false
;
}
const
CharT
*
buffer
=
reinterpret_cast
<
const
CharT
*>
(
PYBIND11_BYTES_AS_STRING
(
utfNbytes
.
ptr
()));
const
auto
*
buffer
=
reinterpret_cast
<
const
CharT
*>
(
PYBIND11_BYTES_AS_STRING
(
utfNbytes
.
ptr
()));
size_t
length
=
(
size_t
)
PYBIND11_BYTES_SIZE
(
utfNbytes
.
ptr
())
/
sizeof
(
CharT
);
size_t
length
=
(
size_t
)
PYBIND11_BYTES_SIZE
(
utfNbytes
.
ptr
())
/
sizeof
(
CharT
);
if
(
UTF_N
>
8
)
{
buffer
++
;
length
--
;
}
// Skip BOM for UTF-16/32
if
(
UTF_N
>
8
)
{
buffer
++
;
length
--
;
}
// Skip BOM for UTF-16/32
value
=
StringType
(
buffer
,
length
);
value
=
StringType
(
buffer
,
length
);
...
@@ -1258,7 +1258,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
...
@@ -1258,7 +1258,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
static
handle
cast
(
const
StringType
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
StringType
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
const
char
*
buffer
=
reinterpret_cast
<
const
char
*>
(
src
.
data
());
const
char
*
buffer
=
reinterpret_cast
<
const
char
*>
(
src
.
data
());
ssize_t
nbytes
=
ssize_t
(
src
.
size
()
*
sizeof
(
CharT
));
auto
nbytes
=
ssize_t
(
src
.
size
()
*
sizeof
(
CharT
));
handle
s
=
decode_utfN
(
buffer
,
nbytes
);
handle
s
=
decode_utfN
(
buffer
,
nbytes
);
if
(
!
s
)
throw
error_already_set
();
if
(
!
s
)
throw
error_already_set
();
return
s
;
return
s
;
...
@@ -1364,7 +1364,7 @@ public:
...
@@ -1364,7 +1364,7 @@ public:
// errors. We also allow want to allow unicode characters U+0080 through U+00FF, as those
// errors. We also allow want to allow unicode characters U+0080 through U+00FF, as those
// can fit into a single char value.
// can fit into a single char value.
if
(
StringCaster
::
UTF_N
==
8
&&
str_len
>
1
&&
str_len
<=
4
)
{
if
(
StringCaster
::
UTF_N
==
8
&&
str_len
>
1
&&
str_len
<=
4
)
{
unsigned
char
v0
=
static_cast
<
unsigned
char
>
(
value
[
0
]);
auto
v0
=
static_cast
<
unsigned
char
>
(
value
[
0
]);
size_t
char0_bytes
=
!
(
v0
&
0x80
)
?
1
:
// low bits only: 0-127
size_t
char0_bytes
=
!
(
v0
&
0x80
)
?
1
:
// low bits only: 0-127
(
v0
&
0xE0
)
==
0xC0
?
2
:
// 0b110xxxxx - start of 2-byte sequence
(
v0
&
0xE0
)
==
0xC0
?
2
:
// 0b110xxxxx - start of 2-byte sequence
(
v0
&
0xF0
)
==
0xE0
?
3
:
// 0b1110xxxx - start of 3-byte sequence
(
v0
&
0xF0
)
==
0xE0
?
3
:
// 0b1110xxxx - start of 3-byte sequence
...
...
include/pybind11/numpy.h
View file @
ce88e940
...
@@ -1296,7 +1296,7 @@ public:
...
@@ -1296,7 +1296,7 @@ public:
m_strides
.
back
()
=
static_cast
<
value_type
>
(
strides
.
back
());
m_strides
.
back
()
=
static_cast
<
value_type
>
(
strides
.
back
());
for
(
size_type
i
=
m_strides
.
size
()
-
1
;
i
!=
0
;
--
i
)
{
for
(
size_type
i
=
m_strides
.
size
()
-
1
;
i
!=
0
;
--
i
)
{
size_type
j
=
i
-
1
;
size_type
j
=
i
-
1
;
value_type
s
=
static_cast
<
value_type
>
(
shape
[
i
]);
auto
s
=
static_cast
<
value_type
>
(
shape
[
i
]);
m_strides
[
j
]
=
strides
[
j
]
+
m_strides
[
i
]
-
strides
[
i
]
*
s
;
m_strides
[
j
]
=
strides
[
j
]
+
m_strides
[
i
]
-
strides
[
i
]
*
s
;
}
}
}
}
...
@@ -1539,7 +1539,7 @@ private:
...
@@ -1539,7 +1539,7 @@ private:
ssize_t
nd
=
0
;
ssize_t
nd
=
0
;
std
::
vector
<
ssize_t
>
shape
(
0
);
std
::
vector
<
ssize_t
>
shape
(
0
);
auto
trivial
=
broadcast
(
buffers
,
nd
,
shape
);
auto
trivial
=
broadcast
(
buffers
,
nd
,
shape
);
size_t
ndim
=
(
size_t
)
nd
;
auto
ndim
=
(
size_t
)
nd
;
size_t
size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
(
size_t
)
1
,
std
::
multiplies
<
size_t
>
());
size_t
size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
(
size_t
)
1
,
std
::
multiplies
<
size_t
>
());
...
...
include/pybind11/pybind11.h
View file @
ce88e940
...
@@ -165,7 +165,7 @@ protected:
...
@@ -165,7 +165,7 @@ protected:
/* Get a pointer to the capture object */
/* Get a pointer to the capture object */
auto
data
=
(
sizeof
(
capture
)
<=
sizeof
(
call
.
func
.
data
)
auto
data
=
(
sizeof
(
capture
)
<=
sizeof
(
call
.
func
.
data
)
?
&
call
.
func
.
data
:
call
.
func
.
data
[
0
]);
?
&
call
.
func
.
data
:
call
.
func
.
data
[
0
]);
capture
*
cap
=
const_cast
<
capture
*>
(
reinterpret_cast
<
const
capture
*>
(
data
));
auto
*
cap
=
const_cast
<
capture
*>
(
reinterpret_cast
<
const
capture
*>
(
data
));
/* Override policy for rvalues -- usually to enforce rvp::move on an rvalue */
/* Override policy for rvalues -- usually to enforce rvp::move on an rvalue */
return_value_policy
policy
=
return_value_policy_override
<
Return
>::
policy
(
call
.
func
.
policy
);
return_value_policy
policy
=
return_value_policy_override
<
Return
>::
policy
(
call
.
func
.
policy
);
...
@@ -420,7 +420,7 @@ protected:
...
@@ -420,7 +420,7 @@ protected:
}
}
/* Install docstring */
/* Install docstring */
PyCFunctionObject
*
func
=
(
PyCFunctionObject
*
)
m_ptr
;
auto
*
func
=
(
PyCFunctionObject
*
)
m_ptr
;
if
(
func
->
m_ml
->
ml_doc
)
if
(
func
->
m_ml
->
ml_doc
)
std
::
free
(
const_cast
<
char
*>
(
func
->
m_ml
->
ml_doc
));
std
::
free
(
const_cast
<
char
*>
(
func
->
m_ml
->
ml_doc
));
func
->
m_ml
->
ml_doc
=
strdup
(
signatures
.
c_str
());
func
->
m_ml
->
ml_doc
=
strdup
(
signatures
.
c_str
());
...
@@ -465,7 +465,7 @@ protected:
...
@@ -465,7 +465,7 @@ protected:
*
it
=
overloads
;
*
it
=
overloads
;
/* Need to know how many arguments + keyword arguments there are to pick the right overload */
/* Need to know how many arguments + keyword arguments there are to pick the right overload */
const
size_t
n_args_in
=
(
size_t
)
PyTuple_GET_SIZE
(
args_in
);
const
auto
n_args_in
=
(
size_t
)
PyTuple_GET_SIZE
(
args_in
);
handle
parent
=
n_args_in
>
0
?
PyTuple_GET_ITEM
(
args_in
,
0
)
:
nullptr
,
handle
parent
=
n_args_in
>
0
?
PyTuple_GET_ITEM
(
args_in
,
0
)
:
nullptr
,
result
=
PYBIND11_TRY_NEXT_OVERLOAD
;
result
=
PYBIND11_TRY_NEXT_OVERLOAD
;
...
@@ -860,7 +860,7 @@ public:
...
@@ -860,7 +860,7 @@ public:
explicit
module
(
const
char
*
name
,
const
char
*
doc
=
nullptr
)
{
explicit
module
(
const
char
*
name
,
const
char
*
doc
=
nullptr
)
{
if
(
!
options
::
show_user_defined_docstrings
())
doc
=
nullptr
;
if
(
!
options
::
show_user_defined_docstrings
())
doc
=
nullptr
;
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
PyModuleDef
*
def
=
new
PyModuleDef
();
auto
*
def
=
new
PyModuleDef
();
std
::
memset
(
def
,
0
,
sizeof
(
PyModuleDef
));
std
::
memset
(
def
,
0
,
sizeof
(
PyModuleDef
));
def
->
m_name
=
name
;
def
->
m_name
=
name
;
def
->
m_doc
=
doc
;
def
->
m_doc
=
doc
;
...
@@ -1020,7 +1020,7 @@ protected:
...
@@ -1020,7 +1020,7 @@ protected:
void
install_buffer_funcs
(
void
install_buffer_funcs
(
buffer_info
*
(
*
get_buffer
)(
PyObject
*
,
void
*
),
buffer_info
*
(
*
get_buffer
)(
PyObject
*
,
void
*
),
void
*
get_buffer_data
)
{
void
*
get_buffer_data
)
{
PyHeapTypeObject
*
type
=
(
PyHeapTypeObject
*
)
m_ptr
;
auto
*
type
=
(
PyHeapTypeObject
*
)
m_ptr
;
auto
tinfo
=
detail
::
get_type_info
(
&
type
->
ht_type
);
auto
tinfo
=
detail
::
get_type_info
(
&
type
->
ht_type
);
if
(
!
type
->
ht_type
.
tp_as_buffer
)
if
(
!
type
->
ht_type
.
tp_as_buffer
)
...
@@ -1242,7 +1242,7 @@ public:
...
@@ -1242,7 +1242,7 @@ public:
template
<
typename
Func
>
class_
&
def_buffer
(
Func
&&
func
)
{
template
<
typename
Func
>
class_
&
def_buffer
(
Func
&&
func
)
{
struct
capture
{
Func
func
;
};
struct
capture
{
Func
func
;
};
capture
*
ptr
=
new
capture
{
std
::
forward
<
Func
>
(
func
)
};
auto
*
ptr
=
new
capture
{
std
::
forward
<
Func
>
(
func
)
};
install_buffer_funcs
([](
PyObject
*
obj
,
void
*
ptr
)
->
buffer_info
*
{
install_buffer_funcs
([](
PyObject
*
obj
,
void
*
ptr
)
->
buffer_info
*
{
detail
::
make_caster
<
type
>
caster
;
detail
::
make_caster
<
type
>
caster
;
if
(
!
caster
.
load
(
obj
,
false
))
if
(
!
caster
.
load
(
obj
,
false
))
...
...
include/pybind11/pytypes.h
View file @
ce88e940
...
@@ -1351,7 +1351,7 @@ public:
...
@@ -1351,7 +1351,7 @@ public:
buffer_info
request
(
bool
writable
=
false
)
const
{
buffer_info
request
(
bool
writable
=
false
)
const
{
int
flags
=
PyBUF_STRIDES
|
PyBUF_FORMAT
;
int
flags
=
PyBUF_STRIDES
|
PyBUF_FORMAT
;
if
(
writable
)
flags
|=
PyBUF_WRITABLE
;
if
(
writable
)
flags
|=
PyBUF_WRITABLE
;
Py_buffer
*
view
=
new
Py_buffer
();
auto
*
view
=
new
Py_buffer
();
if
(
PyObject_GetBuffer
(
m_ptr
,
view
,
flags
)
!=
0
)
{
if
(
PyObject_GetBuffer
(
m_ptr
,
view
,
flags
)
!=
0
)
{
delete
view
;
delete
view
;
throw
error_already_set
();
throw
error_already_set
();
...
...
include/pybind11/stl_bind.h
View file @
ce88e940
...
@@ -223,7 +223,7 @@ void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_t
...
@@ -223,7 +223,7 @@ void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_t
if
(
!
slice
.
compute
(
v
.
size
(),
&
start
,
&
stop
,
&
step
,
&
slicelength
))
if
(
!
slice
.
compute
(
v
.
size
(),
&
start
,
&
stop
,
&
step
,
&
slicelength
))
throw
error_already_set
();
throw
error_already_set
();
Vector
*
seq
=
new
Vector
();
auto
*
seq
=
new
Vector
();
seq
->
reserve
((
size_t
)
slicelength
);
seq
->
reserve
((
size_t
)
slicelength
);
for
(
size_t
i
=
0
;
i
<
slicelength
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
slicelength
;
++
i
)
{
...
...
tests/test_numpy_array.cpp
View file @
ce88e940
...
@@ -212,7 +212,7 @@ TEST_SUBMODULE(numpy_array, sm) {
...
@@ -212,7 +212,7 @@ TEST_SUBMODULE(numpy_array, sm) {
.
def
(
py
::
init
<>
())
.
def
(
py
::
init
<>
())
.
def
(
"numpy_view"
,
[](
py
::
object
&
obj
)
{
.
def
(
"numpy_view"
,
[](
py
::
object
&
obj
)
{
py
::
print
(
"ArrayClass::numpy_view()"
);
py
::
print
(
"ArrayClass::numpy_view()"
);
ArrayClass
&
a
=
obj
.
cast
<
ArrayClass
&>
();
auto
&
a
=
obj
.
cast
<
ArrayClass
&>
();
return
py
::
array_t
<
int
>
({
2
},
{
4
},
a
.
data
,
obj
);
return
py
::
array_t
<
int
>
({
2
},
{
4
},
a
.
data
,
obj
);
}
}
);
);
...
@@ -362,7 +362,7 @@ TEST_SUBMODULE(numpy_array, sm) {
...
@@ -362,7 +362,7 @@ TEST_SUBMODULE(numpy_array, sm) {
// test_array_resize
// test_array_resize
// reshape array to 2D without changing size
// reshape array to 2D without changing size
sm
.
def
(
"array_reshape2"
,
[](
py
::
array_t
<
double
>
a
)
{
sm
.
def
(
"array_reshape2"
,
[](
py
::
array_t
<
double
>
a
)
{
const
ssize_t
dim_sz
=
(
ssize_t
)
std
::
sqrt
(
a
.
size
());
const
auto
dim_sz
=
(
ssize_t
)
std
::
sqrt
(
a
.
size
());
if
(
dim_sz
*
dim_sz
!=
a
.
size
())
if
(
dim_sz
*
dim_sz
!=
a
.
size
())
throw
std
::
domain_error
(
"array_reshape2: input array total size is not a squared integer"
);
throw
std
::
domain_error
(
"array_reshape2: input array total size is not a squared integer"
);
a
.
resize
({
dim_sz
,
dim_sz
});
a
.
resize
({
dim_sz
,
dim_sz
});
...
...
tests/test_opaque_types.cpp
View file @
ce88e940
...
@@ -60,7 +60,7 @@ TEST_SUBMODULE(opaque_types, m) {
...
@@ -60,7 +60,7 @@ TEST_SUBMODULE(opaque_types, m) {
m
.
def
(
"get_null_str_value"
,
[](
char
*
ptr
)
{
return
reinterpret_cast
<
std
::
intptr_t
>
(
ptr
);
});
m
.
def
(
"get_null_str_value"
,
[](
char
*
ptr
)
{
return
reinterpret_cast
<
std
::
intptr_t
>
(
ptr
);
});
m
.
def
(
"return_unique_ptr"
,
[]()
->
std
::
unique_ptr
<
StringList
>
{
m
.
def
(
"return_unique_ptr"
,
[]()
->
std
::
unique_ptr
<
StringList
>
{
StringList
*
result
=
new
StringList
();
auto
*
result
=
new
StringList
();
result
->
push_back
(
"some value"
);
result
->
push_back
(
"some value"
);
return
std
::
unique_ptr
<
StringList
>
(
result
);
return
std
::
unique_ptr
<
StringList
>
(
result
);
});
});
...
...
tests/test_sequences_and_iterators.cpp
View file @
ce88e940
...
@@ -200,7 +200,7 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
...
@@ -200,7 +200,7 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
size_t
start
,
stop
,
step
,
slicelength
;
size_t
start
,
stop
,
step
,
slicelength
;
if
(
!
slice
.
compute
(
s
.
size
(),
&
start
,
&
stop
,
&
step
,
&
slicelength
))
if
(
!
slice
.
compute
(
s
.
size
(),
&
start
,
&
stop
,
&
step
,
&
slicelength
))
throw
py
::
error_already_set
();
throw
py
::
error_already_set
();
Sequence
*
seq
=
new
Sequence
(
slicelength
);
auto
*
seq
=
new
Sequence
(
slicelength
);
for
(
size_t
i
=
0
;
i
<
slicelength
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
slicelength
;
++
i
)
{
(
*
seq
)[
i
]
=
s
[
start
];
start
+=
step
;
(
*
seq
)[
i
]
=
s
[
start
];
start
+=
step
;
}
}
...
...
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