8000 gh-128863: deprecate _PyLong_FromDigits() function by skirpichev · Pull Request #127939 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128863: deprecate _PyLong_FromDigits() function #127939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review: inline _PyLong_FromDigits & improve docs
  • Loading branch information
skirpichev committed Jan 24, 2025
commit 1b803503403c03f32e2353e74c34309f9b88e369
3 changes: 2 additions & 1 deletion Doc/deprecations/c-api-pending-removal-in-3.18.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Pending removal in Python 3.18
* :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`.
Expand Down
2 changes: 0 additions & 2 deletions Doc/deprecations/c-api-pending-removal-in-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ although there is currently no date scheduled for their removal.
* :c:member:`!PyBytesObject.ob_shash` member:
call :c:func:`PyObject_Hash` instead.
* :c:member:`!PyDictObject.ma_version_tag` member.
* :c:func::c:func:`!_PyLong_FromDigits`
Use instead :c:struct:`PyLongWriter` API.
* Thread Local Storage (TLS) API:

* :c:func:`PyThread_create_key`:
Expand Down
3 changes: 2 additions & 1 deletion Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,8 @@ Deprecated
* :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`.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Python 3.18:
* :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`.
Expand Down
11 changes: 10 additions & 1 deletion Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,17 @@
return get_small_int((sdigit)ival);
}
}

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) {
PyErr_NoMemory();
return NULL;
}
_PyLong_SetSignAndDigitCount(result, _PyLong_Sign(src), size);

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in 9E88 Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

‘_PyLong_Sign’ is deprecated [-Wdeprecated-declarations]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

passing argument 1 of ‘_PyLong_Sign’ from incompatible pointer type [-Wincompatible-pointer-types]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'function': incompatible types - from 'PyLongObject *' to 'PyObject *' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 235 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'_PyLong_Sign': deprecated in 3.14 [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
memcpy(result->long_value.ob_digit, src->long_value.ob_digit, size * sizeof(digit));
return (PyObject *)result;
}

static PyObject *
Expand Down
Loading
0