Skip to content

Commit 2bf606c

Browse files
rwgkcopybara-github
authored andcommitted
Make use of new py::buffer_info::item_type_is_equivalent_to<T>()
The new member function was added with pybind/pybind11#4674 PiperOrigin-RevId: 534952040
1 parent 7d17c90 commit 2bf606c

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

pybind11_abseil/absl_casters.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ template <>
386386
struct type_caster<absl::CivilYear>
387387
: public absl_civil_date_caster<absl::CivilYear> {};
388388

389-
// Using internal namespace to avoid name collisons in case this code is
390-
// accepted upsteam (pybind11).
391389
namespace internal {
392390

393391
template <typename T>
@@ -397,33 +395,6 @@ static constexpr bool is_buffer_interface_compatible_type =
397395
std::is_same<T, std::complex<float>>::value ||
398396
std::is_same<T, std::complex<double>>::value;
399397

400-
template <typename T, typename SFINAE = void>
401-
struct format_descriptor_char1 : format_descriptor<T> {};
402-
403-
template <typename T>
404-
struct format_descriptor_char1<
405-
T,
406-
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject*>::value>> {
407-
static constexpr const char c = 'O';
408-
static constexpr const char value[2] = {c, '\0'};
409-
static std::string format() { return std::string(1, c); }
410-
};
411-
412-
template <typename T, typename SFINAE = void>
413-
struct format_descriptor_char2 {
414-
static constexpr const char c = '\0';
415-
};
416-
417-
template <typename T>
418-
struct format_descriptor_char2<std::complex<T>> : format_descriptor<T> {};
419-
420-
template <typename T>
421-
inline bool buffer_view_matches_format_descriptor(const char* view_format) {
422-
return view_format[0] == format_descriptor_char1<T>::c ||
423-
(view_format[0] == 'Z' &&
424-
view_format[1] == format_descriptor_char2<T>::c);
425-
}
426-
427398
} // namespace internal
428399

429400
// Returns {true, a span referencing the data contained by src} without copying
@@ -438,7 +409,7 @@ std::tuple<bool, absl::Span<T>> LoadSpanFromBuffer(handle src) {
438409
if (PyObject_GetBuffer(src.ptr(), &view, flags) == 0) {
439410
auto cleanup = absl::MakeCleanup([&view] { PyBuffer_Release(&view); });
440411
if (view.ndim == 1 && view.strides[0] == sizeof(T) &&
441-
internal::buffer_view_matches_format_descriptor<T>(view.format)) {
412+
buffer_info(&view, /*ownview=*/false).item_type_is_equivalent_to<T>()) {
442413
return {true, absl::MakeSpan(static_cast<T*>(view.buf), view.shape[0])};
443414
}
444415
} else {

0 commit comments

Comments
 (0)