[pypy-commit] pypy py3.5: fix an issue in ctypes

arigo pypy.commits at gmail.com
Wed Mar 8 09:39:58 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r90593:4ceaad7f1e7d
Date: 2017-03-08 15:39 +0100
http://bitbucket.org/pypy/pypy/changeset/4ceaad7f1e7d/

Log:	fix an issue in ctypes

diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -94,14 +94,21 @@
         # array accepts very strange parameters as part of structure
         # or function argument...
         from ctypes import c_char, c_wchar
-        if issubclass(self._type_, (c_char, c_wchar)):
-             # XXX: this should maybe be stricer for py3 (c_char disallowing str?)
-            if isinstance(value, (bytes, str)):
+        if issubclass(self._type_, c_char):
+            if isinstance(value, bytes):
                 if len(value) > self._length_:
                     raise ValueError("Invalid length")
                 value = self(*value)
             elif not isinstance(value, self):
-                raise TypeError("expected string, %s found"
+                raise TypeError("expected bytes, %s found"
+                                % (value.__class__.__name__,))
+        elif issubclass(self._type_, c_wchar):
+            if isinstance(value, str):
+                if len(value) > self._length_:
+                    raise ValueError("Invalid length")
+                value = self(*value)
+            elif not isinstance(value, self):
+                raise TypeError("expected unicode string, %s found"
                                 % (value.__class__.__name__,))
         else:
             if isinstance(value, tuple):


More information about the pypy-commit mailing list