summaryrefslogtreecommitdiff
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-12 10:37:58 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-12 10:37:58 +0300
commitea36c941a1b2ad6582a35bc42aa70da9600d2841 (patch)
treee915477a42189e490044a15d786a18382064bc1f /Objects/longobject.c
parent9de7efe5ab40c19775dcc9ca88adf58d906fc53d (diff)
downloadcpython-git-ea36c941a1b2ad6582a35bc42aa70da9600d2841.tar.gz
Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index d821e4bfb6..f68d15e615 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5049,27 +5049,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;