* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
- * :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
+ * :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
+ use :c:func:`PyLongWriter_Create`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
- * :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
+ * :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
+ use :c:func:`PyLongWriter_Create`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
// Return a copy of src.
PyAPI_FUNC(PyObject*) _PyLong_Copy(PyLongObject *src);
-PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
+Py_DEPRECATED(3.14) PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
int negative,
Py_ssize_t digit_count,
digit *digits);
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
-* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
+* :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
+ use :c:func:`PyLongWriter_Create`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
}
PyLongObject *result = long_alloc(digit_count);
if (result == NULL) {
- PyErr_NoMemory();
return NULL;
}
_PyLong_SetSignAndDigitCount(result, negative?-1:1, digit_count);
_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);
- return (PyObject *)_PyLong_FromDigits(_PyLong_IsNegative(src), size, src->long_value.ob_digit);
+ PyLongObject *result = long_alloc(size);
+
+ if (result == NULL) {
+ return NULL;
+ }
+ _PyLong_SetSignAndDigitCount(result, sign, size);
+ memcpy(result->long_value.ob_digit, src->long_value.ob_digit,
+ size * sizeof(digit));
+ return (PyObject *)result;
}
static PyObject *