Commit d0a0312c authored by Matti Picus's avatar Matti Picus
Browse files

remove MSVC9 checks from windows strftime formatting

--HG--
branch : release-pypy3.8-v7.x
parent 7f7d667ab53e
Pipeline #59198 passed with stage
in 8 minutes and 1 second
......@@ -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
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment