From d5e1fefc35d10e729ac7524f919e51146db445e2 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 24 Jan 2025 09:15:04 +0300 Subject: [PATCH] +1 --- Objects/longobject.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index 5fd677e2109e85..ea0bb36f6222ec 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -217,12 +217,17 @@ PyObject * _PyLong_Copy(PyLongObject *src) { assert(src != NULL); + int sign; if (_PyLong_IsCompact(src)) { stwodigits ival = medium_value(src); if (IS_SMALL_INT(ival)) { return get_small_int((sdigit)ival); } + sign = _PyLong_CompactSign(src); + } + else { + sign = _PyLong_NonCompactSign(src); } Py_ssize_t size = _PyLong_DigitCount(src); @@ -232,8 +237,9 @@ _PyLong_Copy(PyLongObject *src) PyErr_NoMemory(); return NULL; } - _PyLong_SetSignAndDigitCount(result, _PyLong_Sign(src), size); - memcpy(result->long_value.ob_digit, src->long_value.ob_digit, size * sizeof(digit)); + _PyLong_SetSignAndDigitCount(result, sign, size); + memcpy(result->long_value.ob_digit, src->long_value.ob_digit, + size * sizeof(digit)); return (PyObject *)result; }