[pypy-commit] pypy py3.5: Fix test_abstract in ctypes/test/test_frombuffer.py

rlamy pypy.commits at gmail.com
Thu Oct 19 13:21:08 EDT 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r92801:05b154658972
Date: 2017-10-19 18:20 +0100
http://bitbucket.org/pypy/pypy/changeset/05b154658972/

Log:	Fix test_abstract in ctypes/test/test_frombuffer.py

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
@@ -8,9 +8,14 @@
 class ArrayMeta(_CDataMeta):
     def __new__(self, name, cls, typedict):
         res = type.__new__(self, name, cls, typedict)
+
         if cls == (_CData,): # this is the Array class defined below
+            res._ffiarray = None
             return res
-
+        if not hasattr(res, '_length_') or not isinstance(res._length_, int):
+            raise AttributeError(
+                "class must define a '_length_' attribute, "
+                "which must be a positive integer")
         ffiarray = res._ffiarray = _rawffi.Array(res._type_._ffishape_)
         subletter = getattr(res._type_, '_type_', None)
         if subletter == 'c':
@@ -55,7 +60,7 @@
                 for i in range(len(val)):
                     target[i] = val[i]
                 if len(val) < self._length_:
-                    target[len(val)] = '\x00'
+                    target[len(val)] = u'\x00'
             res.value = property(getvalue, setvalue)
 
         res._ffishape_ = (ffiarray, res._length_)
@@ -164,7 +169,7 @@
     if letter == 'c':
         return b"".join(l)
     if letter == 'u':
-        return "".join(l)
+        return u"".join(l)
     return l
 
 class Array(_CData, metaclass=ArrayMeta):


More information about the pypy-commit mailing list