mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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.
This commit is contained in:
parent
8b4e43e768
commit
64b5ce3a69
6 changed files with 55 additions and 3 deletions
|
|
@ -51,6 +51,25 @@ _PyLong_New(int size)
|
|||
return PyObject_NEW_VAR(PyLongObject, &PyLong_Type, size);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
PyObject *
|
||||
|
|
@ -2205,7 +2224,7 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
tmp = (PyLongObject *)long_new(&PyLong_Type, args, kwds);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
assert(PyLong_Check(tmp));
|
||||
assert(PyLong_CheckExact(tmp));
|
||||
n = tmp->ob_size;
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue