summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:39:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:39:32 (GMT)
commit1f364438adf1bcdc89a51af9af526ed9d7b7996d (patch)
tree2d620f18e63ff8703f4da17d98d0467a40a3c507 /Objects
parent5787ef621a76dfe225308f0001d60e5e46e9a55f (diff)
parentea36c941a1b2ad6582a35bc42aa70da9600d2841 (diff)
downloadcpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.zip
cpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.tar.gz
cpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.tar.bz2
Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 70d8cfc..14d2974 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5199,27 +5199,9 @@ long_from_bytes(PyTypeObject *type, PyObject *args, PyObject *kwds)
little_endian, is_signed);
Py_DECREF(bytes);
- /* If from_bytes() was used on subclass, allocate new subclass
- * instance, initialize it with decoded int value and return it.
- */
- if (type != &PyLong_Type && PyType_IsSubtype(type, &PyLong_Type)) {
- PyLongObject *newobj;
- int i;
- Py_ssize_t n = Py_ABS(Py_SIZE(long_obj));
-
- newobj = (PyLongObject *)type->tp_alloc(type, n);
- if (newobj == NULL) {
- Py_DECREF(long_obj);
- return NULL;
- }
- assert(PyLong_Check(newobj));
- Py_SIZE(newobj) = Py_SIZE(long_obj);
- for (i = 0; i < n; i++) {
- newobj->ob_digit[i] =
- ((PyLongObject *)long_obj)->ob_digit[i];
- }
- Py_DECREF(long_obj);
- return (PyObject *)newobj;
+ if (type != &PyLong_Type) {
+ Py_SETREF(long_obj, PyObject_CallFunctionObjArgs((PyObject *)type,
+ long_obj, NULL));
}
return long_obj;