[Python-checkins] CVS: python/dist/src/Objects complexobject.c,2.52,2.53

Fred L. Drake fdrake@users.sourceforge.net
Thu, 13 Dec 2001 11:52:24 -0800


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

Modified Files:
	complexobject.c 
Log Message:
Ensure that complex() only accepts a string argument as the first arg,
and only if there is no second arg.
This closes SF patch #479551.


Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.52
retrieving revision 2.53
diff -C2 -d -r2.52 -r2.53
*** complexobject.c	2001/11/28 20:50:56	2.52
--- complexobject.c	2001/12/13 19:52:22	2.53
***************
*** 807,812 ****
  					 &r, &i))
  		return NULL;
! 	if (PyString_Check(r) || PyUnicode_Check(r))
  		return complex_subtype_from_string(type, r);
  
  	nbr = r->ob_type->tp_as_number;
--- 807,824 ----
  					 &r, &i))
  		return NULL;
! 	if (PyString_Check(r) || PyUnicode_Check(r)) {
! 		if (i != NULL) {
! 			PyErr_SetString(PyExc_TypeError,
! 					"complex() can't take second arg"
! 					" if first is a string");
! 			return NULL;
!                 }
  		return complex_subtype_from_string(type, r);
+ 	}
+ 	if (i != NULL && (PyString_Check(i) || PyUnicode_Check(i))) {
+ 		PyErr_SetString(PyExc_TypeError,
+ 				"complex() second arg can't be a string");
+ 		return NULL;
+ 	}
  
  	nbr = r->ob_type->tp_as_number;