[Python-checkins] CVS: python/dist/src/Objects abstract.c,2.74,2.75 longobject.c,1.103,1.104

Tim Peters tim_one@users.sourceforge.net
Mon, 10 Sep 2001 13:52:53 -0700


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

Modified Files:
	abstract.c longobject.c 
Log Message:
SF bug #460020:  bug or feature: unicode() and subclasses.
Given an immutable type M, and an instance I of a subclass of M, the
constructor call M(I) was just returning I as-is; but it should return a
new instance of M.  This fixes it for M in {int, long}.  Strings, floats
and tuples remain to be done.
Added new macros PyInt_CheckExact and PyLong_CheckExact, to more easily
distinguish between "is" and "is a" (i.e., only an int passes
PyInt_CheckExact, while any sublass of int passes PyInt_Check).
Added private API function _PyLong_Copy.


Index: abstract.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v
retrieving revision 2.74
retrieving revision 2.75
diff -C2 -d -r2.74 -r2.75
*** abstract.c	2001/09/08 04:00:12	2.74
--- abstract.c	2001/09/10 20:52:51	2.75
***************
*** 5,8 ****
--- 5,9 ----
  #include <ctype.h>
  #include "structmember.h" /* we need the offsetof() macro from there */
+ #include "longintrepr.h"
  
  #define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \
***************
*** 819,826 ****
  	if (o == NULL)
  		return null_error();
! 	if (PyInt_Check(o)) {
  		Py_INCREF(o);
  		return o;
  	}
  	if (PyString_Check(o))
  		return int_from_string(PyString_AS_STRING(o), 
--- 820,831 ----
  	if (o == NULL)
  		return null_error();
! 	if (PyInt_CheckExact(o)) {
  		Py_INCREF(o);
  		return o;
  	}
+ 	if (PyInt_Check(o)) {
+ 		PyIntObject *io = (PyIntObject*)o;
+ 		return PyInt_FromLong(io->ob_ival);
+ 	}
  	if (PyString_Check(o))
  		return int_from_string(PyString_AS_STRING(o), 
***************
*** 869,876 ****
  	if (o == NULL)
  		return null_error();
! 	if (PyLong_Check(o)) {
  		Py_INCREF(o);
  		return o;
  	}
  	if (PyString_Check(o))
  		/* need to do extra error checking that PyLong_FromString() 
--- 874,883 ----
  	if (o == NULL)
  		return null_error();
! 	if (PyLong_CheckExact(o)) {
  		Py_INCREF(o);
  		return o;
  	}
+ 	if (PyLong_Check(o))
+ 		return _PyLong_Copy((PyLongObject *)o);
  	if (PyString_Check(o))
  		/* need to do extra error checking that PyLong_FromString() 

Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -C2 -d -r1.103 -r1.104
*** longobject.c	2001/09/06 21:59:14	1.103
--- longobject.c	2001/09/10 20:52:51	1.104
***************
*** 52,55 ****
--- 52,74 ----
  }
  
+ PyObject *
+ _PyLong_Copy(PyLongObject *src)
+ {
+ 	PyLongObject *result;
+ 	int i;
+ 
+ 	assert(src != NULL);
+ 	i = src->ob_size;
+ 	if (i < 0)
+ 		i = -(i);
+ 	result = _PyLong_New(i);
+ 	if (result != NULL) {
+ 		result->ob_size = i;
+ 		while (--i >= 0)
+ 			result->ob_digit[i] = src->ob_digit[i];
+ 	}
+ 	return (PyObject *)result;
+ }
+ 
  /* Create a new long int object from a C long int */
  
***************
*** 2206,2210 ****
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyLong_Check(tmp));
  	n = tmp->ob_size;
  	if (n < 0)
--- 2225,2229 ----
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyLong_CheckExact(tmp));
  	n = tmp->ob_size;
  	if (n < 0)