Skip to content

Commit 53056b1

Browse files
committed
style: run clang-format
1 parent 8ee4eb3 commit 53056b1

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

+7511
-5490
lines changed

.pre-commit-config.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,3 @@ repos:
145145
rev: "v13.0.0"
146146
hooks:
147147
- id: clang-format
148-
149-
- repo: local
150-
hooks:
151-
- id: check-style
152-
name: Classic check-style
153-
language: system
154-
types:
155-
- c++
156-
entry: ./tools/check-style.sh

include/pybind11/attr.h

+137-84
Large diffs are not rendered by default.

include/pybind11/buffer_info.h

+80-38
Original file line numberDiff line numberDiff line change
@@ -38,58 +38,84 @@ PYBIND11_NAMESPACE_END(detail)
3838

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

5052
buffer_info() = default;
5153

52-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
53-
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
54-
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
55-
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
54+
buffer_info(void *ptr,
55+
ssize_t itemsize,
56+
const std::string &format,
57+
ssize_t ndim,
58+
detail::any_container<ssize_t> shape_in,
59+
detail::any_container<ssize_t> strides_in,
60+
bool readonly = false)
61+
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
62+
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
5663
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size())
5764
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
5865
for (size_t i = 0; i < (size_t) ndim; ++i)
5966
size *= shape[i];
6067
}
6168

6269
template <typename T>
63-
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
64-
: 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) { }
65-
66-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
67-
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { }
70+
buffer_info(T *ptr,
71+
detail::any_container<ssize_t> shape_in,
72+
detail::any_container<ssize_t> strides_in,
73+
bool readonly = false)
74+
: buffer_info(private_ctr_tag(),
75+
ptr,
76+
sizeof(T),
77+
format_descriptor<T>::format(),
78+
static_cast<ssize_t>(shape_in->size()),
79+
std::move(shape_in),
80+
std::move(strides_in),
81+
readonly) {}
82+
83+
buffer_info(void *ptr,
84+
ssize_t itemsize,
85+
const std::string &format,
86+
ssize_t size,
87+
bool readonly = false)
88+
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) {}
6889

6990
template <typename T>
70-
buffer_info(T *ptr, ssize_t size, bool readonly=false)
71-
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) { }
91+
buffer_info(T *ptr, ssize_t size, bool readonly = false)
92+
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) {}
7293

7394
template <typename T>
74-
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
75-
: buffer_info(const_cast<T*>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) { }
95+
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
96+
: buffer_info(
97+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
7698

7799
explicit buffer_info(Py_buffer *view, bool ownview = true)
78-
: buffer_info(view->buf, view->itemsize, view->format, view->ndim,
100+
: buffer_info(
101+
view->buf,
102+
view->itemsize,
103+
view->format,
104+
view->ndim,
79105
{view->shape, view->shape + view->ndim},
80106
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
81107
* ignore this flag and return a view with NULL strides.
82108
* When strides are NULL, build them manually. */
83109
view->strides
84-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
85-
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
110+
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
111+
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
86112
(view->readonly != 0)) {
87113
this->m_view = view;
88114
this->ownview = ownview;
89115
}
90116

91117
buffer_info(const buffer_info &) = delete;
92-
buffer_info& operator=(const buffer_info &) = delete;
118+
buffer_info &operator=(const buffer_info &) = delete;
93119

94120
buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); }
95121

@@ -108,35 +134,51 @@ struct buffer_info {
108134
}
109135

110136
~buffer_info() {
111-
if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; }
137+
if (m_view && ownview) {
138+
PyBuffer_Release(m_view);
139+
delete m_view;
140+
}
112141
}
113142

114143
Py_buffer *view() const { return m_view; }
115144
Py_buffer *&view() { return m_view; }
116-
private:
117-
struct private_ctr_tag { };
118145

119-
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
120-
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
121-
: buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { }
146+
private:
147+
struct private_ctr_tag {};
148+
149+
buffer_info(private_ctr_tag,
150+
void *ptr,
151+
ssize_t itemsize,
152+
const std::string &format,
153+
ssize_t ndim,
154+
detail::any_container<ssize_t> &&shape_in,
155+
detail::any_container<ssize_t> &&strides_in,
156+
bool readonly)
157+
: buffer_info(
158+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
122159

123160
Py_buffer *m_view = nullptr;
124161
bool ownview = false;
125162
};
126163

127164
PYBIND11_NAMESPACE_BEGIN(detail)
128165

129-
template <typename T, typename SFINAE = void> struct compare_buffer_info {
130-
static bool compare(const buffer_info& b) {
166+
template <typename T, typename SFINAE = void>
167+
struct compare_buffer_info {
168+
static bool compare(const buffer_info &b) {
131169
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
132170
}
133171
};
134172

135-
template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
136-
static bool compare(const buffer_info& b) {
137-
return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor<T>::value ||
138-
((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned<T>::value ? "L" : "l")) ||
139-
((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned<T>::value ? "N" : "n")));
173+
template <typename T>
174+
struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
175+
static bool compare(const buffer_info &b) {
176+
return (size_t) b.itemsize == sizeof(T)
177+
&& (b.format == format_descriptor<T>::value
178+
|| ((sizeof(T) == sizeof(long))
179+
&& b.format == (std::is_unsigned<T>::value ? "L" : "l"))
180+
|| ((sizeof(T) == sizeof(size_t))
181+
&& b.format == (std::is_unsigned<T>::value ? "N" : "n")));
140182
}
141183
};
142184

0 commit comments

Comments
 (0)