Repository navigation
Conversation
Since Visual Studio 2015, the MSVC runtime provides a C99-conforming vsnprintf(), so the _vsnprintf() special case is no longer needed. Add a test for the truncation case and update the outdated comment.
|
According to the comment changes in this PR, the behavior of |
|
Ah! This wasn't meant as a bug fix: the intent was |
|
Is it dead code for everyone or are there versions where it is NOT dead code or extension modules that could be affected when running on an older platform? If this is possible, I prefer not to change anything. |
|
"Dead code" was not the right term, sorry: the branch is really executed on MSVC builds, it is just a special case that is not needed anymore. Starting from python 3.5, The difference is the return value when the output is truncated: -1 before (windows specific), rv >= size now (standard C99). I don't think it can break much: The doc says That said, I will not insist much to get this merged. I like this change, it provides a (very) small value in code-readiness/cognitive load, though at the expense of a low risk of breaking some wrongly-written extensions. I know CPython value the second over everything. |
|
Let me rephrase it as follows: does the current code rely on fragile details and is it still correct with newer MSVC versions? if so, let's keep it that way since there is a slight behavior change (AFAIU) |
|
Current code leaks out an undocumented implementation detail on Windows, but it still correct with newer MSVC. |
Since Visual Studio 2015, the MSVC runtime provides a C99-conforming
vsnprintf(), so the_vsnprintf()special case inPyOS_vsnprintf()is no longer needed. On truncation,_vsnprintf()returned a negative value, unlike the C99 behavior documented forPyOS_vsnprintf().Also adds a test for the truncation case in
test_ctypesand updates the outdated comment.No existing caller relies on the negative return value for truncation. Marked as draft until the Windows CI results are in.
Fixes #162054. See also #101703 (comment)