From bce254e768d9e461f2bd5b4012ac8a504ad21c16 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Sat, 17 May 2014 15:16:47 -0400
Subject: [PATCH] workaround for unhashable pypy dtype

---
 pyopencl/tools.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/pyopencl/tools.py b/pyopencl/tools.py
index c2842f60..ea0d66db 100644
--- a/pyopencl/tools.py
+++ b/pyopencl/tools.py
@@ -37,7 +37,9 @@ import re
 
 from pyopencl.compyte.dtypes import (  # noqa
         get_or_register_dtype, TypeNameNotKnown,
-        register_dtype, dtype_to_ctype)
+        register_dtype, dtype_to_ctype,
+        dtype_hashable as _dtype_hashable,
+        dtype_to_key as _dtype_to_key)
 
 
 def _register_types():
@@ -507,8 +509,15 @@ class _CDeclList:
 
         return result
 
+if _dtype_hashable:
+    _memoize_match_dtype_to_c_struct = memoize
+else:
+    import json as _json
+    _memoize_match_dtype_to_c_struct = memoize(
+        key=lambda device, name, dtype, context=None:
+        (device, name, _dtype_to_key(dtype), context))
 
-@memoize
+@_memoize_match_dtype_to_c_struct
 def match_dtype_to_c_struct(device, name, dtype, context=None):
     """Return a tuple `(dtype, c_decl)` such that the C struct declaration
     in `c_decl` and the structure :class:`numpy.dtype` instance `dtype`
@@ -656,8 +665,14 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
 
     return dtype, c_decl
 
+if _dtype_hashable:
+    _memoize_dtype_to_c_struct = memoize
+else:
+    import json as _json
+    _memoize_dtype_to_c_struct = memoize(
+        key=lambda device, dtype: (device, _dtype_to_key(dtype)))
 
-@memoize
+@_memoize_dtype_to_c_struct
 def dtype_to_c_struct(device, dtype):
     matched_dtype, c_decl = match_dtype_to_c_struct(
             device, dtype_to_ctype(dtype), dtype)
-- 
GitLab