redesigned format_descriptor<> and npy_format_descriptor<>
This somewhat heavyweight solution will avoid size_t/long long/long/int
mismatches on various platforms once and for all. The previous template
overloads could e.g. not handle size_t on Darwin.
One gotcha: the 'format_descriptor<T>::value()' syntax changed to just
'format_descriptor<T>::value'
diff --git a/docs/advanced.rst b/docs/advanced.rst
index e8ce71f..ec09534 100644
--- a/docs/advanced.rst
+++ b/docs/advanced.rst
@@ -825,12 +825,12 @@
py::class_<Matrix>(m, "Matrix")
.def_buffer([](Matrix &m) -> py::buffer_info {
return py::buffer_info(
- m.data(), /* Pointer to buffer */
- sizeof(float), /* Size of one scalar */
- py::format_descriptor<float>::value(), /* Python struct-style format descriptor */
- 2, /* Number of dimensions */
- { m.rows(), m.cols() }, /* Buffer dimensions */
- { sizeof(float) * m.rows(), /* Strides (in bytes) for each index */
+ m.data(), /* Pointer to buffer */
+ sizeof(float), /* Size of one scalar */
+ py::format_descriptor<float>::value, /* Python struct-style format descriptor */
+ 2, /* Number of dimensions */
+ { m.rows(), m.cols() }, /* Buffer dimensions */
+ { sizeof(float) * m.rows(), /* Strides (in bytes) for each index */
sizeof(float) }
);
});
@@ -867,7 +867,7 @@
py::buffer_info info = b.request();
/* Some sanity checks ... */
- if (info.format != py::format_descriptor<double>::value())
+ if (info.format != py::format_descriptor<double>::value)
throw std::runtime_error("Incompatible format: expected a double array!");
if (info.ndim != 2)
@@ -994,7 +994,7 @@
auto result = py::array(py::buffer_info(
nullptr, /* Pointer to data (nullptr -> ask NumPy to allocate!) */
sizeof(double), /* Size of one item */
- py::format_descriptor<double>::value(), /* Buffer format */
+ py::format_descriptor<double>::value, /* Buffer format */
buf1.ndim, /* How many dimensions? */
{ buf1.shape[0] }, /* Number of elements for each dimension */
{ sizeof(double) } /* Strides for each dimension */