Skip to content

Commit 6bc3973

Browse files
committed
gh-104469: Convert _testcapi/long to use AC
1 parent 9392379 commit 6bc3973

File tree

2 files changed

+214
-33
lines changed

2 files changed

+214
-33
lines changed

Modules/_testcapi/clinic/long.c.h

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_testcapi/long.c

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#include "parts.h"
2+
#include "clinic/long.c.h"
3+
4+
/*[clinic input]
5+
module _testcapi
6+
[clinic start generated code]*/
7+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/
28

39

410
static PyObject *
@@ -40,8 +46,13 @@ raise_test_long_error(const char* msg)
4046

4147
#include "testcapi_long.h"
4248

49+
/*[clinic input]
50+
_testcapi.test_long_api
51+
[clinic start generated code]*/
52+
4353
static PyObject *
44-
test_long_api(PyObject* self, PyObject *Py_UNUSED(ignored))
54+
_testcapi_test_long_api_impl(PyObject *module)
55+
/*[clinic end generated code: output=4405798ca1e9f444 input=e9b8880d7331c688]*/
4556
{
4657
return TESTNAME(raise_test_long_error);
4758
}
@@ -68,8 +79,13 @@ raise_test_longlong_error(const char* msg)
6879

6980
#include "testcapi_long.h"
7081

82+
/*[clinic input]
83+
_testcapi.test_longlong_api
84+
[clinic start generated code]*/
85+
7186
static PyObject *
72-
test_longlong_api(PyObject* self, PyObject *args)
87+
_testcapi_test_longlong_api_impl(PyObject *module)
88+
/*[clinic end generated code: output=2b3414ba8c31dfe6 input=ccbb2a48c2b3c4a5]*/
7389
{
7490
return TESTNAME(raise_test_longlong_error);
7591
}
@@ -81,13 +97,16 @@ test_longlong_api(PyObject* self, PyObject *args)
8197
#undef F_U_TO_PY
8298
#undef F_PY_TO_U
8399

84-
/* Test the PyLong_AsLongAndOverflow API. General conversion to PY_LONG
85-
is tested by test_long_api_inner. This test will concentrate on proper
86-
handling of overflow.
87-
*/
100+
101+
/*[clinic input]
102+
_testcapi.test_long_and_overflow
103+
104+
Test the PyLong_AsLongAndOverflow API. General conversion to PY_LONG is tested by test_long_api_inner. This test will concentrate on proper handling of overflow.
105+
[clinic start generated code]*/
88106

89107
static PyObject *
90-
test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
108+
_testcapi_test_long_and_overflow_impl(PyObject *module)
109+
/*[clinic end generated code: output=f8460ca115e31d8e input=0eec7ad657143d42]*/
91110
{
92111
PyObject *num, *one, *temp;
93112
long value;
@@ -243,13 +262,15 @@ test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
243262
Py_RETURN_NONE;
244263
}
245264

246-
/* Test the PyLong_AsLongLongAndOverflow API. General conversion to
247-
long long is tested by test_long_api_inner. This test will
248-
concentrate on proper handling of overflow.
249-
*/
265+
/*[clinic input]
266+
_testcapi.test_long_long_and_overflow
267+
268+
Test the PyLong_AsLongLongAndOverflow API. General conversion to long long is tested by test_long_api_inner. This test will concentrate on proper handling of overflow.
269+
[clinic start generated code]*/
250270

251271
static PyObject *
252-
test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
272+
_testcapi_test_long_long_and_overflow_impl(PyObject *module)
273+
/*[clinic end generated code: output=0b92330786f45483 input=96dc3e6c0cdc0475]*/
253274
{
254275
PyObject *num, *one, *temp;
255276
long long value;
@@ -405,13 +426,15 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
405426
Py_RETURN_NONE;
406427
}
407428

408-
/* Test the PyLong_As{Size,Ssize}_t API. At present this just tests that
409-
non-integer arguments are handled correctly. It should be extended to
410-
test overflow handling.
411-
*/
429+
/*[clinic input]
430+
_testcapi.test_long_as_size_t
431+
432+
Test the PyLong_As{Size,Ssize}_t API. At present this just tests that non-integer arguments are handled correctly. It should be extended to test overflow handling.
433+
[clinic start generated code]*/
412434

