Author: Alecsandru Patrascu <alecsandru.patra...@rinftech.com> Branch: ctypes_char_indexing Changeset: r91552:c5adea5c7b06 Date: 2017-05-29 21:11 +0300 http://bitbucket.org/pypy/pypy/changeset/c5adea5c7b06/
Log: fix char_p and unichar_p interpretation 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 @@ -76,6 +76,16 @@ return self._type_._alignmentofinstances() def _CData_output(self, resarray, base=None, index=-1): + from _rawffi.alt import types + # If a char_p or unichar_p is received, skip the string interpretation + if base._ffiargtype != types.Pointer(types.char_p) and \ + base._ffiargtype != types.Pointer(types.unichar_p): + #this seems to be a string if we're array of char, surprise! + from ctypes import c_char, c_wchar + if self._type_ is c_char: + return _rawffi.charp2string(resarray.buffer, self._length_) + if self._type_ is c_wchar: + return _rawffi.wcharp2unicode(resarray.buffer, self._length_) res = self.__new__(self) ffiarray = self._ffiarray.fromaddress(resarray.buffer, self._length_) res._buffer = ffiarray _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit