Skip to content

Commit 168e21c

Browse files
committed
Manual curation of clang-format diffs involving source code comments.
Very labor-intensive and dull.
1 parent d8ec2ee commit 168e21c

19 files changed

+118
-72
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ IndentWidth: 4
1515
Language: Cpp
1616
SpaceAfterCStyleCast: true
1717
Standard: Cpp11
18+
StatementMacros: ['PyObject_HEAD']
1819
TabWidth: 4
1920
...

include/pybind11/buffer_info.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ 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 format_descriptor<T>::format()
47+
std::string format; // For homogeneous buffers, this should be set to
48+
// format_descriptor<T>::format()
4849
ssize_t ndim = 0; // Number of dimensions
4950
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+
std::vector<ssize_t> strides; // Number of bytes between adjacent entries
52+
// (for each per dimension)
5153
bool readonly = false; // flag to indicate if the underlying storage may be written to
5254

5355
buffer_info() = default;

include/pybind11/cast.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
996996
template <typename T, enable_if_t<!is_pyobject<T>::value, int>>
997997
object object_or_cast(T &&o) { return pybind11::cast(std::forward<T>(o)); }
998998

999-
struct override_unused {}; // Placeholder type for the unneeded (and dead code) static variable in the PYBIND11_OVERRIDE_OVERRIDE macro
999+
// Placeholder type for the unneeded (and dead code) static variable in the
1000+
// PYBIND11_OVERRIDE_OVERRIDE macro
1001+
struct override_unused {};
10001002
template <typename ret_type> using override_caster_t = conditional_t<
10011003
cast_is_temporary_value_reference<ret_type>::value, make_caster<ret_type>, override_unused>;
10021004

@@ -1463,7 +1465,8 @@ handle type::handle_of() {
14631465
}}
14641466

14651467
/// Lets you pass a type containing a `,` through a macro parameter without needing a separate
1466-
/// typedef, e.g.: `PYBIND11_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
1468+
/// typedef, e.g.:
1469+
/// `PYBIND11_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
14671470
#define PYBIND11_TYPE(...) __VA_ARGS__
14681471

