[Patches] [ python-Patches-1474907 ] detect %zd format for PY_FORMAT_SIZE_T
SourceForge.net
noreply at sourceforge.net
Fri Apr 28 06:51:24 CEST 2006
Patches item #1474907, was opened at 2006-04-22 23:18
Message generated for change (Comment added) made by bcannon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1474907&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Build
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Martin v. Löwis (loewis)
Summary: detect %zd format for PY_FORMAT_SIZE_T
Initial Comment:
The patch modifies configure.in to add PY_FORMAT_SIZE_T
to configure.in (meaning you need to run autoheader on
configure.in) so that if %zd is supported for size_t it
sets PY_FORMAT_SIZE_T to "z", otherwise it goes
undefined and the preprocessor trickery in
Include/pyport.h kicks in.
This fix removes compiler warnings on OS X 10.4.6 with
gcc 4.0.1 thanks to PY_FORMAT_SIZE_T being set to "".
Initially assigned to Martin v. Loewis since he said
this would be good to do and the Py_ssize_t stuff is
his invention.
----------------------------------------------------------------------
>Comment By: Brett Cannon (bcannon)
Date: 2006-04-27 21:51
Message:
Logged In: YES
user_id=357491
Yeah, I tried to use a string constant as a stack value, but
that didn't work. =) My brain just was not thinking in C
when I first came up with the patch.
I have a new version that uses a char array as the buffer.
I am on vacation so I don't have the time to apply it and
break buildbot, so I will hold off on applying if no one
finds problems with this version.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2006-04-26 22:29
Message:
Logged In: YES
user_id=21627
Looks fine to me, although it has "unusual" style of C:
- sizeof(char) is guaranteed to be 1 by the C standard. The
C standard defines "char" and "byte" as synonyms, even if
that means that "byte" has more than 8 bits. sizeof gives
the number of bytes, so for char, it is always 1.
- for a fixed-size array, people would normally make this an
automatic (stack) variable, instead of bothering with
explicit memory allocation, i.e.
char str_buffer[4]
Just out of fear of buffer overruns, many people would also
add some horrendous overallocation, such as str_buffer[1024] :-)
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2006-04-26 22:16
Message:
Logged In: YES
user_id=357491
Realized there is a better way: just strncmp() for the
expected result. Uploaded a new version.
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2006-04-26 21:59
Message:
Logged In: YES
user_id=357491
OK, uploaded a new version that uses strchr to check for
'%', 'z', and 'd'. If it looks reasonable I will apply it
and hope I don't break the buildbot. =)
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2006-04-26 09:15
Message:
Logged In: YES
user_id=21627
The patch seems to rely on printf returning <0 for the
unrecognized format. That seems unreliable: atleast on
Linux, printf just outputs the format as-is for unrecognized
formats. Instead, I think it should use sprintf, and then
check whether the result is the string "0" (in addition to
checking whether the printf call itself failed).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1474907&group_id=5470
More information about the Patches
mailing list