[Python-checkins] python/dist/src/Python bltinmodule.c,2.312,2.313

nascheme at users.sourceforge.net nascheme at users.sourceforge.net
Mon Jul 19 18:29:20 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28866/Python

Modified Files:
	bltinmodule.c 
Log Message:
Check the type of values returned by __int__, __float__, __long__,
__oct__, and __hex__.  Raise TypeError if an invalid type is
returned.  Note that PyNumber_Int and PyNumber_Long can still
return ints or longs.  Fixes SF bug #966618.


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.312
retrieving revision 2.313
diff -C2 -d -r2.312 -r2.313
*** bltinmodule.c	7 Jul 2004 17:44:11 -0000	2.312
--- bltinmodule.c	19 Jul 2004 16:29:17 -0000	2.313
***************
*** 963,966 ****
--- 963,967 ----
  {
  	PyNumberMethods *nb;
+ 	PyObject *res;
  
  	if ((nb = v->ob_type->tp_as_number) == NULL ||
***************
*** 970,974 ****
  		return NULL;
  	}
! 	return (*nb->nb_hex)(v);
  }
  
--- 971,983 ----
  		return NULL;
  	}
! 	res = (*nb->nb_hex)(v);
! 	if (res && !PyString_Check(res)) {
! 		PyErr_Format(PyExc_TypeError,
! 			     "__hex__ returned non-string (type %.200s)",
! 			     res->ob_type->tp_name);
! 		Py_DECREF(res);
! 		return NULL;
! 	}
! 	return res;
  }
  
***************
*** 1179,1182 ****
--- 1188,1192 ----
  {
  	PyNumberMethods *nb;
+ 	PyObject *res;
  
  	if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||
***************
*** 1186,1190 ****
  		return NULL;
  	}
! 	return (*nb->nb_oct)(v);
  }
  
--- 1196,1208 ----
  		return NULL;
  	}
! 	res = (*nb->nb_oct)(v);
! 	if (res && !PyString_Check(res)) {
! 		PyErr_Format(PyExc_TypeError,
! 			     "__oct__ returned non-string (type %.200s)",
! 			     res->ob_type->tp_name);
! 		Py_DECREF(res);
! 		return NULL;
! 	}
! 	return res;
  }
  



More information about the Python-checkins mailing list