[pypy-commit] pypy winconsoleio: Implemented a bit more of readall. Fixed memory allocation in
andrewjlawrence
pypy.commits at gmail.com
Tue Sep 10 18:13:33 EDT 2019
Author: andrewjlawrence
Branch: winconsoleio
Changeset: r97424:38ba22b576dd
Date: 2019-09-10 22:54 +0100
http://bitbucket.org/pypy/pypy/changeset/38ba22b576dd/
Log: Implemented a bit more of readall. Fixed memory allocation in
read_console_w
diff --git a/pypy/module/_io/interp_win32consoleio.py b/pypy/module/_io/interp_win32consoleio.py
--- a/pypy/module/_io/interp_win32consoleio.py
+++ b/pypy/module/_io/interp_win32consoleio.py
@@ -33,6 +33,7 @@
err = 0
sig = 0
buf = lltype.malloc(rwin32.CWCHARP, maxlen, flavor='raw')
+
try:
if not buf:
return None
@@ -83,6 +84,7 @@
continue
off += BUFSIZ
if err:
+ lltype.free(buf, flavor='raw')
return None
if readlen > 0 and buf[0] == '\x1a':
@@ -91,7 +93,7 @@
buf[0] = '\0'
readlen = 0
return buf
- finally:
+ except:
lltype.free(buf, flavor='raw')
@@ -422,10 +424,11 @@
return space.newint(read_len)
- def read_w(self, space):
+ def read_w(self, space, w_size=None):
+ size = convert_size(space, w_size)
if self.handle == rwin32.INVALID_HANDLE_VALUE:
err_closed()
- if !self.readable:
+ if not self.readable:
return err_mode("reading")
if size < 0:
@@ -468,6 +471,21 @@
lltype.free(buf, flavor='raw')
buf = lltype.malloc(rwin32.CWCHARP, bufsize + 1, flavor='raw')
subbuf = read_console_w(self.handle, bufsize - len, n)
+
+ if n > 0:
+ rwin32.wcsncpy_s(buf[len], bufsize - len +1, subbuf, n)
+
+ lltype.free(subbuf, flavor='raw')
+
+ if n == 0;
+ break
+
+ len += n
+
+ if len == 0 and _buflen(self) == 0:
+ return None
+
+
finally:
lltype.free(buf, flavor='raw')
diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -255,7 +255,9 @@
fd = _open_osfhandle(handle, flags)
with FdValidator(fd):
return fd
-
+
+ wcsncpy_s = rffi.llexternal('wcsncpy_s',
+ [rffi.WCHARP, rffi.SIZE_T, rffi.CWCHARP, rffi.SIZE_T], rffi.INT)
wcsicmp = rffi.llexternal('_wcsicmp', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
def build_winerror_to_errno():
More information about the pypy-commit
mailing list