[pypy-commit] pypy release-2.2.x: Like CPython, strip the message from trailing dots.
arigo
noreply at buildbot.pypy.org
Tue Nov 12 13:56:17 CET 2013
Author: Armin Rigo <arigo at tunes.org>
Branch: release-2.2.x
Changeset: r67973:7ce0a6e10446
Date: 2013-11-12 13:54 +0100
http://bitbucket.org/pypy/pypy/changeset/7ce0a6e10446/
Log: Like CPython, strip the message from trailing dots.
diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -216,7 +216,7 @@
def llimpl_FormatError(code):
"Return a message corresponding to the given Windows error code."
buf = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
-
+ buf[0] = lltype.nullptr(rffi.CCHARP.TO)
try:
msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
@@ -225,17 +225,20 @@
DEFAULT_LANGUAGE,
rffi.cast(rffi.CCHARP, buf),
0, None)
+ buflen = intmask(msglen)
- if msglen <= 2: # includes the case msglen < 0
- return fake_FormatError(code)
+ # remove trailing cr/lf and dots
+ s_buf = buf[0]
+ while buflen > 0 and (s_buf[buflen - 1] <= ' ' or
+ s_buf[buflen - 1] == '.'):
+ buflen -= 1
- # FormatMessage always appends \r\n.
- buflen = intmask(msglen - 2)
- assert buflen > 0
-
- result = rffi.charpsize2str(buf[0], buflen)
+ if buflen <= 0:
+ result = fake_FormatError(code)
+ else:
+ result = rffi.charpsize2str(s_buf, buflen)
+ finally:
LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
- finally:
lltype.free(buf, flavor='raw')
return result
More information about the pypy-commit
mailing list