[Python-checkins] CVS: python/dist/src/Objects complexobject.c,2.44,2.45 floatobject.c,2.98,2.99

Tim Peters tim_one@users.sourceforge.net
Wed, 12 Sep 2001 12:12:51 -0700


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

Modified Files:
	complexobject.c floatobject.c 
Log Message:
Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Inhibited complex unary plus optimization when applied to a complex subtype.
Added PyComplex_CheckExact macro.  Some comments and minor code fiddling.


Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -d -r2.44 -r2.45
*** complexobject.c	2001/09/06 08:16:17	2.44
--- complexobject.c	2001/09/12 19:12:49	2.45
***************
*** 490,495 ****
  complex_pos(PyComplexObject *v)
  {
! 	Py_INCREF(v);
! 	return (PyObject *)v;
  }
  
--- 490,499 ----
  complex_pos(PyComplexObject *v)
  {
! 	if (PyComplex_CheckExact(v)) {
! 		Py_INCREF(v);
! 		return (PyObject *)v;
! 	}
! 	else
! 		return PyComplex_FromCComplex(v->cval);
  }
  
***************
*** 793,801 ****
  	if (PyString_Check(r) || PyUnicode_Check(r))
  		return complex_subtype_from_string(type, r);
! 	if ((nbr = r->ob_type->tp_as_number) == NULL ||
! 	    nbr->nb_float == NULL ||
! 	    (i != NULL &&
! 	     ((nbi = i->ob_type->tp_as_number) == NULL ||
! 	      nbi->nb_float == NULL))) {
  		PyErr_SetString(PyExc_TypeError,
  			   "complex() arg can't be converted to complex");
--- 797,806 ----
  	if (PyString_Check(r) || PyUnicode_Check(r))
  		return complex_subtype_from_string(type, r);
! 
! 	nbr = r->ob_type->tp_as_number;
! 	if (i != NULL)
! 		nbi = i->ob_type->tp_as_number;
! 	if (nbr == NULL || nbr->nb_float == NULL ||
! 	    ((i != NULL) && (nbi == NULL || nbi->nb_float == NULL))) {
  		PyErr_SetString(PyExc_TypeError,
  			   "complex() arg can't be converted to complex");
***************
*** 827,830 ****
--- 832,838 ----
  	}
  	if (PyComplex_Check(r)) {
+ 		/* Note that if r is of a complex subtype, we're only
+ 		   retaining its real & imag parts here, and the return
+ 		   value is (properly) of the builtin complex type. */
  		cr = ((PyComplexObject*)r)->cval;
  		if (own_r) {
***************
*** 869,876 ****
  
  static char complex_doc[] =
! "complex(real[, imag]) -> complex number\n\
! \n\
! Create a complex number from a real part and an optional imaginary part.\n\
! This is equivalent to (real + imag*1j) where imag defaults to 0.";
  
  static PyNumberMethods complex_as_number = {
--- 877,884 ----
  
  static char complex_doc[] =
! "complex(real[, imag]) -> complex number\n"
! "\n"
! "Create a complex number from a real part and an optional imaginary part.\n"
! "This is equivalent to (real + imag*1j) where imag defaults to 0.";
  
  static PyNumberMethods complex_as_number = {

Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.98
retrieving revision 2.99
diff -C2 -d -r2.98 -r2.99
*** floatobject.c	2001/09/11 21:53:35	2.98
--- floatobject.c	2001/09/12 19:12:49	2.99
***************
*** 660,664 ****
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyFloat_Check(tmp));
  	new = type->tp_alloc(type, 0);
  	if (new == NULL)
--- 660,664 ----
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyFloat_CheckExact(tmp));
  	new = type->tp_alloc(type, 0);
  	if (new == NULL)