diff options
author | Mark Shannon <mark@hotpy.org> | 2023-05-21 13:45:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 13:45:48 (GMT) |
commit | 93923793f602ea9117f13bfac8cbe01a864eeb01 (patch) | |
tree | 33657460417c68e16479212566385144a0d9d30a /Modules/_testcapi | |
parent | ab71acd67b5b09926498b8c7f855bdb28ac0ec2f (diff) | |
download | cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.zip cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.gz cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.bz2 |
GH-101291: Add low level, unstable API for pylong (GH-101685)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r-- | Modules/_testcapi/long.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_testcapi/long.c b/Modules/_testcapi/long.c index 1be8de5..61dd965 100644 --- a/Modules/_testcapi/long.c +++ b/Modules/_testcapi/long.c @@ -534,6 +534,18 @@ test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored)) Py_RETURN_NONE; } +static PyObject * +check_long_compact_api(PyObject *self, PyObject *arg) +{ + assert(PyLong_Check(arg)); + int is_compact = PyUnstable_Long_IsCompact((PyLongObject*)arg); + Py_ssize_t value = -1; + if (is_compact) { + value = PyUnstable_Long_CompactValue((PyLongObject*)arg); + } + return Py_BuildValue("in", is_compact, value); +} + static PyMethodDef test_methods[] = { {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, {"test_long_api", test_long_api, METH_NOARGS}, @@ -543,6 +555,7 @@ static PyMethodDef test_methods[] = { {"test_long_long_and_overflow",test_long_long_and_overflow, METH_NOARGS}, {"test_long_numbits", test_long_numbits, METH_NOARGS}, {"test_longlong_api", test_longlong_api, METH_NOARGS}, + {"call_long_compact_api", check_long_compact_api, METH_O}, {NULL}, }; |