diff --git a/doc/tools.rst b/doc/tools.rst index 243535142b21ef219391f7e9a552b846b58ec60c..c0565d2fbaf32fc0949f8958de111007e7030d91 100644 --- a/doc/tools.rst +++ b/doc/tools.rst @@ -54,6 +54,11 @@ not complicated:: Allocate a :class:`pyopencl.Buffer` of the given *size*. + .. versionchanged :: 2020.2 + + The allocator will succeed even for allocations of size zero, + returning *None*. + .. class:: ImmediateAllocator(queue, mem_flags=pyopencl.mem_flags.READ_WRITE) *mem_flags* takes its values from :class:`pyopencl.mem_flags` and corresponds @@ -68,6 +73,11 @@ not complicated:: Allocate a :class:`pyopencl.Buffer` of the given *size*. + .. versionchanged :: 2020.2 + + The allocator will succeed even for allocations of size zero, + returning *None*. + .. class:: MemoryPool(allocator[, leading_bits_in_bin_id]) A memory pool for OpenCL device memory. *allocator* must be an instance of diff --git a/src/wrap_mempool.cpp b/src/wrap_mempool.cpp index 8778c1bf665953c159b41ceaf8b7de516d2b78c9..dceb33dcab63129ddaac89602324d87b816d7315 100644 --- a/src/wrap_mempool.cpp +++ b/src/wrap_mempool.cpp @@ -104,6 +104,9 @@ namespace pointer_type allocate(size_type s) { + if (s == 0) + return nullptr; + return pyopencl::create_buffer(m_context->data(), m_flags, s, 0); } }; @@ -137,6 +140,9 @@ namespace pointer_type allocate(size_type s) { + if (s == 0) + return nullptr; + pointer_type ptr = pyopencl::create_buffer( m_context->data(), m_flags, s, 0);