|
1 | | -# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 | 3 | # |
4 | 4 | # The Universal Permissive License (UPL), Version 1.0 |
@@ -127,6 +127,11 @@ def _reference_sign(args): |
127 | 127 | else: |
128 | 128 | return 1 |
129 | 129 |
|
| 130 | +def _reference_is_compact(args): |
| 131 | + n = args[0] |
| 132 | + # the range is impl. specific, but let's assume it's at least int32 |
| 133 | + return 1 if -2147483648 <= n <= 2147483647 else 0 |
| 134 | + |
130 | 135 |
|
131 | 136 | class DummyNonInt(): |
132 | 137 | pass |
@@ -420,7 +425,25 @@ class TestPyLong(CPyExtTestCase): |
420 | 425 | argspec="OniiO", |
421 | 426 | arguments=["PyObject* object", "Py_ssize_t n", "int little_endian", "int is_signed", "PyObject* unused"], |
422 | 427 | ) |
423 | | - |
| 428 | + |
| 429 | + test_PyUnstable_Long_IsCompact = CPyExtFunction( |
| 430 | + _reference_is_compact, |
| 431 | + # for CPython the range is different, so we test only obvious values |
| 432 | + lambda: ((0,), (-1,), (1,), (9223372036854775807 * 10,)), |
| 433 | + resultspec="i", |
| 434 | + argspec='O', |
| 435 | + arguments=["PyLongObject* o"], |
| 436 | + ) |
| 437 | + |
| 438 | + test_PyUnstable_Long_CompactValue = CPyExtFunction( |
| 439 | + lambda x: x[0], |
| 440 | + # for CPython the range is different, so we test only obvious values |
| 441 | + lambda: ((0,), (-1,), (1,)), |
| 442 | + resultspec="l", |
| 443 | + argspec='O', |
| 444 | + arguments=["PyLongObject* o"], |
| 445 | + ) |
| 446 | + |
424 | 447 | test__PyLong_Sign = CPyExtFunction( |
425 | 448 | _reference_sign, |
426 | 449 | lambda: ( |
|
0 commit comments