Skip to content

Commit ec24786

Browse files
rwgkhenryiii
andauthored
Fully-automatic clang-format with include reordering (#3713)
* chore: add clang-format * Removing check-style (Classic check-style) Ported from @henryiii's 53056b1 * Automatic clang-format changes (NO manual changes). Co-authored-by: Henry Schreiner <[email protected]>
1 parent e96221b commit ec24786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7067
-5152
lines changed

.pre-commit-config.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ repos:
141141
entry: PyBind|Numpy|Cmake|CCache|PyTest
142142
exclude: .pre-commit-config.yaml
143143

144-
- repo: local
144+
- repo: https://github.com/pre-commit/mirrors-clang-format
145+
rev: "v13.0.0"
145146
hooks:
146-
- id: check-style
147-
name: Classic check-style
148-
language: system
149-
types:
150-
- c++
151-
entry: ./tools/check-style.sh
147+
- id: clang-format

include/pybind11/attr.h

+128-79
Large diffs are not rendered by default.

include/pybind11/buffer_info.h

+72-32
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ struct buffer_info {
4444
void *ptr = nullptr; // Pointer to the underlying storage
4545
ssize_t itemsize = 0; // Size of individual items in bytes
4646
ssize_t size = 0; // Total number of entries
47-
std::string format; // For homogeneous buffers, this should be set to
48-
// format_descriptor<T>::format()
47+
std::string format; // For homogeneous buffers, this should be set to
48+
// format_descriptor<T>::format()
4949
ssize_t ndim = 0; // Number of dimensions
5050
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
5151
std::vector<ssize_t> strides; // Number of bytes between adjacent entries
@@ -54,10 +54,15 @@ struct buffer_info {
5454

5555
buffer_info() = default;
5656

57-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
58-
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
59-
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
60-
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
57+
buffer_info(void *ptr,
58+
ssize_t itemsize,
59+
const std::string &format,
60+
ssize_t ndim,
61+
detail::any_container<ssize_t> shape_in,
62+
detail::any_container<ssize_t> strides_in,
63+
bool readonly = false)
64+
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
65+
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
6166
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) {
6267
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
6368
}
@@ -67,29 +72,48 @@ struct buffer_info {
6772
}
6873

6974
template <typename T>
70-
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
71-
: buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) { }
72-
73-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
74-
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { }
75+
buffer_info(T *ptr,
76+
detail::any_container<ssize_t> shape_in,
77+
detail::any_container<ssize_t> strides_in,
78+
bool readonly = false)
79+
: buffer_info(private_ctr_tag(),
80+
ptr,
81+
sizeof(T),
82+
format_descriptor<T>::format(),
83+
static_cast<ssize_t>(shape_in->size()),
84+
std::move(shape_in),
85+
std::move(strides_in),
86+
readonly) {}
87+
88+
buffer_info(void *ptr,
89+
ssize_t itemsize,
90+
const std::string &format,
91+
ssize_t size,
92+
bool readonly = false)
93+
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) {}
7594

7695
template <typename T>
77-
buffer_info(T *ptr, ssize_t size, bool readonly=false)
78-
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) { }
96+
buffer_info(T *ptr, ssize_t size, bool readonly = false)
97+
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) {}
7998

8099
template <typename T>
81-
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
82-
: buffer_info(const_cast<T*>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) { }
100+
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
101+
: buffer_info(
102+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
83103

84104
explicit buffer_info(Py_buffer *view, bool ownview = true)
85-
: buffer_info(view->buf, view->itemsize, view->format, view->ndim,
105+
: buffer_info(
106+
view->buf,
107+
view->itemsize,
108+
view->format,
109+
view->ndim,
86110
{view->shape, view->shape + view->ndim},
87111
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
88112
* ignore this flag and return a view with NULL strides.
89113
* When strides are NULL, build them manually. */
90114
view->strides
91-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
92-
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
115+
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
116+
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
93117
(view->readonly != 0)) {
94118
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
95119
this->m_view = view;
@@ -98,7 +122,7 @@ struct buffer_info {
98122
}
99123

100124
buffer_info(const buffer_info &) = delete;
101-
buffer_info& operator=(const buffer_info &) = delete;
125+
buffer_info &operator=(const buffer_info &) = delete;
102126

103127
buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); }
104128

@@ -117,35 +141,51 @@ struct buffer_info {
117141
}
118142

119143
~buffer_info() {
120-
if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; }
144+
if (m_view && ownview) {
145+
PyBuffer_Release(m_view);
146+
delete m_view;
147+
}
121148
}
122149

123150
Py_buffer *view() const { return m_view; }
124151
Py_buffer *&view() { return m_view; }
125-
private:
126-
struct private_ctr_tag { };
127152

128-
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
129-
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
130-
: buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { }
153+
private:
154+
struct private_ctr_tag {};
155+
156+
buffer_info(private_ctr_tag,
157+
void *ptr,
158+
ssize_t itemsize,
159+
const std::string &format,
160+
ssize_t ndim,
161+
detail::any_container<ssize_t> &&shape_in,
162+
detail::any_container<ssize_t> &&strides_in,
163+
bool readonly)
164+
: buffer_info(
165+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
131166

132167
Py_buffer *m_view = nullptr;
133168
bool ownview = false;
134169
};
135170

136171
PYBIND11_NAMESPACE_BEGIN(detail)
137172

138-
template <typename T, typename SFINAE = void> struct compare_buffer_info {
139-
static bool compare(const buffer_info& b) {
173+
template <typename T, typename SFINAE = void>
174+
struct compare_buffer_info {
175+
static bool compare(const buffer_info &b) {
140176
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
141177
}
142178
};
143179

144-
template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
145-
static bool compare(const buffer_info& b) {
146-
return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor<T>::value ||
147-
((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned<T>::value ? "L" : "l")) ||
148-
((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned<T>::value ? "N" : "n")));
180+
template <typename T>
181+
struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
182+
static bool compare(const buffer_info &b) {
183+
return (size_t) b.itemsize == sizeof(T)
184+
&& (b.format == format_descriptor<T>::value
185+
|| ((sizeof(T) == sizeof(long))
186+
&& b.format == (std::is_unsigned<T>::value ? "L" : "l"))
187+
|| ((sizeof(T) == sizeof(size_t))
188+
&& b.format == (std::is_unsigned<T>::value ? "N" : "n")));
149189
}
150190
};
151191

0 commit comments

Comments
 (0)