From b85bd3984614192c1ad1b9f7289765d614bee4de Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sat, 1 Feb 2014 21:30:51 -0600
Subject: [PATCH] Only ask for write buffers in create_image and create_buffer
 if USE_HOST_PTR and WRITE_ONLY or READ_WRITE is requested (reported by
 Antoine Martin)

---
 src/wrapper/wrap_cl.hpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index 38667949..cce59d66 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -1756,7 +1756,9 @@ namespace pyopencl
     if (py_hostbuf.ptr() != Py_None)
     {
       PYOPENCL_BUFFER_SIZE_T len;
-      if (flags & CL_MEM_USE_HOST_PTR)
+      if ((flags & CL_MEM_USE_HOST_PTR)
+          && ((flags & CL_MEM_READ_WRITE)
+            || (flags & CL_MEM_WRITE_ONLY)))
       {
         if (PyObject_AsWriteBuffer(py_hostbuf.ptr(), &buf, &len))
           throw py::error_already_set();
@@ -2236,7 +2238,9 @@ namespace pyopencl
 
     if (buffer.ptr() != Py_None)
     {
-      if (flags & CL_MEM_USE_HOST_PTR)
+      if ((flags & CL_MEM_USE_HOST_PTR)
+          && ((flags & CL_MEM_READ_WRITE)
+            || (flags & CL_MEM_WRITE_ONLY)))
       {
         if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
           throw py::error_already_set();
-- 
GitLab