Skip to content

Commit 590822a

Browse files
committed
Automatic clang-format changes (NO manual changes).
1 parent 2f78a4a commit 590822a

Some content is hidden

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

73 files changed

+7028
-5127
lines changed

include/pybind11/attr.h

Lines changed: 130 additions & 80 deletions
Large diffs are not rendered by default.

include/pybind11/buffer_info.h

Lines changed: 72 additions & 32 deletions
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,36 +72,55 @@ 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
this->m_view = view;
95119
this->ownview = ownview;
96120
}
97121

98122
buffer_info(const buffer_info &) = delete;
99-
buffer_info& operator=(const buffer_info &) = delete;
123+
buffer_info &operator=(const buffer_info &) = delete;
100124

101125
buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); }
102126

@@ -115,35 +139,51 @@ struct buffer_info {
115139
}
116140

117141
~buffer_info() {
118-
if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; }
142+
if (m_view && ownview) {
143+
PyBuffer_Release(m_view);
144+
delete m_view;
145+
}
119146
}
120147

121148
Py_buffer *view() const { return m_view; }
122149
Py_buffer *&view() { return m_view; }
123-
private:
124-
struct private_ctr_tag { };
125150

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

130165
Py_buffer *m_view = nullptr;
131166
bool ownview = false;
132167
};
133168

134169
PYBIND11_NAMESPACE_BEGIN(detail)
135170

136-
template <typename T, typename SFINAE = void> struct compare_buffer_info {
137-
static bool compare(const buffer_info& b) {
171+
template <typename T, typename SFINAE = void>
172+
struct compare_buffer_info {
173+
static bool compare(const buffer_info &b) {
138174
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
139175
}
140176
};
141177

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

0 commit comments

Comments
 (0)