@@ -37,6 +37,9 @@ raise_test_long_error(const char* msg)
3737 return raiseTestError ("test_long_api" , msg );
3838}
3939
40+ // Test PyLong_FromLong()/PyLong_AsLong()
41+ // and PyLong_FromUnsignedLong()/PyLong_AsUnsignedLong().
42+
4043#define TESTNAME test_long_api_inner
4144#define TYPENAME long
4245#define F_S_TO_PY PyLong_FromLong
@@ -64,6 +67,9 @@ _testcapi_test_long_api_impl(PyObject *module)
6467#undef F_U_TO_PY
6568#undef F_PY_TO_U
6669
70+ // Test PyLong_FromLongLong()/PyLong_AsLongLong()
71+ // and PyLong_FromUnsignedLongLong()/PyLong_AsUnsignedLongLong().
72+
6773static PyObject *
6874raise_test_longlong_error (const char * msg )
6975{
@@ -595,6 +601,24 @@ _testcapi_call_long_compact_api(PyObject *module, PyObject *arg)
595601 return Py_BuildValue ("in" , is_compact , value );
596602}
597603
604+ /*[clinic input]
605+ _testcapi.PyLong_AsInt
606+ arg: object
607+ /
608+ [clinic start generated code]*/
609+
610+ static PyObject *
611+ _testcapi_PyLong_AsInt (PyObject * module , PyObject * arg )
612+ /*[clinic end generated code: output=0df9f19de5fa575b input=9561b97105493a67]*/
613+ {
614+ assert (!PyErr_Occurred ());
615+ int value = PyLong_AsInt (arg );
616+ if (value == -1 && PyErr_Occurred ()) {
617+ return NULL ;
618+ }
619+ return PyLong_FromLong (value );
620+ }
621+
598622static PyMethodDef test_methods [] = {
599623 _TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF
600624 _TESTCAPI_TEST_LONG_API_METHODDEF
@@ -605,6 +629,7 @@ static PyMethodDef test_methods[] = {
605629 _TESTCAPI_TEST_LONG_NUMBITS_METHODDEF
606630 _TESTCAPI_TEST_LONGLONG_API_METHODDEF
607631 _TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF
632+ _TESTCAPI_PYLONG_ASINT_METHODDEF
608633 {NULL },
609634};
610635
0 commit comments