From 4c5d0392b845baecdb7a7e2a68900d212d56163b Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Mon, 23 Jun 2014 09:33:49 +0800
Subject: [PATCH] disable get_host_array for MemoryObject without USE_HOST_PTR
 since the returned array may not be valid

---
 src/wrapper/wrap_cl.hpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index af524fd9..95ebc9b0 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -4236,6 +4236,13 @@ namespace pyopencl
     PyArray_Descr *tp_descr;
     if (PyArray_DescrConverter(dtype.ptr(), &tp_descr) != NPY_SUCCEED)
       throw py::error_already_set();
+    cl_mem_flags mem_flags;
+    PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
+            (mem_obj.data(), CL_MEM_FLAGS, sizeof(mem_flags), &mem_flags, 0));
+    if (!(mem_flags & CL_MEM_USE_HOST_PTR))
+      throw pyopencl::error("MemoryObject.get_host_array", CL_INVALID_VALUE,
+                            "Only MemoryObject with USE_HOST_PTR "
+                            "is supported.");
 
     py::extract<npy_intp> shape_as_int(shape);
     std::vector<npy_intp> dims;
-- 
GitLab