14691472
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/chrono.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ template <typename type> class duration_caster {
3838
using rep = typename type::rep;
3939
using period = typename type::period;
4040

41-
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>; // signed 25 bits required by the standard.
41+
// signed 25 bits required by the standard.
42+
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>;
4243

4344
bool load(handle src, bool) {
4445
using namespace std::chrono;

include/pybind11/detail/common.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
# endif
4343
# endif
4444
#elif defined(_MSC_VER) && __cplusplus == 199711L
45-
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented)
46-
// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
45+
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
46+
// implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
47+
// or newer.
4748
# if _MSVC_LANG >= 201402L
4849
# define PYBIND11_CPP14
4950
# if _MSVC_LANG > 201402L && _MSC_VER >= 1910
@@ -722,8 +723,8 @@ template <typename T, typename... Ts>
722723
constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
723724
PYBIND11_NAMESPACE_END(constexpr_impl)
724725

725-
/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
726-
/// none match.
726+
/// Return the index of the first type in Ts which satisfies Predicate<T>.
727+
/// Returns sizeof...(Ts) if none match.
727728
template <template<typename> class Predicate, typename... Ts>
728729
constexpr int constexpr_first() { return constexpr_impl::first(0, Predicate<Ts>::value...); }
729730

@@ -872,7 +873,9 @@ PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
872873
PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
873874
PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
874875
PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
875-
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
876+
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or
877+
/// handle::call fail due to a type
878+
/// casting error
876879
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
877880

878881
[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
@@ -976,13 +979,14 @@ class any_container {
976979
template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
977980
any_container(It first, It last) : v(first, last) { }
978981

979-
// Implicit conversion constructor from any arbitrary container type with values convertible to T
982+
// Implicit conversion constructor from any arbitrary container type
983+
// with values convertible to T
980984
template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>::value>>
981985
// NOLINTNEXTLINE(google-explicit-constructor)
982986
any_container(const Container &c) : any_container(std::begin(c), std::end(c)) { }
983987

984-
// initializer_list's aren't deducible, so don't get matched by the above template; we need this
985-
// to explicitly allow implicit conversion from one:
988+
// initializer_list's aren't deducible, so don't get matched by the above template;
989+
// we need this to explicitly allow implicit conversion from one:
986990
template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
987991
any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) { }
988992

include/pybind11/detail/internals.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,22 @@ struct override_hash {
147147
/// Whenever binary incompatible changes are made to this structure,
148148
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
149149
struct internals {
150-
type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information
151-
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s)
150+
// std::type_index -> pybind11's type information
151+
type_map<type_info *> registered_types_cpp;
152+
// PyTypeObject* -> base type_info(s)
153+
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py;
152154
std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance*
153155
std::unordered_set<std::pair<const PyObject *, const char *>, override_hash> inactive_override_cache;
154156
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
155157
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
156158
std::forward_list<ExceptionTranslator> registered_exception_translators;
157-
std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across extensions
159+
std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across
160+
// extensions
158161
#if PYBIND11_INTERNALS_VERSION == 4
159162
std::vector<PyObject *> unused_loader_patient_stack_remove_at_v5;
160163
#endif
161-
std::forward_list<std::string> static_strings; // Stores the std::strings backing detail::c_str()
164+
std::forward_list<std::string> static_strings; // Stores the std::strings backing
165+
// detail::c_str()
162166
PyTypeObject *static_property_type;
163167
PyTypeObject *default_metaclass;
164168
PyObject *instance_base;

include/pybind11/detail/type_caster_base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ PYBIND11_NOINLINE void instance::allocate_layout() {
426426
space += t->holder_size_in_ptrs; // holder instance
427427
}
428428
size_t flags_at = space;
429-
space += size_in_ptrs(n_types); // status bytes (holder_constructed and instance_registered)
429+
space += size_in_ptrs(n_types); // status bytes (holder_constructed and
430+
// instance_registered)
430431

431432
// Allocate space for flags, values, and holders, and initialize it to 0 (flags and values,
432433
// in particular, need to be 0). Use Python's memory allocation functions: in Python 3.6

include/pybind11/numpy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ template <typename T, size_t N> struct array_info<T[N]> : array_info<std::array<
325325
template <typename T> using remove_all_extents_t = typename array_info<T>::type;
326326

327327
template <typename T> using is_pod_struct = all_of<
328-
std::is_standard_layout<T>, // since we're accessing directly in memory we need a standard layout type
328+
std::is_standard_layout<T>, // since we're accessing directly in memory
329+
// we need a standard layout type
329330
#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20150422 || __GLIBCXX__ == 20150426 || __GLIBCXX__ == 20150623 || __GLIBCXX__ == 20150626 || __GLIBCXX__ == 20160803)
330331
// libstdc++ < 5 (including versions 4.8.5, 4.9.3 and 4.9.4 which were released after 5)
331332
// don't implement is_trivially_copyable, so approximate it

include/pybind11/options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class options {
5151

5252
struct state {
5353
bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
54-
bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings.
54+
bool show_function_signatures = true; //< Include auto-generated function signatures
55+
// in docstrings.
5556
};
5657

5758
static state &global_state() {

include/pybind11/pybind11.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ class cpp_function : public function {
242242

243243
rec->nargs_pos = cast_in::args_pos >= 0
244244
? static_cast<std::uint16_t>(cast_in::args_pos)
245-
: sizeof...(Args) - cast_in::has_kwargs; // Will get reduced more if we have a kw_only
245+
: sizeof...(Args) - cast_in::has_kwargs; // Will get reduced more if
246+
// we have a kw_only
246247
rec->has_args = cast_in::args_pos >= 0;
247248
rec->has_kwargs = cast_in::has_kwargs;
248249

@@ -263,7 +264,8 @@ class cpp_function : public function {
263264
static_assert(!(has_kw_only_args && has_pos_only_args) || pos_only_pos < kw_only_pos, "py::pos_only must come before py::kw_only");
264265
}
265266

266-
/* Generate a readable signature describing the function's arguments and return value types */
267+
/* Generate a readable signature describing the function's arguments and return
268+
value types */
267269
static constexpr auto signature = const_name("(") + cast_in::arg_names + const_name(") -> ") + cast_out::name;
268270
PYBIND11_DESCR_CONSTEXPR auto types = decltype(signature)::types();
269271

@@ -400,7 +402,8 @@ class cpp_function : public function {
400402
handle th((PyObject *) tinfo->type);
401403
signature +=
402404
th.attr("__module__").cast<std::string>() + "." +
403-
th.attr("__qualname__").cast<std::string>(); // Python 3.3+, but we backport it to earlier versions
405+
// Python 3.3+, but we backport it to earlier versions
406+
th.attr("__qualname__").cast<std::string>();
404407
} else if (rec->is_new_style_constructor && arg_index == 0) {
405408
// A new-style `__init__` takes `self` as `value_and_holder`.
406409
// Rewrite it to the proper class type.
@@ -639,7 +642,8 @@ class cpp_function : public function {
639642
const function_record *overloads = (function_record *) PyCapsule_GetPointer(self, nullptr),
640643
*it = overloads;
641644

642-
/* Need to know how many arguments + keyword arguments there are to pick the right overload */
645+
/* Need to know how many arguments + keyword arguments there are to pick the right
646+
overload */
643647
const auto n_args_in = (size_t) PyTuple_GET_SIZE(args_in);
644648

645649
handle parent = n_args_in > 0 ? PyTuple_GET_ITEM(args_in, 0) : nullptr,
@@ -715,7 +719,8 @@ class cpp_function : public function {
715719

716720
function_call call(func, parent);
717721

718-
size_t args_to_copy = (std::min)(pos_args, n_args_in); // Protect std::min with parentheses
722+
// Protect std::min with parentheses
723+
size_t args_to_copy = (std::min)(pos_args, n_args_in);
719724
size_t args_copied = 0;
720725

721726
// 0. Inject new-style `self` argument
@@ -956,7 +961,8 @@ class cpp_function : public function {
956961
- catch the exception and call PyErr_SetString or PyErr_SetObject
957962
to set a standard (or custom) Python exception, or
958963
- do nothing and let the exception fall through to the next translator, or
959-
- delegate translation to the next translator by throwing a new type of exception. */
964+
- delegate translation to the next translator by throwing a new type of exception.
965+
*/
960966

961967
auto &local_exception_translators = get_local_internals().registered_exception_translators;
962968
if (detail::apply_exception_translators(local_exception_translators)) {
@@ -1197,7 +1203,8 @@ class module_ : public object {
11971203
static module_ create_extension_module(const char *name, const char *doc, module_def *def) {
11981204
#if PY_MAJOR_VERSION >= 3
11991205
// module_def is PyModuleDef
1200-
def = new (def) PyModuleDef { // Placement new (not an allocation).
1206+
// Placement new (not an allocation).
1207+
def = new (def) PyModuleDef {
12011208
/* m_base */ PyModuleDef_HEAD_INIT,
12021209
/* m_name */ name,
12031210
/* m_doc */ options::show_user_defined_docstrings() ? doc : nullptr,
@@ -1456,7 +1463,8 @@ class class_ : public detail::generic_type {
14561463
none_of<is_pyobject<Extra>...>::value || // no base class arguments, or:
14571464
( constexpr_sum(is_pyobject<Extra>::value...) == 1 && // Exactly one base
14581465
constexpr_sum(is_base<options>::value...) == 0 && // no template option bases
1459-
none_of<std::is_same<multiple_inheritance, Extra>...>::value), // no multiple_inheritance attr
1466+
// no multiple_inheritance attr
1467+
none_of<std::is_same<multiple_inheritance, Extra>...>::value),
14601468
"Error: multiple inheritance bases must be specified via class_ template options");
14611469

14621470
type_record record;

include/pybind11/pytypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class object_api : public pyobject_tag {
161161
/// Return the object's current reference count
162162
int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
163163

164-
// TODO PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
164+
// TODO PYBIND11_DEPRECATED(
165+
// "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
165166
handle get_type() const;
166167

167168
private:

include/pybind11/stl_bind.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ struct is_comparable<
4444
container_traits<T>::is_comparable>>
4545
: std::true_type { };
4646

47-
/* For a vector/map data structure, recursively check the value type (which is std::pair for maps) */
47+
/* For a vector/map data structure, recursively check the value type
48+
(which is std::pair for maps) */
4849
template <typename T>
4950
struct is_comparable<T, enable_if_t<container_traits<T>::is_vector>> {
5051
static constexpr const bool value =
@@ -384,7 +385,8 @@ template <typename Vector, typename Class_> auto vector_if_insertion_operator(Cl
384385
}
385386

386387
// Provide the buffer interface for vectors if we have data() and we have a format for it
387-
// GCC seems to have "void std::vector<bool>::data()" - doing SFINAE on the existence of data() is insufficient, we need to check it returns an appropriate pointer
388+
// GCC seems to have "void std::vector<bool>::data()" - doing SFINAE on the existence of data()
389+
// is insufficient, we need to check it returns an appropriate pointer
388390
template <typename Vector, typename = void>
389391
struct vector_has_data_and_format : std::false_type {};
390392
template <typename Vector>
@@ -408,7 +410,8 @@ void vector_buffer_impl(Class_& cl, std::true_type) {
408410

409411
static_assert(vector_has_data_and_format<Vector>::value, "There is not an appropriate format descriptor for this vector");
410412

411-
// numpy.h declares this for arbitrary types, but it may raise an exception and crash hard at runtime if PYBIND11_NUMPY_DTYPE hasn't been called, so check here
413+
// numpy.h declares this for arbitrary types, but it may raise an exception and crash hard
414+
// at runtime if PYBIND11_NUMPY_DTYPE hasn't been called, so check here
412415
format_descriptor<T>::format();
413416

414417
cl.def_buffer([](Vector& v) -> buffer_info {

tests/constructor_stats.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ inspection/testing in python) by using the functions with `print_` replaced with
7272

7373
class ConstructorStats {
7474
protected:
75-
std::unordered_map<void*, int> _instances; // Need a map rather than set because members can shared address with parents
76-
std::list<std::string> _values; // Used to track values (e.g. of value constructors)
75+
std::unordered_map<void*, int> _instances; // Need a map rather than set because members can
76+
// shared address with parents
77+
std::list<std::string> _values; // Used to track values
78+
// (e.g. of value constructors)
7779
public:
7880
int default_constructions = 0;
7981
int copy_constructions = 0;

tests/test_class.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <utility>
2323

2424
#if defined(_MSC_VER)
25-
# pragma warning(disable: 4324) // warning C4324: structure was padded due to alignment specifier
25+
# pragma warning(disable: 4324)
26+
// warning C4324: structure was padded due to alignment specifier
2627
#endif
2728

2829
// test_brace_initialization
@@ -534,22 +535,24 @@ CHECK_HOLDER(6, shared); CHECK_HOLDER(7, shared); CHECK_HOLDER(8, shared);
534535
#define CHECK_BROKEN(N) static_assert(std::is_same<typename Breaks##N::type, BreaksBase<-(N)>>::value, \
535536
"Breaks1 has wrong type!");
536537

537-
//// Two holder classes:
538-
//typedef py::class_<BreaksBase<-1>, std::unique_ptr<BreaksBase<-1>>, std::unique_ptr<BreaksBase<-1>>> Breaks1;
539-
//CHECK_BROKEN(1);
540-
//// Two aliases:
541-
//typedef py::class_<BreaksBase<-2>, BreaksTramp<-2>, BreaksTramp<-2>> Breaks2;
542-
//CHECK_BROKEN(2);
543-
//// Holder + 2 aliases
544-
//typedef py::class_<BreaksBase<-3>, std::unique_ptr<BreaksBase<-3>>, BreaksTramp<-3>, BreaksTramp<-3>> Breaks3;
545-
//CHECK_BROKEN(3);
546-
//// Alias + 2 holders
547-
//typedef py::class_<BreaksBase<-4>, std::unique_ptr<BreaksBase<-4>>, BreaksTramp<-4>, std::shared_ptr<BreaksBase<-4>>> Breaks4;
548-
//CHECK_BROKEN(4);
549-
//// Invalid option (not a subclass or holder)
550-
//typedef py::class_<BreaksBase<-5>, BreaksTramp<-4>> Breaks5;
551-
//CHECK_BROKEN(5);
552-
//// Invalid option: multiple inheritance not supported:
553-
//template <> struct BreaksBase<-8> : BreaksBase<-6>, BreaksBase<-7> {};
554-
//typedef py::class_<BreaksBase<-8>, BreaksBase<-6>, BreaksBase<-7>> Breaks8;
555-
//CHECK_BROKEN(8);
538+
#ifdef PYBIND11_NEVER_DEFINED_EVER
539+
// Two holder classes:
540+
typedef py::class_<BreaksBase<-1>, std::unique_ptr<BreaksBase<-1>>, std::unique_ptr<BreaksBase<-1>>> Breaks1;
541+
CHECK_BROKEN(1);
542+
// Two aliases:
543+
typedef py::class_<BreaksBase<-2>, BreaksTramp<-2>, BreaksTramp<-2>> Breaks2;
544+
CHECK_BROKEN(2);
545+
// Holder + 2 aliases
546+
typedef py::class_<BreaksBase<-3>, std::unique_ptr<BreaksBase<-3>>, BreaksTramp<-3>, BreaksTramp<-3>> Breaks3;
547+
CHECK_BROKEN(3);
548+
// Alias + 2 holders
549+
typedef py::class_<BreaksBase<-4>, std::unique_ptr<BreaksBase<-4>>, BreaksTramp<-4>, std::shared_ptr<BreaksBase<-4>>> Breaks4;
550+
CHECK_BROKEN(4);
551+
// Invalid option (not a subclass or holder)
552+
typedef py::class_<BreaksBase<-5>, BreaksTramp<-4>> Breaks5;
553+
CHECK_BROKEN(5);
554+
// Invalid option: multiple inheritance not supported:
555+
template <> struct BreaksBase<-8> : BreaksBase<-6>, BreaksBase<-7> {};
556+
typedef py::class_<BreaksBase<-8>, BreaksBase<-6>, BreaksBase<-7>> Breaks8;
557+
CHECK_BROKEN(8);
558+
#endif

0 commit comments

Comments
 (0)