diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-12-04 10:41:06 +0200 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2022-12-04 10:41:06 +0200 |
commit | f9d5ae392ad48ccdb86b99a1dfd6d5aaf6697257 (patch) | |
tree | 2d88b13b0b1f1fe74eb21e35e50394c0a6336d77 | |
parent | (cfbolz, arigo pointing at the problem): somewhat blindly apply an equivalent (diff) | |
download | pypy-f9d5ae392ad48ccdb86b99a1dfd6d5aaf6697257.tar.gz pypy-f9d5ae392ad48ccdb86b99a1dfd6d5aaf6697257.tar.bz2 pypy-f9d5ae392ad48ccdb86b99a1dfd6d5aaf6697257.zip |
remove MSVC9 checks from windows strftime formattingrelease-pypy3.8-v7.3.10
-rw-r--r-- | pypy/module/time/interp_time.py | 33 | ||||
-rw-r--r-- | pypy/module/time/test/test_time.py | 22 |
2 files changed, 23 insertions, 32 deletions
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py index 24941a44ba..f4809f7b0a 100644 --- a/pypy/module/time/interp_time.py +++ b/pypy/module/time/interp_time.py @@ -397,10 +397,13 @@ if _WIN: rffi.INT, win_eci, calling_conv='c') if _WIN: - c_strftime = external('wcsftime', [rffi.CWCHARP, rffi.SIZE_T, rffi.CWCHARP, TM_P], - rffi.SIZE_T) + c_strftime = external('wcsftime', + [rffi.CWCHARP, rffi.SIZE_T, rffi.CWCHARP, TM_P], + rffi.SIZE_T, + save_err=rffi.RFFI_FULL_ERRNO_ZERO) else: - c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P], + c_strftime = external('strftime', + [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P], rffi.SIZE_T) def _init_timezone(space): @@ -1000,26 +1003,6 @@ def strftime(space, format, w_tup=None): if (tm_year + 1900 < 1 or 9999 < tm_year + 1900): raise oefmt(space.w_ValueError, "strftime() requires year in [1; 9999]") - if not we_are_translated(): - # We use this pre-call check since, when untranslated, since the host - # python and the c_strftime use different runtimes, and the c_strftime - # call goes through the ctypes call of the host python's runtime, which - # can be different than the translated runtime - - # Remove this when we no longer allow msvcrt9 - fmts = "aAbBcdHIjmMpSUwWxXyYzZ%" - length = len(format) - i = 0 - while i < length: - if format[i] == '%': - i += 1 - if i < length and format[i] == '#': - # not documented by python - i += 1 - # Assume visual studio 2015 - if i >= length or format[i] not in fmts: - raise oefmt(space.w_ValueError, "invalid format string") - i += 1 # wcharp with track_allocation=True format_for_call = rffi.utf82wcharp( format, codepoints_in_utf8(format)) @@ -1039,6 +1022,8 @@ def strftime(space, format, w_tup=None): try: with rposix.SuppressIPH(): buflen = c_strftime(outbuf, i, format_for_call, buf_value) + if _WIN and buflen == 0 and rposix.get_saved_errno() == errno.EINVAL: + raise oefmt(space.w_ValueError, "invalid format string") if buflen > 0 or i >= 256 * len(format): # if the buffer is 256 times as long as the format, # it's probably not failing for lack of room! @@ -1055,8 +1040,6 @@ def strftime(space, format, w_tup=None): else: decoded, size = str_decode_locale_surrogateescape(result) return space.newutf8(decoded, size) - if buflen == 0 and rposix.get_saved_errno() == errno.EINVAL: - raise oefmt(space.w_ValueError, "invalid format string") finally: lltype.free(outbuf, flavor='raw') i += i diff --git a/pypy/module/time/test/test_time.py b/pypy/module/time/test/test_time.py index aebb00c56f..d3bb16f90a 100644 --- a/pypy/module/time/test/test_time.py +++ b/pypy/module/time/test/test_time.py @@ -250,14 +250,24 @@ class AppTestTime: def test_mktime_overflow(self): import time - MAX_YEAR = (1 << 31) - 1 - MIN_YEAR = -(1 << 31) + 1900 + import sys + if sys.platform == 'win32': + # on windows, mktime will convert to utc and the upper + # bound is 23:59:59 Dec 21, 3000. So in order to be sure + # to exceed the limit everywhere, add 2 years + MAX_YEAR = 3000 + DELTA = 2 + MIN_YEAR = 1971 + else: + MAX_YEAR = (1 << 31) - 1 + DELTA = 1 + MIN_YEAR = -(1 << 31) + 1900 time.mktime((MAX_YEAR,) + (0,) * 8) # doesn't raise with raises(OverflowError): - time.mktime((MAX_YEAR + 1,) + (0,) * 8) + time.mktime((MAX_YEAR + DELTA,) + (0,) * 8) time.mktime((MIN_YEAR,) + (0,) * 8) # doesn't raise with raises(OverflowError): - time.mktime((MIN_YEAR - 1,) + (0,) * 8) + time.mktime((MIN_YEAR - DELTA,) + (0,) * 8) def test_asctime(self): import time @@ -415,11 +425,9 @@ class AppTestTime: raises(TypeError, time.strftime, (1,)) raises(TypeError, time.strftime, range(8)) - # Guard against invalid/non-supported format string - # so that Python don't crash (Windows crashes when the format string - # input to [w]strftime is not kosher. if os.name == 'nt': raises(ValueError, time.strftime, '%f') + # windows must have year stricly > 0 return elif sys.platform == 'darwin' or 'bsd' in sys.platform: # darwin strips % of unknown format codes |