[Python-checkins] python/dist/src/Modules datetimemodule.c,1.66,1.67
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
2003年6月27日 01:14:19 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv5051/Modules
Modified Files:
datetimemodule.c
Log Message:
SF bug #761337: datetime.strftime fails on trivial format string
The interning of short strings violates the refcnt==1 assumption for
_PyString_Resize().
A simple fix is to boost the initial value of "totalnew" by 1.
Combined with an NULL argument to PyString_FromStringAndSize(),
this assures that resulting format string is not interned.
This will remain true even if the implementation of
PyString_FromStringAndSize() changes because only the uninitialized
strings that can be interned are those of zero length.
Added a test case.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** datetimemodule.c 18 May 2003 02:24:46 -0000 1.66
--- datetimemodule.c 27 Jun 2003 08:14:17 -0000 1.67
***************
*** 1176,1180 ****
* is expensive, don't unless they're actually used.
*/
! totalnew = PyString_Size(format); /* realistic if no %z/%Z */
newfmt = PyString_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done;
--- 1176,1180 ----
* is expensive, don't unless they're actually used.
*/
! totalnew = PyString_Size(format) + 1; /* realistic if no %z/%Z */
newfmt = PyString_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done;