3333
3434#include "clinic/_testinternalcapi.c.h"
3535
36- #ifdef MS_WINDOWS
37- # include <winsock2.h> // struct timeval
38- #endif
36+ // Include test definitions from _testinternalcapi/
37+ #include "_testinternalcapi/parts.h"
3938
4039
4140#define MODULE_NAME "_testinternalcapi"
@@ -1123,250 +1122,6 @@ pending_identify(PyObject *self, PyObject *args)
11231122 return res ;
11241123}
11251124
1126-
1127- static PyObject *
1128- test_pytime_fromseconds (PyObject * self , PyObject * args )
1129- {
1130- int seconds ;
1131- if (!PyArg_ParseTuple (args , "i" , & seconds )) {
1132- return NULL ;
1133- }
1134- _PyTime_t ts = _PyTime_FromSeconds (seconds );
1135- return _PyTime_AsNanosecondsObject (ts );
1136- }
1137-
1138- static int
1139- check_time_rounding (int round )
1140- {
1141- if (round != _PyTime_ROUND_FLOOR
1142- && round != _PyTime_ROUND_CEILING
1143- && round != _PyTime_ROUND_HALF_EVEN
1144- && round != _PyTime_ROUND_UP )
1145- {
1146- PyErr_SetString (PyExc_ValueError , "invalid rounding" );
1147- return -1 ;
1148- }
1149- return 0 ;
1150- }
1151-
1152- static PyObject *
1153- test_pytime_fromsecondsobject (PyObject * self , PyObject * args )
1154- {
1155- PyObject * obj ;
1156- int round ;
1157- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1158- return NULL ;
1159- }
1160- if (check_time_rounding (round ) < 0 ) {
1161- return NULL ;
1162- }
1163- _PyTime_t ts ;
1164- if (_PyTime_FromSecondsObject (& ts , obj , round ) == -1 ) {
1165- return NULL ;
1166- }
1167- return _PyTime_AsNanosecondsObject (ts );
1168- }
1169-
1170- static PyObject *
1171- test_pytime_assecondsdouble (PyObject * self , PyObject * args )
1172- {
1173- PyObject * obj ;
1174- if (!PyArg_ParseTuple (args , "O" , & obj )) {
1175- return NULL ;
1176- }
1177- _PyTime_t ts ;
1178- if (_PyTime_FromNanosecondsObject (& ts , obj ) < 0 ) {
1179- return NULL ;
1180- }
1181- double d = _PyTime_AsSecondsDouble (ts );
1182- return PyFloat_FromDouble (d );
1183- }
1184-
1185- static PyObject *
1186- test_PyTime_AsTimeval (PyObject * self , PyObject * args )
1187- {
1188- PyObject * obj ;
1189- int round ;
1190- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1191- return NULL ;
1192- }
1193- if (check_time_rounding (round ) < 0 ) {
1194- return NULL ;
1195- }
1196- _PyTime_t t ;
1197- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1198- return NULL ;
1199- }
1200- struct timeval tv ;
1201- if (_PyTime_AsTimeval (t , & tv , round ) < 0 ) {
1202- return NULL ;
1203- }
1204-
1205- PyObject * seconds = PyLong_FromLongLong (tv .tv_sec );
1206- if (seconds == NULL ) {
1207- return NULL ;
1208- }
1209- return Py_BuildValue ("Nl" , seconds , (long )tv .tv_usec );
1210- }
1211-
1212- static PyObject *
1213- test_PyTime_AsTimeval_clamp (PyObject * self , PyObject * args )
1214- {
1215- PyObject * obj ;
1216- int round ;
1217- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1218- return NULL ;
1219- }
1220- if (check_time_rounding (round ) < 0 ) {
1221- return NULL ;
1222- }
1223- _PyTime_t t ;
1224- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1225- return NULL ;
1226- }
1227- struct timeval tv ;
1228- _PyTime_AsTimeval_clamp (t , & tv , round );
1229-
1230- PyObject * seconds = PyLong_FromLongLong (tv .tv_sec );
1231- if (seconds == NULL ) {
1232- return NULL ;
1233- }
1234- return Py_BuildValue ("Nl" , seconds , (long )tv .tv_usec );
1235- }
1236-
1237- #ifdef HAVE_CLOCK_GETTIME
1238- static PyObject *
1239- test_PyTime_AsTimespec (PyObject * self , PyObject * args )
1240- {
1241- PyObject * obj ;
1242- if (!PyArg_ParseTuple (args , "O" , & obj )) {
1243- return NULL ;
1244- }
1245- _PyTime_t t ;
1246- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1247- return NULL ;
1248- }
1249- struct timespec ts ;
1250- if (_PyTime_AsTimespec (t , & ts ) == -1 ) {
1251- return NULL ;
1252- }
1253- return Py_BuildValue ("Nl" , _PyLong_FromTime_t (ts .tv_sec ), ts .tv_nsec );
1254- }
1255-
1256- static PyObject *
1257- test_PyTime_AsTimespec_clamp (PyObject * self , PyObject * args )
1258- {
1259- PyObject * obj ;
1260- if (!PyArg_ParseTuple (args , "O" , & obj )) {
1261- return NULL ;
1262- }
1263- _PyTime_t t ;
1264- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1265- return NULL ;
1266- }
1267- struct timespec ts ;
1268- _PyTime_AsTimespec_clamp (t , & ts );
1269- return Py_BuildValue ("Nl" , _PyLong_FromTime_t (ts .tv_sec ), ts .tv_nsec );
1270- }
1271- #endif
1272-
1273- static PyObject *
1274- test_PyTime_AsMilliseconds (PyObject * self , PyObject * args )
1275- {
1276- PyObject * obj ;
1277- int round ;
1278- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1279- return NULL ;
1280- }
1281- _PyTime_t t ;
1282- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1283- return NULL ;
1284- }
1285- if (check_time_rounding (round ) < 0 ) {
1286- return NULL ;
1287- }
1288- _PyTime_t ms = _PyTime_AsMilliseconds (t , round );
1289- _PyTime_t ns = _PyTime_FromNanoseconds (ms );
1290- return _PyTime_AsNanosecondsObject (ns );
1291- }
1292-
1293- static PyObject *
1294- test_PyTime_AsMicroseconds (PyObject * self , PyObject * args )
1295- {
1296- PyObject * obj ;
1297- int round ;
1298- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1299- return NULL ;
1300- }
1301- _PyTime_t t ;
1302- if (_PyTime_FromNanosecondsObject (& t , obj ) < 0 ) {
1303- return NULL ;
1304- }
1305- if (check_time_rounding (round ) < 0 ) {
1306- return NULL ;
1307- }
1308- _PyTime_t us = _PyTime_AsMicroseconds (t , round );
1309- _PyTime_t ns = _PyTime_FromNanoseconds (us );
1310- return _PyTime_AsNanosecondsObject (ns );
1311- }
1312-
1313- static PyObject *
1314- test_pytime_object_to_time_t (PyObject * self , PyObject * args )
1315- {
1316- PyObject * obj ;
1317- time_t sec ;
1318- int round ;
1319- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1320- return NULL ;
1321- }
1322- if (check_time_rounding (round ) < 0 ) {
1323- return NULL ;
1324- }
1325- if (_PyTime_ObjectToTime_t (obj , & sec , round ) == -1 ) {
1326- return NULL ;
1327- }
1328- return _PyLong_FromTime_t (sec );
1329- }
1330-
1331- static PyObject *
1332- test_pytime_object_to_timeval (PyObject * self , PyObject * args )
1333- {
1334- PyObject * obj ;
1335- time_t sec ;
1336- long usec ;
1337- int round ;
1338- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1339- return NULL ;
1340- }
1341- if (check_time_rounding (round ) < 0 ) {
1342- return NULL ;
1343- }
1344- if (_PyTime_ObjectToTimeval (obj , & sec , & usec , round ) == -1 ) {
1345- return NULL ;
1346- }
1347- return Py_BuildValue ("Nl" , _PyLong_FromTime_t (sec ), usec );
1348- }
1349-
1350- static PyObject *
1351- test_pytime_object_to_timespec (PyObject * self , PyObject * args )
1352- {
1353- PyObject * obj ;
1354- time_t sec ;
1355- long nsec ;
1356- int round ;
1357- if (!PyArg_ParseTuple (args , "Oi" , & obj , & round )) {
1358- return NULL ;
1359- }
1360- if (check_time_rounding (round ) < 0 ) {
1361- return NULL ;
1362- }
1363- if (_PyTime_ObjectToTimespec (obj , & sec , & nsec , round ) == -1 ) {
1364- return NULL ;
1365- }
1366- return Py_BuildValue ("Nl" , _PyLong_FromTime_t (sec ), nsec );
1367- }
1368-
1369-
13701125static PyObject *
13711126tracemalloc_get_traceback (PyObject * self , PyObject * args )
13721127{
@@ -1731,20 +1486,6 @@ static PyMethodDef module_functions[] = {
17311486 {"pending_threadfunc" , _PyCFunction_CAST (pending_threadfunc ),
17321487 METH_VARARGS | METH_KEYWORDS },
17331488 {"pending_identify" , pending_identify , METH_VARARGS , NULL },
1734- {"_PyTime_AsMicroseconds" , test_PyTime_AsMicroseconds , METH_VARARGS },
1735- {"_PyTime_AsMilliseconds" , test_PyTime_AsMilliseconds , METH_VARARGS },
1736- {"_PyTime_AsSecondsDouble" , test_pytime_assecondsdouble , METH_VARARGS },
1737- #ifdef HAVE_CLOCK_GETTIME
1738- {"_PyTime_AsTimespec" , test_PyTime_AsTimespec , METH_VARARGS },
1739- {"_PyTime_AsTimespec_clamp" , test_PyTime_AsTimespec_clamp , METH_VARARGS },
1740- #endif
1741- {"_PyTime_AsTimeval" , test_PyTime_AsTimeval , METH_VARARGS },
1742- {"_PyTime_AsTimeval_clamp" , test_PyTime_AsTimeval_clamp , METH_VARARGS },
1743- {"_PyTime_FromSeconds" , test_pytime_fromseconds , METH_VARARGS },
1744- {"_PyTime_FromSecondsObject" , test_pytime_fromsecondsobject , METH_VARARGS },
1745- {"_PyTime_ObjectToTime_t" , test_pytime_object_to_time_t , METH_VARARGS },
1746- {"_PyTime_ObjectToTimespec" , test_pytime_object_to_timespec , METH_VARARGS },
1747- {"_PyTime_ObjectToTimeval" , test_pytime_object_to_timeval , METH_VARARGS },
17481489 {"_PyTraceMalloc_GetTraceback" , tracemalloc_get_traceback , METH_VARARGS },
17491490 {"test_tstate_capi" , test_tstate_capi , METH_NOARGS , NULL },
17501491 {"_PyUnicode_TransformDecimalAndSpaceToASCII" , unicode_transformdecimalandspacetoascii , METH_O },
@@ -1771,6 +1512,10 @@ static PyMethodDef module_functions[] = {
17711512static int
17721513module_exec (PyObject * module )
17731514{
1515+ if (_PyTestInternalCapi_Init_PyTime (module ) < 0 ) {
1516+ return 1 ;
1517+ }
1518+
17741519 if (PyModule_Add (module , "SIZEOF_PYGC_HEAD" ,
17751520 PyLong_FromSsize_t (sizeof (PyGC_Head ))) < 0 ) {
17761521 return 1 ;
0 commit comments