[Python-checkins] CVS: python/dist/src/Objects bufferobject.c,2.7,2.8 classobject.c,2.93,2.94 fileobject.c,2.74,2.75 floatobject.c,2.58,2.59 funcobject.c,2.24,2.25 intobject.c,2.42,2.43 methodobject.c,2.27,2.28 object.c,2.75,2.76

Fred L. Drake python-dev@python.org
Fri, 30 Jun 2000 08:01:02 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv13110/Objects

Modified Files:
	bufferobject.c classobject.c fileobject.c floatobject.c 
	funcobject.c intobject.c methodobject.c object.c 
Log Message:
Trent Mick <trentm@activestate.com>:

The common technique for printing out a pointer has been to cast to a long 
and use the "%lx" printf modifier. This is incorrect on Win64 where casting 
to a long truncates the pointer. The "%p" formatter should be used instead. 

The problem as stated by Tim: 
> Unfortunately, the C committee refused to define what %p conversion "looks 
> like" -- they explicitly allowed it to be implementation-defined. Older 
> versions of Microsoft C even stuck a colon in the middle of the address (in 
> the days of segment+offset addressing)! 

The result is that the hex value of a pointer will maybe/maybe not have a 0x 
prepended to it. 


Notes on the patch: 

There are two main classes of changes: 
- in the various repr() functions that print out pointers 
- debugging printf's in the various thread_*.h files (these are why the 
patch is large)


Closes SourceForge patch #100505.


Index: bufferobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/bufferobject.c,v
retrieving revision 2.7
retrieving revision 2.8
diff -C2 -r2.7 -r2.8
*** bufferobject.c	2000/05/03 23:44:34	2.7
--- bufferobject.c	2000/06/30 15:01:00	2.8
***************
*** 242,259 ****
  	if ( self->b_base == NULL )
  	{
! 		sprintf(buf, "<%s buffer ptr %lx, size %d at %lx>",
  			status,
! 			(long)self->b_ptr,
  			self->b_size,
! 			(long)self);
  	}
  	else
  	{
! 		sprintf(buf, "<%s buffer for %lx, ptr %lx, size %d at %lx>",
  			status,
! 			(long)self->b_base,
! 			(long)self->b_ptr,
  			self->b_size,
! 			(long)self);
  	}
  
--- 242,259 ----
  	if ( self->b_base == NULL )
  	{
! 		sprintf(buf, "<%s buffer ptr %p, size %d at %p>",
  			status,
! 			self->b_ptr,
  			self->b_size,
! 			self);
  	}
  	else
  	{
! 		sprintf(buf, "<%s buffer for %p, ptr %p, size %d at %p>",
  			status,
! 			self->b_base,
! 			self->b_ptr,
  			self->b_size,
! 			self);
  	}
  

Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.93
retrieving revision 2.94
diff -C2 -r2.93 -r2.94
*** classobject.c	2000/06/30 05:02:53	2.93
--- classobject.c	2000/06/30 15:01:00	2.94
***************
*** 354,362 ****
  		name = PyString_AsString(op->cl_name);
  	if (mod == NULL || !PyString_Check(mod))
! 		sprintf(buf, "<class ?.%.100s at %lx>", name, (long)op);
  	else
! 		sprintf(buf, "<class %.50s.%.50s at %lx>",
  			PyString_AsString(mod),
! 			name, (long)op);
  	return PyString_FromString(buf);
  }
--- 354,362 ----
  		name = PyString_AsString(op->cl_name);
  	if (mod == NULL || !PyString_Check(mod))
! 		sprintf(buf, "<class ?.%.100s at %p>", name, op);
  	else
! 		sprintf(buf, "<class %.50s.%.50s at %p>",
  			PyString_AsString(mod),
! 			name, op);
  	return PyString_FromString(buf);
  }
***************
*** 806,815 ****
  		PyErr_Clear();
  		if (mod == NULL || !PyString_Check(mod))
! 			sprintf(buf, "<?.%.100s instance at %lx>",
! 				cname, (long)inst);
  		else
! 			sprintf(buf, "<%.50s.%.50s instance at %lx>",
  				PyString_AsString(mod),
! 				cname, (long)inst);
  		return PyString_FromString(buf);
  	}
--- 806,815 ----
  		PyErr_Clear();
  		if (mod == NULL || !PyString_Check(mod))
! 			sprintf(buf, "<?.%.100s instance at %p>",
! 				cname, inst);
  		else
! 			sprintf(buf, "<%.50s.%.50s instance at %p>",
  				PyString_AsString(mod),
! 				cname, inst);
  		return PyString_FromString(buf);
  	}
***************
*** 1705,1710 ****
  		else
  			icname = "?";
! 		sprintf(buf, "<method %.60s.%.60s of %.60s instance at %lx>",
! 			fcname, fname, icname, (long)self);
  	}
  	Py_XDECREF(funcname);
--- 1705,1710 ----
  		else
  			icname = "?";
! 		sprintf(buf, "<method %.60s.%.60s of %.60s instance at %p>",
! 			fcname, fname, icname, self);
  	}
  	Py_XDECREF(funcname);

Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.74
retrieving revision 2.75
diff -C2 -r2.74 -r2.75
*** fileobject.c	2000/06/28 20:57:07	2.74
--- fileobject.c	2000/06/30 15:01:00	2.75
***************
*** 241,249 ****
  {
  	char buf[300];
! 	sprintf(buf, "<%s file '%.256s', mode '%.10s' at %lx>",
  		f->f_fp == NULL ? "closed" : "open",
  		PyString_AsString(f->f_name),
  		PyString_AsString(f->f_mode),
! 		(long)f);
  	return PyString_FromString(buf);
  }
