Author: Armin Rigo <ar...@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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit