Merge pull request #51658 from dwoz/pip_test_fix

[2019.2] Let memcopy make the null bytes, better py3 support
This commit is contained in:
Daniel Wozniak 2019-02-14 22:42:36 -07:00 committed by GitHub
commit 1ea6f4b18b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -355,13 +355,16 @@ class ContiguousUnicode(ctypes.Structure):
return buf[:length]
return None
def _set_unicode_buffer(self, value):
def _set_unicode_buffer(self, values):
cls = type(self)
wchar_size = ctypes.sizeof(WCHAR)
bufsize = (len(value) + 1) * wchar_size
bufsize = (len('\x00'.join(values)) + 1) * wchar_size
ctypes.resize(self, ctypes.sizeof(cls) + bufsize)
addr = ctypes.addressof(self) + ctypes.sizeof(cls)
ctypes.memmove(addr, value, bufsize)
for value in values:
bufsize = (len(value) + 1) * wchar_size
ctypes.memmove(addr, value, bufsize)
addr += bufsize
def _set_unicode_string(self, name, value):
values = []
@ -370,7 +373,7 @@ class ContiguousUnicode(ctypes.Structure):
values.append(value or '')
else:
values.append(getattr(self, n) or '')
self._set_unicode_buffer('\x00'.join(values))
self._set_unicode_buffer(values)
cls = type(self)
wchar_size = ctypes.sizeof(WCHAR)