diff --git a/src/c_wrapper/utils.h b/src/c_wrapper/utils.h index 512b5f83306009836391c5e82df94de70cb9cef1..a851578cdb16f6acc80e1c53763ef319756aa306 100644 --- a/src/c_wrapper/utils.h +++ b/src/c_wrapper/utils.h @@ -240,6 +240,7 @@ class ConstBuffer : public ArgBuffer { private: T m_intern_buf[n]; ConstBuffer(ConstBuffer&&) = delete; + ConstBuffer() = delete; public: ConstBuffer(const T *buf, size_t l) : ArgBuffer(buf, n) @@ -351,11 +352,14 @@ class pyopencl_buf : public std::unique_ptr > { size_t m_len; public: constexpr static size_t ele_size = sizeof(T); - pyopencl_buf(size_t len=1) : - std::unique_ptr >((T*)(len ? malloc(sizeof(T) * len) : - nullptr)), - m_len(len) + PYOPENCL_INLINE + pyopencl_buf(size_t len=1) + : std::unique_ptr >((T*)(len ? malloc(sizeof(T) * (len + 1)) : + nullptr)), m_len(len) { + if (len) { + memset((void*)this->get(), 0, (len + 1) * sizeof(T)); + } } PYOPENCL_INLINE size_t len() const @@ -378,7 +382,8 @@ public: if (len == m_len) return; m_len = len; - this->reset((T*)realloc((void*)this->release(), len * sizeof(T))); + this->reset((T*)realloc((void*)this->release(), + (len + 1) * sizeof(T))); } };