-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Petr Viktorin <[email protected]>
- Loading branch information
1 parent
ab71acd
commit 9392379
Showing
8 changed files
with
139 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
import sys | ||
|
||
from test.support import import_helper | ||
|
||
# Skip this test if the _testcapi module isn't available. | ||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class LongTests(unittest.TestCase): | ||
|
||
def test_compact(self): | ||
for n in { | ||
# Edge cases | ||
*(2**n for n in range(66)), | ||
*(-2**n for n in range(66)), | ||
*(2**n - 1 for n in range(66)), | ||
*(-2**n + 1 for n in range(66)), | ||
# Essentially random | ||
*(37**n for n in range(14)), | ||
*(-37**n for n in range(14)), | ||
}: | ||
with self.subTest(n=n): | ||
is_compact, value = _testcapi.call_long_compact_api(n) | ||
if is_compact: | ||
self.assertEqual(n, value) | ||
|
||
def test_compact_known(self): | ||
# Sanity-check some implementation details (we don't guarantee | ||
# that these are/aren't compact) | ||
self.assertEqual(_testcapi.call_long_compact_api(-1), (True, -1)) | ||
self.assertEqual(_testcapi.call_long_compact_api(0), (True, 0)) | ||
self.assertEqual(_testcapi.call_long_compact_api(256), (True, 256)) | ||
self.assertEqual(_testcapi.call_long_compact_api(sys.maxsize), | ||
(False, -1)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/C API/2023-05-18-20-53-05.gh-issue-101291.ZBh9aR.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Added unstable C API for extracting the value of "compact" integers: | ||
:c:func:`PyUnstable_Long_IsCompact` and | ||
:c:func:`PyUnstable_Long_CompactValue`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters