From 098f9aef7382f483128919c97a74c81359a7c911 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Mon, 18 Jul 2016 22:52:08 +0100 Subject: [PATCH] Replace 4096B format buffer with std::string --- include/pybind11/numpy.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 12073ba74..10eb89532 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -291,7 +291,7 @@ struct npy_format_descriptor::value> static const char* format() { if (!dtype_()) pybind11_fail("NumPy: unsupported buffer format!"); - return format_(); + return format_().c_str(); } static void register_dtype(std::initializer_list fields) { @@ -337,7 +337,7 @@ struct npy_format_descriptor::value> if (sizeof(T) > offset) oss << (sizeof(T) - offset) << 'x'; oss << '}'; - std::strncpy(format_(), oss.str().c_str(), 4096); + format_() = oss.str(); // Sanity check: verify that NumPy properly parses our buffer format string auto arr = array(buffer_info(nullptr, sizeof(T), format(), 1, { 0 }, { sizeof(T) })); @@ -348,7 +348,7 @@ struct npy_format_descriptor::value> private: static inline PyObject*& dtype_() { static PyObject *ptr = nullptr; return ptr; } - static inline char* format_() { static char s[4096]; return s; } + static inline std::string& format_() { static std::string s; return s; } }; // Extract name, offset and format descriptor for a struct field