Skip to content

Commit 1b80350

Browse files
committed
address review: inline _PyLong_FromDigits & improve docs
1 parent ebb5693 commit 1b80350

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

Doc/deprecations/c-api-pending-removal-in-3.18.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Pending removal in Python 3.18
77
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
88
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
99
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
10-
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
10+
* :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
11+
use :c:func:`PyLongWriter_Create`.
1112
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
1213
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
1314
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.

Doc/deprecations/c-api-pending-removal-in-future.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ although there is currently no date scheduled for their removal.
3535
* :c:member:`!PyBytesObject.ob_shash` member:
3636
call :c:func:`PyObject_Hash` instead.
3737
* :c:member:`!PyDictObject.ma_version_tag` member.
38-
* :c:func::c:func:`!_PyLong_FromDigits`
39-
Use instead :c:struct:`PyLongWriter` API.
4038
* Thread Local Storage (TLS) API:
4139

4240
* :c:func:`PyThread_create_key`:

Doc/whatsnew/3.14.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ Deprecated
13961396
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
13971397
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
13981398
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
1399-
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
1399+
* :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
1400+
use :c:func:`PyLongWriter_Create`.
14001401
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
14011402
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
14021403
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.

Misc/NEWS.d/next/C_API/2024-12-14-10-14-27.gh-issue-127937.-tT1KP.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

Misc/NEWS.d/next/C_API/2025-01-15-11-42-07.gh-issue-128863.C9MkB_.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Python 3.18:
55
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
66
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
77
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
8-
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
8+
* :c:func:`!_PyLong_FromDigits` and :c:func:`!_PyLong_New`:
9+
use :c:func:`PyLongWriter_Create`.
910
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
1011
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
1112
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.

Objects/longobject.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,17 @@ _PyLong_Copy(PyLongObject *src)
224224
return get_small_int((sdigit)ival);
225225
}
226226
}
227+
227228
Py_ssize_t size = _PyLong_DigitCount(src);
228-
return (PyObject *)_PyLong_FromDigits(_PyLong_IsNegative(src), size, src->long_value.ob_digit);
229+
PyLongObject *result = long_alloc(size);
230+
231+
if (result == NULL) {
232+
PyErr_NoMemory();
233+
return NULL;
234+
}
235+
_PyLong_SetSignAndDigitCount(result, _PyLong_Sign(src), size);
236+
memcpy(result->long_value.ob_digit, src->long_value.ob_digit, size * sizeof(digit));
237+
return (PyObject *)result;
229238
}
230239

231240
static PyObject *

0 commit comments

Comments
 (0)