diff --git a/pyopencl/array.py b/pyopencl/array.py index bcc0770fa4a1446cb8a7e6c481f4ffc2ffe55f83..b25ffc5766d8ec31a88e1e5a37fbbead0f0ad2e0 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -483,23 +483,22 @@ class Array(object): self.allocator = allocator if data is None: - if alloc_nbytes <= 0: - if alloc_nbytes == 0: - # Work around CL not allowing zero-sized buffers. - alloc_nbytes = 1 + if alloc_nbytes < 0: + raise ValueError("cannot allocate CL buffer with " + "negative size") - else: - raise ValueError("cannot allocate CL buffer with " - "negative size") - - if allocator is None: - if context is None and queue is not None: - context = queue.context + elif alloc_nbytes == 0: + self.base_data = None - self.base_data = cl.Buffer( - context, cl.mem_flags.READ_WRITE, alloc_nbytes) else: - self.base_data = self.allocator(alloc_nbytes) + if allocator is None: + if context is None and queue is not None: + context = queue.context + + self.base_data = cl.Buffer( + context, cl.mem_flags.READ_WRITE, alloc_nbytes) + else: + self.base_data = self.allocator(alloc_nbytes) else: self.base_data = data