From 40cfe7d749d8a05e28e70eee0ab98202de7a755a Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sun, 3 Jul 2011 23:29:51 -0400
Subject: [PATCH] Fix some more Py3 hash-vs-encoding bugs in the caching code.

---
 pyopencl/cache.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/pyopencl/cache.py b/pyopencl/cache.py
index a84413d1..bf63ae6f 100644
--- a/pyopencl/cache.py
+++ b/pyopencl/cache.py
@@ -138,11 +138,13 @@ def get_dependencies(src, include_path):
                     except IOError:
                         continue
 
-                    checksum = new_hash()
-                    included_src = src_file.read()
-                    checksum.update(included_src)
-                    src_file.close()
+                    try:
+                        included_src = src_file.read()
+                    finally:
+                        src_file.close()
 
+                    checksum = new_hash()
+                    checksum.update(included_src.encode("utf8"))
                     _inner(included_src)
 
                     result[included_file_name] = (
@@ -167,8 +169,11 @@ def get_dependencies(src, include_path):
 def get_file_md5sum(fname):
     checksum = new_hash()
     inf = open(fname)
-    checksum.update(inf.read())
-    inf.close()
+    try:
+        contents = inf.read()
+    finally:
+        inf.close()
+    checksum.update(contents.encode("utf8"))
     return checksum.hexdigest()
 
 
-- 
GitLab