--- 241,249 ----
  {
  	char buf[300];
! 	sprintf(buf, "<%s file '%.256s', mode '%.10s' at %p>",
  		f->f_fp == NULL ? "closed" : "open",
  		PyString_AsString(f->f_name),
  		PyString_AsString(f->f_mode),
! 		f);
  	return PyString_FromString(buf);
  }

Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.58
retrieving revision 2.59
diff -C2 -r2.58 -r2.59
*** floatobject.c	2000/06/29 19:17:04	2.58
--- floatobject.c	2000/06/30 15:01:00	2.59
***************
*** 807,812 ****
  					PyFloat_AsString(buf, p);
  					fprintf(stderr,
! 			     "#   <float at %lx, refcnt=%d, val=%s>\n",
! 						(long)p, p->ob_refcnt, buf);
  				}
  			}
--- 807,812 ----
  					PyFloat_AsString(buf, p);
  					fprintf(stderr,
! 			     "#   <float at %p, refcnt=%d, val=%s>\n",
! 						p, p->ob_refcnt, buf);
  				}
  			}

Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.24
retrieving revision 2.25
diff -C2 -r2.24 -r2.25
*** funcobject.c	2000/06/30 05:02:53	2.24
--- funcobject.c	2000/06/30 15:01:00	2.25
***************
*** 203,211 ****
  	char buf[140];
  	if (op->func_name == Py_None)
! 		sprintf(buf, "<anonymous function at %lx>", (long)op);
  	else
! 		sprintf(buf, "<function %.100s at %lx>",
  			PyString_AsString(op->func_name),
! 			(long)op);
  	return PyString_FromString(buf);
  }
--- 203,211 ----
  	char buf[140];
  	if (op->func_name == Py_None)
! 		sprintf(buf, "<anonymous function at %p>", op);
  	else
! 		sprintf(buf, "<function %.100s at %p>",
  			PyString_AsString(op->func_name),
! 			op);
  	return PyString_FromString(buf);
  }

Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.42
retrieving revision 2.43
diff -C2 -r2.42 -r2.43
*** intobject.c	2000/05/09 14:27:48	2.42
--- intobject.c	2000/06/30 15:01:00	2.43
***************
*** 958,963 ****
  				if (PyInt_Check(p) && p->ob_refcnt != 0)
  					fprintf(stderr,
! 				"#   <int at %lx, refcnt=%d, val=%ld>\n",
! 					  (long)p, p->ob_refcnt, p->ob_ival);
  			}
  			list = list->next;
--- 958,963 ----
  				if (PyInt_Check(p) && p->ob_refcnt != 0)
  					fprintf(stderr,
! 				"#   <int at %p, refcnt=%d, val=%ld>\n",
! 						p, p->ob_refcnt, p->ob_ival);
  			}
  			list = list->next;

Index: methodobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/methodobject.c,v
retrieving revision 2.27
retrieving revision 2.28
diff -C2 -r2.27 -r2.28
*** methodobject.c	2000/06/29 19:17:04	2.27
--- methodobject.c	2000/06/30 15:01:00	2.28
***************
*** 149,155 ****
  	else
  		sprintf(buf,
! 			"<built-in method %.80s of %.80s object at %lx>",
  			m->m_ml->ml_name, m->m_self->ob_type->tp_name,
! 			(long)m->m_self);
  	return PyString_FromString(buf);
  }
--- 149,155 ----
  	else
  		sprintf(buf,
! 			"<built-in method %.80s of %.80s object at %p>",
  			m->m_ml->ml_name, m->m_self->ob_type->tp_name,
! 			m->m_self);
  	return PyString_FromString(buf);
  }

Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.75
retrieving revision 2.76
diff -C2 -r2.75 -r2.76
*** object.c	2000/06/30 05:02:53	2.75
--- object.c	2000/06/30 15:01:00	2.76
***************
*** 230,239 ****
  	else {
  		if (op->ob_refcnt <= 0)
! 			fprintf(fp, "<refcnt %u at %lx>",
! 				op->ob_refcnt, (long)op);
  		else if (op->ob_type->tp_print == NULL) {
  			if (op->ob_type->tp_repr == NULL) {
! 				fprintf(fp, "<%s object at %lx>",
! 					op->ob_type->tp_name, (long)op);
  			}
  			else {
--- 230,239 ----
  	else {
  		if (op->ob_refcnt <= 0)
! 			fprintf(fp, "<refcnt %u at %p>",
! 				op->ob_refcnt, op);
  		else if (op->ob_type->tp_print == NULL) {
  			if (op->ob_type->tp_repr == NULL) {
! 				fprintf(fp, "<%s object at %p>",
! 					op->ob_type->tp_name, op);
  			}
  			else {
***************
*** 281,286 ****
  	else if (v->ob_type->tp_repr == NULL) {
  		char buf[120];
! 		sprintf(buf, "<%.80s object at %lx>",
! 			v->ob_type->tp_name, (long)v);
  		return PyString_FromString(buf);
  	}
--- 281,286 ----
  	else if (v->ob_type->tp_repr == NULL) {
  		char buf[120];
! 		sprintf(buf, "<%.80s object at %p>",
! 			v->ob_type->tp_name, v);
  		return PyString_FromString(buf);
  	}