[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.102,2.102.2.1

Thomas Wouters twouters@users.sourceforge.net
Wed, 23 May 2001 05:31:01 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv28190/Objects

Modified Files:
      Tag: release21-maint
	stringobject.c 
Log Message:

Backport Tim's checkin 2.104:

A different approach to the problem reported in
Patch #419651: Metrowerks on Mac adds 0x itself
C std says %#x and %#X conversion of 0 do not add the 0x/0X base marker. 
Metrowerks apparently does.  Mark Favas reported the same bug under a
Compaq compiler on Tru64 Unix, but no other libc broken in this respect
is known (known to be OK under MSVC and gcc). 
So just try the damn thing at runtime and see what the platform does. 
Note that we've always had bugs here, but never knew it before because
a relevant test case didn't exist before 2.1.



Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.102
retrieving revision 2.102.2.1
diff -C2 -r2.102 -r2.102.2.1
*** stringobject.c	2001/04/12 18:38:48	2.102
--- stringobject.c	2001/05/23 12:30:59	2.102.2.1
***************
*** 2674,2680 ****
  	 * but we want it (for consistency with other %#x conversions, and
  	 * for consistency with Python's hex() function).
  	 */
! 	if (x == 0 && (flags & F_ALT) && (type == 'x' || type == 'X')) {
! 		assert(buf[1] != type);  /* else this C *is* adding 0x/0X */
  		memmove(buf+2, buf, strlen(buf) + 1);
  		buf[0] = '0';
--- 2674,2684 ----
  	 * but we want it (for consistency with other %#x conversions, and
  	 * for consistency with Python's hex() function).
+ 	 * BUG 28-Apr-2001 tim:  At least two platform Cs (Metrowerks &
+ 	 * Compaq Tru64) violate the std by converting 0 w/ leading 0x anyway.
+ 	 * So add it only if the platform didn't already.
  	 */
! 	if (x == 0 && (flags & F_ALT) && (type == 'x' || type == 'X') &&
! 	    buf[1] != (char)type) /* this last always true under std C */
! 		{
  		memmove(buf+2, buf, strlen(buf) + 1);
  		buf[0] = '0';