Skip to content

Commit

Permalink
+1
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jan 24, 2025
1 parent 1b80350 commit d5e1fef
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit d5e1fef

Please sign in to comment.