[Python-checkins] python/dist/src/Modules datetimemodule.c,1.7,1.8

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Thu, 19 Dec 2002 17:31:30 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv17490/python/Modules

Modified Files:
	datetimemodule.c 
Log Message:
format_utcoffset():  The natural type of the buflen arg is size_t, so
used that.

wrap_strftime():  Removed the most irritating uses of buf.

TestDate.test_ordinal_conversions():  The C implementation is fast enough
that we can afford to check the endpoints of every year.  Also added
tm_yday tests at the endpoints.


Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** datetimemodule.c	19 Dec 2002 02:30:56 -0000	1.7
--- datetimemodule.c	20 Dec 2002 01:31:27 -0000	1.8
***************
*** 813,817 ****
   */
  static int
! format_utcoffset(char *buf, int buflen, const char *sep,
  		PyObject *tzinfo, PyObject *tzinfoarg)
  {
--- 813,817 ----
   */
  static int
! format_utcoffset(char *buf, size_t buflen, const char *sep,
  		PyObject *tzinfo, PyObject *tzinfoarg)
  {
***************
*** 864,874 ****
  	int ntoappend;	/* # of bytes to append to output buffer */
  
- 	char buf[100];	/* scratch buffer */
- 
  	assert(object && format && timetuple);
  	assert(PyString_Check(format));
  
  	/* Scan the input format, looking for %z and %Z escapes, building
! 	 * a new format.
  	 */
  	totalnew = PyString_Size(format);	/* realistic if no %z/%Z */
--- 864,873 ----
  	int ntoappend;	/* # of bytes to append to output buffer */
  
  	assert(object && format && timetuple);
  	assert(PyString_Check(format));
  
  	/* Scan the input format, looking for %z and %Z escapes, building
! 	 * a new format.  Since computing the replacements for those codes
! 	 * is expensive, don't unless they're actually used.
  	 */
  	totalnew = PyString_Size(format);	/* realistic if no %z/%Z */
***************
*** 881,886 ****
  	while ((ch = *pin++) != '\0') {
  		if (ch != '%') {
! 			buf[0] = ch;
! 			ptoappend = buf;
  			ntoappend = 1;
  		}
--- 880,884 ----
  	while ((ch = *pin++) != '\0') {
  		if (ch != '%') {
! 			ptoappend = pin - 1;
  			ntoappend = 1;
  		}
***************
*** 895,898 ****
--- 893,897 ----
  			if (zreplacement == NULL) {
  				/* format utcoffset */
+ 				char buf[100];
  				PyObject *tzinfo = get_tzinfo_member(object);
  				zreplacement = PyString_FromString("");
***************
*** 900,904 ****
  				if (tzinfo != Py_None && tzinfo != NULL) {
  					if (format_utcoffset(buf,
! 							     (int)sizeof(buf),
  							     "",
  							     tzinfo,
--- 899,903 ----
  				if (tzinfo != Py_None && tzinfo != NULL) {
  					if (format_utcoffset(buf,
! 							     sizeof(buf),
  							     "",
  							     tzinfo,
***************
*** 949,955 ****
  		}
  		else {
! 			buf[0] = '%';
! 			buf[1] = ch;
! 			ptoappend = buf;
  			ntoappend = 2;
  		}
--- 948,953 ----
  		}
  		else {
! 			/* percent followed by neither z nor Z */
! 			ptoappend = pin - 2;
  			ntoappend = 2;
  		}