]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-90716: Refactor PyLong_FromString to separate concerns (GH-96808)
authorOscar Benjamin <oscar.j.benjamin@gmail.com>
Sun, 25 Sep 2022 09:09:50 +0000 (10:09 +0100)
committerGitHub <noreply@github.com>
Sun, 25 Sep 2022 09:09:50 +0000 (10:09 +0100)
commit817fa28f81eed43539fad2c8e696df954afa6ad7
treed1896ba43aa0978a3c9943b294c51712f1a3f39a
parentea4be278fa6123d1f78c1fd556d79b311cd59f96
gh-90716: Refactor PyLong_FromString to separate concerns (GH-96808)

This is a preliminary PR to refactor `PyLong_FromString` which is currently quite messy and has spaghetti like code that mixes up different concerns as well as duplicating logic.

In particular:

- `PyLong_FromString` now only handles sign, base and prefix detection and calls a new function `long_from_string_base` to parse the main body of the string.
- The `long_from_string_base` function handles all string validation and then calls `long_from_binary_base` or a new function `long_from_non_binary_base` to construct the actual `PyLong`.
- The existing `long_from_binary_base` function is simplified by factoring duplicated logic to `long_from_string_base`.
- The new function `long_from_non_binary_base` factors out much of the code from `PyLong_FromString` including in particular the quadratic algorithm reffered to in gh-95778 so that this can be seen separately from unrelated concerns such as string validation.
Misc/NEWS.d/next/Core and Builtins/2022-09-13-21-45-07.gh-issue-95778.Oll4_5.rst [new file with mode: 0644]
Objects/longobject.c