@@ -319,6 +319,22 @@ py::list test_dtype_methods() {
319
319
return list;
320
320
}
321
321
322
+ struct CompareStruct {
323
+ bool x;
324
+ uint32_t y;
325
+ float z;
326
+ };
327
+
328
+ py::list test_compare_buffer_info () {
329
+ py::list list;
330
+ list.append (py::bool_ (py::detail::compare_buffer_info<float >::compare (py::buffer_info (nullptr , sizeof (float ), " f" , 1 ))));
331
+ list.append (py::bool_ (py::detail::compare_buffer_info<unsigned >::compare (py::buffer_info (nullptr , sizeof (int ), " I" , 1 ))));
332
+ list.append (py::bool_ (py::detail::compare_buffer_info<long >::compare (py::buffer_info (nullptr , sizeof (long ), " l" , 1 ))));
333
+ list.append (py::bool_ (py::detail::compare_buffer_info<long >::compare (py::buffer_info (nullptr , sizeof (long ), sizeof (long ) == sizeof (int ) ? " i" : " q" , 1 ))));
334
+ list.append (py::bool_ (py::detail::compare_buffer_info<CompareStruct>::compare (py::buffer_info (nullptr , sizeof (CompareStruct), " T{?:x:3xI:y:f:z:}" , 1 ))));
335
+ return list;
336
+ }
337
+
322
338
test_initializer numpy_dtypes ([](py::module &m) {
323
339
try {
324
340
py::module::import (" numpy" );
@@ -337,6 +353,7 @@ test_initializer numpy_dtypes([](py::module &m) {
337
353
PYBIND11_NUMPY_DTYPE (StringStruct, a, b);
338
354
PYBIND11_NUMPY_DTYPE (EnumStruct, e1 , e2 );
339
355
PYBIND11_NUMPY_DTYPE (TrailingPaddingStruct, a, b);
356
+ PYBIND11_NUMPY_DTYPE (CompareStruct, x, y, z);
340
357
341
358
// ... or after
342
359
py::class_<PackedStruct>(m, " PackedStruct" );
@@ -366,6 +383,7 @@ test_initializer numpy_dtypes([](py::module &m) {
366
383
m.def (" test_array_ctors" , &test_array_ctors);
367
384
m.def (" test_dtype_ctors" , &test_dtype_ctors);
368
385
m.def (" test_dtype_methods" , &test_dtype_methods);
386
+ m.def (" compare_buffer_info" , &test_compare_buffer_info);
369
387
m.def (" trailing_padding_dtype" , &trailing_padding_dtype);
370
388
m.def (" buffer_to_dtype" , &buffer_to_dtype);
371
389
m.def (" f_simple" , [](SimpleStruct s) { return s.uint_ * 10 ; });
0 commit comments