[Python-bugs-list] [ python-Bugs-761337 ] datetime.strftime fails on trivial format string
SourceForge.net
noreply@sourceforge.net
Fri, 27 Jun 2003 01:16:00 -0700
Bugs item #761337, was opened at 2003-06-26 12:54
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=761337&group_id=5470
Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Jason R. Coombs (jaraco)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime.strftime fails on trivial format string
Initial Comment:
Simply put, strftime can't handle the empty string.
>>> import datetime
>>> now = datetime.datetime.utcnow()
>>> now.strftime( '%d' )
'26'
>>> now.strftime( '' )
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
SystemError: C:\Code\23b1
\Objects\stringobject.c:3315: bad argument to internal
function
This is inconsistent with the docs and the time.strftime
function.
>>> import time
>>> time.strftime( '', time.gmtime() )
''
Do I need to make any more justification for having the
empty format string return an empty string?
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-27 03:16
Message:
Logged In: YES
user_id=80475
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.
Fixed and added a test case. See:
Modules/datetimemodule.c 1.67
Lib/test/test_datetime.py 1.45
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=761337&group_id=5470