@@ -37,6 +37,9 @@ raise_test_long_error(const char* msg)
37
37
return raiseTestError ("test_long_api" , msg );
38
38
}
39
39
40
+ // Test PyLong_FromLong()/PyLong_AsLong()
41
+ // and PyLong_FromUnsignedLong()/PyLong_AsUnsignedLong().
42
+
40
43
#define TESTNAME test_long_api_inner
41
44
#define TYPENAME long
42
45
#define F_S_TO_PY PyLong_FromLong
@@ -64,6 +67,9 @@ _testcapi_test_long_api_impl(PyObject *module)
64
67
#undef F_U_TO_PY
65
68
#undef F_PY_TO_U
66
69
70
+ // Test PyLong_FromLongLong()/PyLong_AsLongLong()
71
+ // and PyLong_FromUnsignedLongLong()/PyLong_AsUnsignedLongLong().
72
+
67
73
static PyObject *
68
74
raise_test_longlong_error (const char * msg )
69
75
{
@@ -595,6 +601,24 @@ _testcapi_call_long_compact_api(PyObject *module, PyObject *arg)
595
601
return Py_BuildValue ("in" , is_compact , value );
596
602
}
597
603
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
+
598
622
static PyMethodDef test_methods [] = {
599
623
_TESTCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF
600
624
_TESTCAPI_TEST_LONG_API_METHODDEF
@@ -605,6 +629,7 @@ static PyMethodDef test_methods[] = {
605
629
_TESTCAPI_TEST_LONG_NUMBITS_METHODDEF
606
630
_TESTCAPI_TEST_LONGLONG_API_METHODDEF
607
631
_TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF
632
+ _TESTCAPI_PYLONG_ASINT_METHODDEF
608
633
{NULL },
609
634
};
610
635
0 commit comments