3333#include < pybind11/cast.h>
3434#include < pybind11/pybind11.h>
3535#include < pybind11/stl.h>
36+ #include < pybind11/type_caster_pyobject_ptr.h>
3637
3738// Must NOT appear before at least one pybind11 include.
3839#include < datetime.h> // Python datetime builtin.
@@ -392,10 +393,23 @@ namespace internal {
392393
393394template <typename T>
394395static constexpr bool is_buffer_interface_compatible_type =
396+ detail::is_same_ignoring_cvref<T, PyObject*>::value ||
395397 std::is_arithmetic<T>::value ||
396398 std::is_same<T, std::complex <float >>::value ||
397399 std::is_same<T, std::complex <double >>::value;
398400
401+ template <typename T, typename SFINAE = void >
402+ struct format_descriptor_char1 : format_descriptor<T> {};
403+
404+ template <typename T>
405+ struct format_descriptor_char1 <
406+ T,
407+ detail::enable_if_t <detail::is_same_ignoring_cvref<T, PyObject*>::value>> {
408+ static constexpr const char c = ' O' ;
409+ static constexpr const char value[2 ] = {c, ' \0 ' };
410+ static std::string format () { return std::string (1 , c); }
411+ };
412+
399413template <typename T, typename SFINAE = void >
400414struct format_descriptor_char2 {
401415 static constexpr const char c = ' \0 ' ;
@@ -406,7 +420,7 @@ struct format_descriptor_char2<std::complex<T>> : format_descriptor<T> {};
406420
407421template <typename T>
408422inline bool buffer_view_matches_format_descriptor (const char * view_format) {
409- return view_format[0 ] == format_descriptor <T>::c ||
423+ return view_format[0 ] == format_descriptor_char1 <T>::c ||
410424 (view_format[0 ] == ' Z' &&
411425 view_format[1 ] == format_descriptor_char2<T>::c);
412426}
0 commit comments