[Python-Dev] PY_FORMAT_SIZE_T warnings on OS X (original) (raw)

Brett Cannon brett at python.org
Thu Apr 27 07:19:46 CEST 2006


On 4/26/06, Tim Peters <tim.peters at gmail.com> wrote:

[Brett Cannon] >> I created patch 1474907 with a fix for it. Checks if %zd works for >> sizet and if so sets PYFORMATSIZET to "z", otherwise just doesn't >> set the macro def. >> >> Assigned to Martin to make sure I didn't foul it up, but pretty much >> anyone could probably double-check it.

[Martin v. Löwis] > Unfortunately, SF stopped sending emails when you get assigned an issue, > so I didn't receive any message when you created that patch. > > I now reviewed it, and think the test might not fail properly on systems > where %zd isn't supported. I agree with Martin's patch comments. The C standards don't require that printf fail if an unrecognized format gimmick is used (behavior is explicitly "undefined" then). For example, """ #include <stdio.h> #include <stdlib.h> int main() { int i; i = printf("%zd\n", (sizet)0); printf("%d\n", i); return 0; } """ prints "zd\n3\n" under all of MSVC 6.0, MSVC 7.1, and gcc (Cygwin) on WinXP. Using sprintf instead and checking the string produced seems much more likely to work. After the trunk freeze melts, I suggest just trying stuff. The buildbot system covers a bunch of platforms now, and when trying to out-hack ill-defined C stuff "try it and see" is easier than thinking <0.5 wink>.

I uploaded a new version that uses sprintf() and then does strncmp() on the result to see if it matches what is expected. That should be explicit enough to make sure that only a properly supported z modifier results in a successful test.

If anyone has a chance to check it again before the trunk unfreezes, that would be great.

-Brett



More information about the Python-Dev mailing list