413435
static PyObject *
414-
test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored))
436+
_testcapi_test_long_as_size_t_impl(PyObject *module)
437+
/*[clinic end generated code: output=f6490ea2b41e6173 input=47d303cdd7144351]*/
415438
{
416439
size_t out_u;
417440
Py_ssize_t out_s;
@@ -442,9 +465,13 @@ test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored))
442465
return Py_None;
443466
}
444467

468+
/*[clinic input]
469+
_testcapi.test_long_as_unsigned_long_long_mask
470+
[clinic start generated code]*/
471+
445472
static PyObject *
446-
test_long_as_unsigned_long_long_mask(PyObject *self,
447-
PyObject *Py_UNUSED(ignored))
473+
_testcapi_test_long_as_unsigned_long_long_mask_impl(PyObject *module)
474+
/*[clinic end generated code: output=e3e16cd0189440cc input=eb2438493ae7b9af]*/
448475
{
449476
unsigned long long res = PyLong_AsUnsignedLongLongMask(NULL);
450477

@@ -462,12 +489,13 @@ test_long_as_unsigned_long_long_mask(PyObject *self,
462489
Py_RETURN_NONE;
463490
}
464491

465-
/* Test the PyLong_AsDouble API. At present this just tests that
466-
non-integer arguments are handled correctly.
467-
*/
492+
/*[clinic input]
493+
_testcapi.test_long_as_double
494+
[clinic start generated code]*/
468495

469496
static PyObject *
470-
test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored))
497+
_testcapi_test_long_as_double_impl(PyObject *module)
498+
/*[clinic end generated code: output=deca0898e15adde5 input=c77bc88ef5a1de76]*/
471499
{
472500
double out;
473501

@@ -487,9 +515,13 @@ test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored))
487515
return Py_None;
488516
}
489517

490-
/* Simple test of _PyLong_NumBits and _PyLong_Sign. */
518+
/*[clinic input]
519+
_testcapi.test_long_numbits
520+
[clinic start generated code]*/
521+
491522
static PyObject *
492-
test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored))
523+
_testcapi_test_long_numbits_impl(PyObject *module)
524+
/*[clinic end generated code: output=9eaf8458cb15d7f7 input=265c02d48a13059e]*/
493525
{
494526
struct triple {
495527
long input;
@@ -547,14 +579,14 @@ check_long_compact_api(PyObject *self, PyObject *arg)
547579
}
548580

549581
static PyMethodDef test_methods[] = {
550-
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
551-
{"test_long_api", test_long_api, METH_NOARGS},
552-
{"test_long_as_double", test_long_as_double, METH_NOARGS},
553-
{"test_long_as_size_t", test_long_as_size_t, METH_NOARGS},
554-
{"test_long_as_unsigned_long_long_mask", test_long_as_unsigned_long_long_mask, METH_NOARGS},
555-
{"test_long_long_and_overflow",test_long_long_and_overflow, METH_NOARGS},
556-
{"test_long_numbits", test_long_numbits, METH_NOARGS},
557-
{"test_longlong_api", test_longlong_api, METH_NOARGS},
582+
_TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF
583+
_TESTCAPI_TEST_LONG_API_METHODDEF
584+
_TESTCAPI_TEST_LONG_AS_DOUBLE_METHODDEF
585+
_TESTCAPI_TEST_LONG_AS_SIZE_T_METHODDEF
586+
_TESTCAPI_TEST_LONG_AS_UNSIGNED_LONG_LONG_MASK_METHODDEF
587+
_TESTCAPI_TEST_LONG_LONG_AND_OVERFLOW_METHODDEF
588+
_TESTCAPI_TEST_LONG_NUMBITS_METHODDEF
589+
_TESTCAPI_TEST_LONGLONG_API_METHODDEF
558590
{"call_long_compact_api", check_long_compact_api, METH_O},
559591
{NULL},
560592
};

0 commit comments

Comments
 (0)