Skip to content

Commit

Permalink
Change item_type_is_equivalent_to<>() from static function to mem…
Browse files Browse the repository at this point in the history
…ber function, as suggested by @lalaland
  • Loading branch information
rwgk committed May 20, 2023
1 parent a4d61b4 commit ef34d29
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/buffer_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ struct buffer_info {
// on some platforms, but `int` and `unsigned` will never be equivalent.
// For the ground truth, please inspect `detail::compare_buffer_info<>`.
template <typename T>
static bool item_type_is_equivalent_to(const buffer_info &b) {
return detail::compare_buffer_info<T>::compare(b);
bool item_type_is_equivalent_to() const {
return detail::compare_buffer_info<T>::compare(*this);
}

private:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ TEST_SUBMODULE(buffers, m) {
// https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
static auto *format_table = new std::map<std::string, std::string>;
static auto *equiv_table
= new std::map<std::string, bool (*)(const py::buffer_info &)>;
= new std::map<std::string, bool (py::buffer_info::*)() const>;
if (format_table->empty()) {
#define PYBIND11_ASSIGN_HELPER(...) \
(*format_table)[#__VA_ARGS__] = py::format_descriptor<__VA_ARGS__>::format(); \
(*equiv_table)[#__VA_ARGS__] = py::buffer_info::item_type_is_equivalent_to<__VA_ARGS__>;
(*equiv_table)[#__VA_ARGS__] = &py::buffer_info::item_type_is_equivalent_to<__VA_ARGS__>;
PYBIND11_ASSIGN_HELPER(PyObject *)
PYBIND11_ASSIGN_HELPER(bool)
PYBIND11_ASSIGN_HELPER(std::int8_t)
Expand All @@ -44,8 +44,8 @@ TEST_SUBMODULE(buffers, m) {
PYBIND11_ASSIGN_HELPER(std::complex<long double>)
#undef PYBIND11_ASSIGN_HELPER
}
return std::pair<std::string, bool>((*format_table)[cpp_name],
(*equiv_table)[cpp_name](buffer.request()));
return std::pair<std::string, bool>(
(*format_table)[cpp_name], (buffer.request().*((*equiv_table)[cpp_name]))());
});

// test_from_python / test_to_python:
Expand Down

0 comments on commit ef34d29

Please sign in to comment.