From 51a4b3ab6d815869883531612200630631184212 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Thu, 19 Jun 2014 00:44:33 +0800 Subject: [PATCH] add one 0 to the end of pyopencl_buf --- src/c_wrapper/utils.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/c_wrapper/utils.h b/src/c_wrapper/utils.h index 512b5f83..a851578c 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))); } }; -- GitLab