[Bugfix] Fix errant const methods (#3194)

* Fix errant const methods

* Remove NOLINT since clang-tidy is pretty conservative

* Missed one

* Fix a few more errors

* Add reviewer suggested comments

* Run clang-format
This commit is contained in:
Aaron Gokaslan 2021-08-14 12:25:54 -04:00 committed by GitHub
parent 1bcd94c481
commit 617cb653ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -522,7 +522,7 @@ struct instance {
void allocate_layout();
/// Destroys/deallocates all of the above
void deallocate_layout() const;
void deallocate_layout();
/// Returns the value_and_holder wrapper for the given type (or the first, if `find_type`
/// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if

View File

@ -241,7 +241,8 @@ struct value_and_holder {
? inst->simple_holder_constructed
: (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
}
void set_holder_constructed(bool v = true) const {
// NOLINTNEXTLINE(readability-make-member-function-const)
void set_holder_constructed(bool v = true) {
if (inst->simple_layout)
inst->simple_holder_constructed = v;
else if (v)
@ -254,7 +255,8 @@ struct value_and_holder {
? inst->simple_instance_registered
: ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
}
void set_instance_registered(bool v = true) const {
// NOLINTNEXTLINE(readability-make-member-function-const)
void set_instance_registered(bool v = true) {
if (inst->simple_layout)
inst->simple_instance_registered = v;
else if (v)
@ -397,7 +399,8 @@ PYBIND11_NOINLINE void instance::allocate_layout() {
owned = true;
}
PYBIND11_NOINLINE void instance::deallocate_layout() const {
// NOLINTNEXTLINE(readability-make-member-function-const)
PYBIND11_NOINLINE void instance::deallocate_layout() {
if (!simple_layout)
PyMem_Free(nonsimple.values_and_holders);
}

View File

@ -1393,7 +1393,7 @@ public:
bool empty() const { return size() == 0; }
detail::dict_iterator begin() const { return {*this, 0}; }
detail::dict_iterator end() const { return {}; }
void clear() const { PyDict_Clear(ptr()); }
void clear() /* py-non-const */ { PyDict_Clear(ptr()); }
template <typename T> bool contains(T &&key) const {
return PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr()) == 1;
}
@ -1435,10 +1435,10 @@ public:
detail::item_accessor operator[](handle h) const { return object::operator[](h); }
detail::list_iterator begin() const { return {*this, 0}; }
detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
template <typename T> void append(T &&val) const {
template <typename T> void append(T &&val) /* py-non-const */ {
PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
}
template <typename T> void insert(size_t index, T &&val) const {
template <typename T> void insert(size_t index, T &&val) /* py-non-const */ {
PyList_Insert(m_ptr, static_cast<ssize_t>(index),
detail::object_or_cast(std::forward<T>(val)).ptr());
}
@ -1455,10 +1455,10 @@ public:
}
size_t size() const { return (size_t) PySet_Size(m_ptr); }
bool empty() const { return size() == 0; }
template <typename T> bool add(T &&val) const {
template <typename T> bool add(T &&val) /* py-non-const */ {
return PySet_Add(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 0;
}
void clear() const { PySet_Clear(m_ptr); }
void clear() /* py-non-const */ { PySet_Clear(m_ptr); }
template <typename T> bool contains(T &&val) const {
return PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 1;
}