Fix #193 (use RtlMoveMemory instead of msvcrt.memcpy)

This commit is contained in:
Aarni Koskela 2013-10-25 14:28:52 +03:00 committed by Jeff Forcier
parent 698adf10fb
commit d8738b1b0f
1 changed files with 6 additions and 6 deletions

View File

@ -81,9 +81,6 @@ def handle_nonzero_success(result):
raise WindowsError() raise WindowsError()
#####################
# jaraco.windows.mmap
CreateFileMapping = ctypes.windll.kernel32.CreateFileMappingW CreateFileMapping = ctypes.windll.kernel32.CreateFileMappingW
CreateFileMapping.argtypes = [ CreateFileMapping.argtypes = [
ctypes.wintypes.HANDLE, ctypes.wintypes.HANDLE,
@ -130,15 +127,18 @@ class MemoryMap(object):
self.pos = pos self.pos = pos
def write(self, msg): def write(self, msg):
ctypes.windll.msvcrt.memcpy(self.view + self.pos, msg, len(msg)) n = len(msg)
self.pos += len(msg) if self.pos + n >= self.length: # A little safety.
raise ValueError("Refusing to write %d bytes" % n)
ctypes.windll.kernel32.RtlMoveMemory(self.view + self.pos, msg, n)
self.pos += n
def read(self, n): def read(self, n):
""" """
Read n bytes from mapped view. Read n bytes from mapped view.
""" """
out = ctypes.create_string_buffer(n) out = ctypes.create_string_buffer(n)
ctypes.windll.msvcrt.memcpy(out, self.view + self.pos, n) ctypes.windll.kernel32.RtlMoveMemory(out, self.view + self.pos, n)
self.pos += n self.pos += n
return out.raw return out.raw