Skip to content

Commit ecc33f0

Browse files
committed
Automatic clang-format changes (NO manual changes).
1 parent b34b2ac commit ecc33f0

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

+7093
-5173
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: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,28 @@ PYBIND11_NAMESPACE_END(detail)
4141

4242
/// Information record describing a Python buffer object
4343
struct buffer_info {
44-
void *ptr = nullptr; // Pointer to the underlying storage
45-
ssize_t itemsize = 0; // Size of individual items in bytes
46-
ssize_t size = 0; // Total number of entries
47-
std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
48-
ssize_t ndim = 0; // Number of dimensions
49-
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
50-
std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension)
51-
bool readonly = false; // flag to indicate if the underlying storage may be written to
44+
void *ptr = nullptr; // Pointer to the underlying storage
45+
ssize_t itemsize = 0; // Size of individual items in bytes
46+
ssize_t size = 0; // Total number of entries
47+
std::string
48+
format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
49+
ssize_t ndim = 0; // Number of dimensions
50+
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
51+
std::vector<ssize_t>
52+
strides; // Number of bytes between adjacent entries (for each per dimension)
53+
bool readonly = false; // flag to indicate if the underlying storage may be written to
5254

5355
buffer_info() = default;
5456

55-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
56-
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
57-
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
58-
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) {
5966
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) {
6067
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
6168
}
@@ -65,36 +72,55 @@ struct buffer_info {
6572
}
6673

6774
template <typename T>
68-
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
69-
: 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) { }
70-
71-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
72-
: 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) {}
7394

7495
template <typename T>
75-
buffer_info(T *ptr, ssize_t size, bool readonly=false)
76-
: 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) {}
7798

7899
template <typename T>
79-
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
80-
: 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) {}
81103

82104
explicit buffer_info(Py_buffer *view, bool ownview = true)
83-
: 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,
84110
{view->shape, view->shape + view->ndim},
85111
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
86112
* ignore this flag and return a view with NULL strides.
87113
* When strides are NULL, build them manually. */
88114
view->strides
89-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
90-
: 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),
91117
(view->readonly != 0)) {
92118
this->m_view = view;
93119
this->ownview = ownview;
94120
}
95121

96122
buffer_info(const buffer_info &) = delete;
97-
buffer_info& operator=(const buffer_info &) = delete;
123+
buffer_info &operator=(const buffer_info &) = delete;
98124

99125
buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); }
100126

@@ -113,35 +139,51 @@ struct buffer_info {
113139
}
114140

115141
~buffer_info() {
116-
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+
}
117146
}
118147

119148
Py_buffer *view() const { return m_view; }
120149
Py_buffer *&view() { return m_view; }
121-
private:
122-
struct private_ctr_tag { };
123150

124-
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
125-
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
126-
: 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) {}
127164

128165
Py_buffer *m_view = nullptr;
129166
bool ownview = false;
130167
};
131168

132169
PYBIND11_NAMESPACE_BEGIN(detail)
133170

134-
template <typename T, typename SFINAE = void> struct compare_buffer_info {
135-
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) {
136174
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
137175
}
138176
};
139177

140-
template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
141-
static bool compare(const buffer_info& b) {
142-
return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor<T>::value ||
143-
((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned<T>::value ? "L" : "l")) ||
144-
((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")));
145187
}
146188
};
147189

0 commit comments

Comments
 (0)