[Python-checkins] gh-104469: Convert _testcapi/long to use AC (gh-104720)

corona10 webhook-mailer at python.org
Tue May 23 09:52:44 EDT 2023


https://github.com/python/cpython/commit/76170f545870db93b6c45cae09ff34b18639ee97
commit: 76170f545870db93b6c45cae09ff34b18639ee97
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-05-23T22:52:36+09:00
summary:

gh-104469: Convert _testcapi/long to use AC (gh-104720)

files:
A Modules/_testcapi/clinic/long.c.h
M Modules/_testcapi/long.c

diff --git a/Modules/_testcapi/clinic/long.c.h b/Modules/_testcapi/clinic/long.c.h
new file mode 100644
index 000000000000..95885e0ae17a
--- /dev/null
+++ b/Modules/_testcapi/clinic/long.c.h
@@ -0,0 +1,166 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+#  include "pycore_gc.h"            // PyGC_Head
+#  include "pycore_runtime.h"       // _Py_ID()
+#endif
+
+
+PyDoc_STRVAR(_testcapi_test_long_api__doc__,
+"test_long_api($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_TEST_LONG_API_METHODDEF    \
+    {"test_long_api", (PyCFunction)_testcapi_test_long_api, METH_NOARGS, _testcapi_test_long_api__doc__},
+
+static PyObject *
+_testcapi_test_long_api_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_api(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_api_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_longlong_api__doc__,
+"test_longlong_api($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_TEST_LONGLONG_API_METHODDEF    \
+    {"test_longlong_api", (PyCFunction)_testcapi_test_longlong_api, METH_NOARGS, _testcapi_test_longlong_api__doc__},
+
+static PyObject *
+_testcapi_test_longlong_api_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_longlong_api(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_longlong_api_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_and_overflow__doc__,
+"test_long_and_overflow($module, /)\n"
+"--\n"
+"\n"
+"Test the PyLong_AsLongAndOverflow API.\n"
+"\n"
+"General conversion to PY_LONG is tested by test_long_api_inner.\n"
+"This test will concentrate on proper handling of overflow.");
+
+#define _TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF    \
+    {"test_long_and_overflow", (PyCFunction)_testcapi_test_long_and_overflow, METH_NOARGS, _testcapi_test_long_and_overflow__doc__},
+
+static PyObject *
+_testcapi_test_long_and_overflow_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_and_overflow(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_and_overflow_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_long_and_overflow__doc__,
+"test_long_long_and_overflow($module, /)\n"
+"--\n"
+"\n"
+"Test the PyLong_AsLongLongAndOverflow API.\n"
+"\n"
+"General conversion to long long is tested by test_long_api_inner.\n"
+"This test will concentrate on proper handling of overflow.");
+
+#define _TESTCAPI_TEST_LONG_LONG_AND_OVERFLOW_METHODDEF    \
+    {"test_long_long_and_overflow", (PyCFunction)_testcapi_test_long_long_and_overflow, METH_NOARGS, _testcapi_test_long_long_and_overflow__doc__},
+
+static PyObject *
+_testcapi_test_long_long_and_overflow_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_long_and_overflow(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_long_and_overflow_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_as_size_t__doc__,
+"test_long_as_size_t($module, /)\n"
+"--\n"
+"\n"
+"Test the PyLong_As{Size,Ssize}_t API.\n"
+"\n"
+"At present this just tests that non-integer arguments are handled correctly.\n"
+"It should be extended to test overflow handling.");
+
+#define _TESTCAPI_TEST_LONG_AS_SIZE_T_METHODDEF    \
+    {"test_long_as_size_t", (PyCFunction)_testcapi_test_long_as_size_t, METH_NOARGS, _testcapi_test_long_as_size_t__doc__},
+
+static PyObject *
+_testcapi_test_long_as_size_t_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_as_size_t(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_as_size_t_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_as_unsigned_long_long_mask__doc__,
+"test_long_as_unsigned_long_long_mask($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_TEST_LONG_AS_UNSIGNED_LONG_LONG_MASK_METHODDEF    \
+    {"test_long_as_unsigned_long_long_mask", (PyCFunction)_testcapi_test_long_as_unsigned_long_long_mask, METH_NOARGS, _testcapi_test_long_as_unsigned_long_long_mask__doc__},
+
+static PyObject *
+_testcapi_test_long_as_unsigned_long_long_mask_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_as_unsigned_long_long_mask(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_as_unsigned_long_long_mask_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_as_double__doc__,
+"test_long_as_double($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_TEST_LONG_AS_DOUBLE_METHODDEF    \
+    {"test_long_as_double", (PyCFunction)_testcapi_test_long_as_double, METH_NOARGS, _testcapi_test_long_as_double__doc__},
+
+static PyObject *
+_testcapi_test_long_as_double_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_as_double(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_as_double_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_test_long_numbits__doc__,
+"test_long_numbits($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_TEST_LONG_NUMBITS_METHODDEF    \
+    {"test_long_numbits", (PyCFunction)_testcapi_test_long_numbits, METH_NOARGS, _testcapi_test_long_numbits__doc__},
+
+static PyObject *
+_testcapi_test_long_numbits_impl(PyObject *module);
+
+static PyObject *
+_testcapi_test_long_numbits(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_test_long_numbits_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_call_long_compact_api__doc__,
+"call_long_compact_api($module, arg, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF    \
+    {"call_long_compact_api", (PyCFunction)_testcapi_call_long_compact_api, METH_O, _testcapi_call_long_compact_api__doc__},
+/*[clinic end generated code: output=d000a1b58fa81eab input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/long.c b/Modules/_testcapi/long.c
index 61dd96596dad..ede43f60d06f 100644
--- a/Modules/_testcapi/long.c
+++ b/Modules/_testcapi/long.c
@@ -1,4 +1,10 @@
 #include "parts.h"
+#include "clinic/long.c.h"
+
+/*[clinic input]
+module _testcapi
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/
 
 
 static PyObject *
@@ -40,8 +46,13 @@ raise_test_long_error(const char* msg)
 
 #include "testcapi_long.h"
 
+/*[clinic input]
+_testcapi.test_long_api
+[clinic start generated code]*/
+
 static PyObject *
-test_long_api(PyObject* self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_api_impl(PyObject *module)
+/*[clinic end generated code: output=4405798ca1e9f444 input=e9b8880d7331c688]*/
 {
     return TESTNAME(raise_test_long_error);
 }
@@ -68,8 +79,13 @@ raise_test_longlong_error(const char* msg)
 
 #include "testcapi_long.h"
 
+/*[clinic input]
+_testcapi.test_longlong_api
+[clinic start generated code]*/
+
 static PyObject *
-test_longlong_api(PyObject* self, PyObject *args)
+_testcapi_test_longlong_api_impl(PyObject *module)
+/*[clinic end generated code: output=2b3414ba8c31dfe6 input=ccbb2a48c2b3c4a5]*/
 {
     return TESTNAME(raise_test_longlong_error);
 }
@@ -81,13 +97,19 @@ test_longlong_api(PyObject* self, PyObject *args)
 #undef F_U_TO_PY
 #undef F_PY_TO_U
 
-/* 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.
-*/
+
+/*[clinic input]
+_testcapi.test_long_and_overflow
+
+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.
+[clinic start generated code]*/
 
 static PyObject *
-test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_and_overflow_impl(PyObject *module)
+/*[clinic end generated code: output=f8460ca115e31d8e input=762f6b62da0a3cdc]*/
 {
     PyObject *num, *one, *temp;
     long value;
@@ -243,13 +265,18 @@ test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
     Py_RETURN_NONE;
 }
 
-/* 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.
-*/
+/*[clinic input]
+_testcapi.test_long_long_and_overflow
+
+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.
+[clinic start generated code]*/
 
 static PyObject *
-test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_long_and_overflow_impl(PyObject *module)
+/*[clinic end generated code: output=0b92330786f45483 input=544bb0aefe5e8a9e]*/
 {
     PyObject *num, *one, *temp;
     long long value;
@@ -405,13 +432,18 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
     Py_RETURN_NONE;
 }
 
-/* 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.
- */
+/*[clinic input]
+_testcapi.test_long_as_size_t
+
+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.
+[clinic start generated code]*/
 
 static PyObject *
-test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_as_size_t_impl(PyObject *module)
+/*[clinic end generated code: output=f6490ea2b41e6173 input=922990c4a3edfb0d]*/
 {
     size_t out_u;
     Py_ssize_t out_s;
@@ -442,9 +474,13 @@ test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored))
     return Py_None;
 }
 
+/*[clinic input]
+_testcapi.test_long_as_unsigned_long_long_mask
+[clinic start generated code]*/
+
 static PyObject *
-test_long_as_unsigned_long_long_mask(PyObject *self,
-                                     PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_as_unsigned_long_long_mask_impl(PyObject *module)
+/*[clinic end generated code: output=e3e16cd0189440cc input=eb2438493ae7b9af]*/
 {
     unsigned long long res = PyLong_AsUnsignedLongLongMask(NULL);
 
@@ -462,12 +498,13 @@ test_long_as_unsigned_long_long_mask(PyObject *self,
     Py_RETURN_NONE;
 }
 
-/* Test the PyLong_AsDouble API. At present this just tests that
-   non-integer arguments are handled correctly.
- */
+/*[clinic input]
+_testcapi.test_long_as_double
+[clinic start generated code]*/
 
 static PyObject *
-test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_as_double_impl(PyObject *module)
+/*[clinic end generated code: output=deca0898e15adde5 input=c77bc88ef5a1de76]*/
 {
     double out;
 
@@ -487,9 +524,13 @@ test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored))
     return Py_None;
 }
 
-/* Simple test of _PyLong_NumBits and _PyLong_Sign. */
+/*[clinic input]
+_testcapi.test_long_numbits
+[clinic start generated code]*/
+
 static PyObject *
-test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_test_long_numbits_impl(PyObject *module)
+/*[clinic end generated code: output=9eaf8458cb15d7f7 input=265c02d48a13059e]*/
 {
     struct triple {
         long input;
@@ -534,8 +575,16 @@ test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored))
     Py_RETURN_NONE;
 }
 
+/*[clinic input]
+_testcapi.call_long_compact_api
+    arg: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-check_long_compact_api(PyObject *self, PyObject *arg)
+_testcapi_call_long_compact_api(PyObject *module, PyObject *arg)
+/*[clinic end generated code: output=7e3894f611b1b2b7 input=87b87396967af14c]*/
+
 {
     assert(PyLong_Check(arg));
     int is_compact = PyUnstable_Long_IsCompact((PyLongObject*)arg);
@@ -547,15 +596,15 @@ check_long_compact_api(PyObject *self, PyObject *arg)
 }
 
 static PyMethodDef test_methods[] = {
-    {"test_long_and_overflow",  test_long_and_overflow,          METH_NOARGS},
-    {"test_long_api",           test_long_api,                   METH_NOARGS},
-    {"test_long_as_double",     test_long_as_double,             METH_NOARGS},
-    {"test_long_as_size_t",     test_long_as_size_t,             METH_NOARGS},
-    {"test_long_as_unsigned_long_long_mask", test_long_as_unsigned_long_long_mask, METH_NOARGS},
-    {"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},
+    _TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF
+    _TESTCAPI_TEST_LONG_API_METHODDEF
+    _TESTCAPI_TEST_LONG_AS_DOUBLE_METHODDEF
+    _TESTCAPI_TEST_LONG_AS_SIZE_T_METHODDEF
+    _TESTCAPI_TEST_LONG_AS_UNSIGNED_LONG_LONG_MASK_METHODDEF
+    _TESTCAPI_TEST_LONG_LONG_AND_OVERFLOW_METHODDEF
+    _TESTCAPI_TEST_LONG_NUMBITS_METHODDEF
+    _TESTCAPI_TEST_LONGLONG_API_METHODDEF
+    _TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF
     {NULL},
 };
 



More information about the Python-checkins mailing list