diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-10 20:52:51 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-10 20:52:51 (GMT) |
commit | 64b5ce3a69569b203a39f74c5c03348ba0a67583 (patch) | |
tree | 87f71bc6ef25a7b7e11087afb1d7827bbcc4d474 /Include | |
parent | 8b4e43e768f3f49513f6f32f20ecb6478c1ad840 (diff) | |
download | cpython-64b5ce3a69569b203a39f74c5c03348ba0a67583.zip cpython-64b5ce3a69569b203a39f74c5c03348ba0a67583.tar.gz cpython-64b5ce3a69569b203a39f74c5c03348ba0a67583.tar.bz2 |
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.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/intobject.h | 1 | ||||
-rw-r--r-- | Include/longintrepr.h | 3 | ||||
-rw-r--r-- | Include/longobject.h | 1 |
3 files changed, 5 insertions, 0 deletions
diff --git a/Include/intobject.h b/Include/intobject.h index 29448e3..2d244ec 100644 --- a/Include/intobject.h +++ b/Include/intobject.h @@ -28,6 +28,7 @@ typedef struct { extern DL_IMPORT(PyTypeObject) PyInt_Type; #define PyInt_Check(op) PyObject_TypeCheck(op, &PyInt_Type) +#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type) extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int); #ifdef Py_USING_UNICODE diff --git a/Include/longintrepr.h b/Include/longintrepr.h index 1154e0b..89ba586 100644 --- a/Include/longintrepr.h +++ b/Include/longintrepr.h @@ -46,6 +46,9 @@ struct _longobject { DL_IMPORT(PyLongObject *) _PyLong_New(int); +/* Return a copy of src. */ +DL_IMPORT(PyObject *) _PyLong_Copy(PyLongObject *src); + #ifdef __cplusplus } #endif diff --git a/Include/longobject.h b/Include/longobject.h index e592891..6b10625 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -12,6 +12,7 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ extern DL_IMPORT(PyTypeObject) PyLong_Type; #define PyLong_Check(op) PyObject_TypeCheck(op, &PyLong_Type) +#define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type) extern DL_IMPORT(PyObject *) PyLong_FromLong(long); extern DL_IMPORT(PyObject *) PyLong_FromUnsignedLong(unsigned long); |