From 4a5eec240231a2edc9e21caa46c075233e18e9d6 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Fri, 16 May 2014 08:01:27 -0400
Subject: [PATCH] c_buffer_from_obj for bytes

---
 pyopencl/cffi_cl.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py
index 8d2510e6..58a2e014 100644
--- a/pyopencl/cffi_cl.py
+++ b/pyopencl/cffi_cl.py
@@ -453,7 +453,7 @@ def _c_buffer_from_obj(obj, writable=False):
                         obj.__array_interface__['data'][0]),
                     obj.nbytes,
                     None)
-        if isinstance(obj, np.generic):
+        elif isinstance(obj, np.generic):
             # numpy scalar
             #
             # * obj.__array_interface__ exists in CPython, but the address does
@@ -467,6 +467,10 @@ def _c_buffer_from_obj(obj, writable=False):
                         s_array.__array_interface__['data'][0]),
                     s_array.nbytes,
                     s_array)
+        elif isinstance(obj, bytes):
+            # There sould be better ways to pass arguments
+            p = _ffi.new('char[]', obj)
+            return (_ffi.cast('void *', p), len(obj), p)
         else:
             raise LogicError("", status_code.INVALID_VALUE,
                     "PyOpencl on PyPy only accepts numpy arrays "
-- 
GitLab