@@ -23,6 +23,13 @@ cdef object PyArray_Empty(int a, np.npy_intp *b, np.dtype c, int d):
2323 Py_INCREF(c)
2424 return _PyArray_Empty(a, b, c, d)
2525
26+ cdef bytes _s(s):
27+ if isinstance (s, unicode ):
28+ return (< unicode > s).encode(' ascii' )
29+ if isinstance (s, bytes):
30+ return s
31+ raise TypeError (" Expected a string" )
32+
2633cdef object call_compiler_fn = None
2734
2835cdef void * call_compiler_python(const char * src, size_t sz,
@@ -107,7 +114,7 @@ def cl_wrap_ctx(size_t ptr):
107114 if cl_make_ctx == NULL :
108115 raise RuntimeError , " cl_make_ctx extension is absent"
109116 res = GpuContext.__new__ (GpuContext)
110- res.ops = get_ops(' opencl' )
117+ res.ops = get_ops(b " opencl" )
111118 res.ctx = cl_make_ctx(< void * > ptr)
112119 if res.ctx == NULL :
113120 raise RuntimeError , " cl_make_ctx call failed"
@@ -132,7 +139,7 @@ def cuda_wrap_ctx(size_t ptr, bint own):
132139 if cuda_make_ctx == NULL :
133140 raise RuntimeError , " cuda_make_ctx extension is absent"
134141 res = GpuContext.__new__ (GpuContext)
135- res.ops = get_ops(' cuda' )
142+ res.ops = get_ops(b " cuda" )
136143 flags = 0
137144 if not own:
138145 flags |= GPUARRAY_CUDA_CTX_NOFREE
@@ -261,9 +268,11 @@ def dtype_to_ctype(dtype):
261268 """
262269 cdef int typecode = dtype_to_typecode(dtype)
263270 cdef const gpuarray_type * t = gpuarray_get_type(typecode)
271+ cdef bytes res
264272 if t.cluda_name == NULL :
265273 raise ValueError , " No mapping for %s " % (dtype,)
266- return t.cluda_name
274+ res = t.cluda_name
275+ return res.decode(' ascii' )
267276
268277cdef ga_order to_ga_order(ord ) except < ga_order> - 2 :
269278 if ord == " C" or ord == " c" :
@@ -498,7 +507,7 @@ cdef int ctx_property(GpuContext c, int prop_id, void *res) except -1:
498507 if err != GA_NO_ERROR:
499508 raise get_exc(err), Gpu_error(c.ops, c.ctx, err)
500509
501- cdef const gpuarray_buffer_ops * get_ops(kind) except NULL :
510+ cdef const gpuarray_buffer_ops * get_ops(bytes kind) except NULL :
502511 cdef const gpuarray_buffer_ops * res
503512 res = gpuarray_get_ops(kind)
504513 if res == NULL :
@@ -972,7 +981,7 @@ cdef class GpuContext:
972981 def __cinit__ (self , kind , devno ):
973982 cdef int err = GA_NO_ERROR
974983 cdef void * ctx
975- self .ops = get_ops(kind)
984+ self .ops = get_ops(_s( kind) )
976985 self .ctx = self .ops.buffer_init(devno, 0 , & err)
977986 if (err != GA_NO_ERROR):
978987 if err == GA_VALUE_ERROR:
@@ -1843,10 +1852,8 @@ cdef class GpuKernel:
18431852 cdef const gpuarray_buffer_ops * ops
18441853 cdef int flags = 0
18451854
1846- if not isinstance (source, (str , unicode )):
1847- raise TypeError , " Expected a string for the kernel source"
1848- if not isinstance (name, (str , unicode )):
1849- raise TypeError , " Expected a string for the kernel name"
1855+ source = _s(source)
1856+ name = _s(name)
18501857
18511858 self .context = ensure_context(context)
18521859
0 commit comments