mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 02:15:10 +00:00 
			
		
		
		
	gh-104469: Convert _testcapi/long to use AC (gh-104720)
This commit is contained in:
		
							parent
							
								
									abdda5b133
								
							
						
					
					
						commit
						76170f5458
					
				
					 2 changed files with 250 additions and 35 deletions
				
			
		
							
								
								
									
										166
									
								
								Modules/_testcapi/clinic/long.c.h
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								Modules/_testcapi/clinic/long.c.h
									
										
									
										generated
									
									
									
										Normal file
									
								
							|  | @ -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]*/ | ||||||
|  | @ -1,4 +1,10 @@ | ||||||
| #include "parts.h" | #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 * | static PyObject * | ||||||
|  | @ -40,8 +46,13 @@ raise_test_long_error(const char* msg) | ||||||
| 
 | 
 | ||||||
| #include "testcapi_long.h" | #include "testcapi_long.h" | ||||||
| 
 | 
 | ||||||
|  | /*[clinic input]
 | ||||||
|  | _testcapi.test_long_api | ||||||
|  | [clinic start generated code]*/ | ||||||
|  | 
 | ||||||
| static PyObject * | 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); |     return TESTNAME(raise_test_long_error); | ||||||
| } | } | ||||||
|  | @ -68,8 +79,13 @@ raise_test_longlong_error(const char* msg) | ||||||
| 
 | 
 | ||||||
| #include "testcapi_long.h" | #include "testcapi_long.h" | ||||||
| 
 | 
 | ||||||
|  | /*[clinic input]
 | ||||||
|  | _testcapi.test_longlong_api | ||||||
|  | [clinic start generated code]*/ | ||||||
|  | 
 | ||||||
| static PyObject * | 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); |     return TESTNAME(raise_test_longlong_error); | ||||||
| } | } | ||||||
|  | @ -81,13 +97,19 @@ test_longlong_api(PyObject* self, PyObject *args) | ||||||
| #undef F_U_TO_PY | #undef F_U_TO_PY | ||||||
| #undef F_PY_TO_U | #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 | /*[clinic input]
 | ||||||
|    handling of overflow. | _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 * | 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; |     PyObject *num, *one, *temp; | ||||||
|     long value; |     long value; | ||||||
|  | @ -243,13 +265,18 @@ test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||||||
|     Py_RETURN_NONE; |     Py_RETURN_NONE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Test the PyLong_AsLongLongAndOverflow API. General conversion to
 | /*[clinic input]
 | ||||||
|    long long is tested by test_long_api_inner. This test will | _testcapi.test_long_long_and_overflow | ||||||
|    concentrate on proper handling of 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 * | 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; |     PyObject *num, *one, *temp; | ||||||
|     long long value; |     long long value; | ||||||
|  | @ -405,13 +432,18 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||||||
|     Py_RETURN_NONE; |     Py_RETURN_NONE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Test the PyLong_As{Size,Ssize}_t API. At present this just tests that
 | /*[clinic input]
 | ||||||
|    non-integer arguments are handled correctly. It should be extended to | _testcapi.test_long_as_size_t | ||||||
|    test overflow handling. | 
 | ||||||
|  */ | 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 * | 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; |     size_t out_u; | ||||||
|     Py_ssize_t out_s; |     Py_ssize_t out_s; | ||||||
|  | @ -442,9 +474,13 @@ test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||||||
|     return Py_None; |     return Py_None; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*[clinic input]
 | ||||||
|  | _testcapi.test_long_as_unsigned_long_long_mask | ||||||
|  | [clinic start generated code]*/ | ||||||
|  | 
 | ||||||
| static PyObject * | static PyObject * | ||||||
| test_long_as_unsigned_long_long_mask(PyObject *self, | _testcapi_test_long_as_unsigned_long_long_mask_impl(PyObject *module) | ||||||
|                                      PyObject *Py_UNUSED(ignored)) | /*[clinic end generated code: output=e3e16cd0189440cc input=eb2438493ae7b9af]*/ | ||||||
| { | { | ||||||
|     unsigned long long res = PyLong_AsUnsignedLongLongMask(NULL); |     unsigned long long res = PyLong_AsUnsignedLongLongMask(NULL); | ||||||
| 
 | 
 | ||||||
|  | @ -462,12 +498,13 @@ test_long_as_unsigned_long_long_mask(PyObject *self, | ||||||
|     Py_RETURN_NONE; |     Py_RETURN_NONE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Test the PyLong_AsDouble API. At present this just tests that
 | /*[clinic input]
 | ||||||
|    non-integer arguments are handled correctly. | _testcapi.test_long_as_double | ||||||
|  */ | [clinic start generated code]*/ | ||||||
| 
 | 
 | ||||||
| static PyObject * | 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; |     double out; | ||||||
| 
 | 
 | ||||||
|  | @ -487,9 +524,13 @@ test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||||||
|     return Py_None; |     return Py_None; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Simple test of _PyLong_NumBits and _PyLong_Sign. */ | /*[clinic input]
 | ||||||
|  | _testcapi.test_long_numbits | ||||||
|  | [clinic start generated code]*/ | ||||||
|  | 
 | ||||||
| static PyObject * | 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 { |     struct triple { | ||||||
|         long input; |         long input; | ||||||
|  | @ -534,8 +575,16 @@ test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||||||
|     Py_RETURN_NONE; |     Py_RETURN_NONE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*[clinic input]
 | ||||||
|  | _testcapi.call_long_compact_api | ||||||
|  |     arg: object | ||||||
|  |     / | ||||||
|  | [clinic start generated code]*/ | ||||||
|  | 
 | ||||||
| static PyObject * | 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)); |     assert(PyLong_Check(arg)); | ||||||
|     int is_compact = PyUnstable_Long_IsCompact((PyLongObject*)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[] = { | static PyMethodDef test_methods[] = { | ||||||
|     {"test_long_and_overflow",  test_long_and_overflow,          METH_NOARGS}, |     _TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF | ||||||
|     {"test_long_api",           test_long_api,                   METH_NOARGS}, |     _TESTCAPI_TEST_LONG_API_METHODDEF | ||||||
|     {"test_long_as_double",     test_long_as_double,             METH_NOARGS}, |     _TESTCAPI_TEST_LONG_AS_DOUBLE_METHODDEF | ||||||
|     {"test_long_as_size_t",     test_long_as_size_t,             METH_NOARGS}, |     _TESTCAPI_TEST_LONG_AS_SIZE_T_METHODDEF | ||||||
|     {"test_long_as_unsigned_long_long_mask", test_long_as_unsigned_long_long_mask, METH_NOARGS}, |     _TESTCAPI_TEST_LONG_AS_UNSIGNED_LONG_LONG_MASK_METHODDEF | ||||||
|     {"test_long_long_and_overflow",test_long_long_and_overflow,  METH_NOARGS}, |     _TESTCAPI_TEST_LONG_LONG_AND_OVERFLOW_METHODDEF | ||||||
|     {"test_long_numbits",       test_long_numbits,               METH_NOARGS}, |     _TESTCAPI_TEST_LONG_NUMBITS_METHODDEF | ||||||
|     {"test_longlong_api",       test_longlong_api,               METH_NOARGS}, |     _TESTCAPI_TEST_LONGLONG_API_METHODDEF | ||||||
|     {"call_long_compact_api",   check_long_compact_api,          METH_O}, |     _TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF | ||||||
|     {NULL}, |     {NULL}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dong-hee Na
						Dong-hee Na