@@ -1313,17 +1313,21 @@ void
1313
1313
gettimeofday ()
1314
1314
PREINIT :
1315
1315
struct timeval Tp ;
1316
- PPCODE :
1317
1316
int status ;
1317
+ U8 is_G_LIST = GIMME_V == G_LIST ;
1318
+ PPCODE :
1319
+ if (is_G_LIST )
1320
+ EXTEND (sp , 2 );
1318
1321
status = gettimeofday (& Tp , NULL );
1319
1322
if (status == 0 ) {
1320
- if (GIMME_V == G_LIST ) {
1321
- EXTEND (sp , 2 );
1322
- PUSHs (sv_2mortal (newSViv (Tp .tv_sec )));
1323
- PUSHs (sv_2mortal (newSViv (Tp .tv_usec )));
1323
+ if (is_G_LIST ) { /* copy to registers to prove sv_2mortal/newSViv */
1324
+ IV sec = Tp .tv_sec ; /* can't modify the values */
1325
+ IV usec = Tp .tv_usec ;
1326
+ PUSHs (sv_2mortal (newSViv (sec )));
1327
+ PUSHs (sv_2mortal (newSViv (usec )));
1324
1328
} else {
1325
- EXTEND ( sp , 1 );
1326
- PUSHs (sv_2mortal (newSVnv (Tp . tv_sec + ( Tp . tv_usec / NV_1E6 ) )));
1329
+ NV nv = Tp . tv_sec + ( Tp . tv_usec / NV_1E6 );
1330
+ PUSHs (sv_2mortal (newSVnv (nv )));
1327
1331
}
1328
1332
}
1329
1333
@@ -1373,10 +1377,8 @@ setitimer(which, seconds, interval = 0)
1373
1377
*/
1374
1378
GCC_DIAG_IGNORE_CPP_COMPAT_STMT ;
1375
1379
if (setitimer (which , & newit , & oldit ) == 0 ) {
1376
- EXTEND (sp , 1 );
1377
1380
PUSHs (sv_2mortal (newSVnv (TV2NV (oldit .it_value ))));
1378
1381
if (GIMME_V == G_LIST ) {
1379
- EXTEND (sp , 1 );
1380
1382
PUSHs (sv_2mortal (newSVnv (TV2NV (oldit .it_interval ))));
1381
1383
}
1382
1384
}
@@ -1393,7 +1395,6 @@ getitimer(which)
1393
1395
*/
1394
1396
GCC_DIAG_IGNORE_CPP_COMPAT_STMT ;
1395
1397
if (getitimer (which , & nowit ) == 0 ) {
1396
- EXTEND (sp , 1 );
1397
1398
PUSHs (sv_2mortal (newSVnv (TV2NV (nowit .it_value ))));
1398
1399
if (GIMME_V == G_LIST ) {
1399
1400
EXTEND (sp , 1 );
@@ -1427,28 +1428,31 @@ PROTOTYPE: $$@
1427
1428
if ( accessed == & PL_sv_undef && modified == & PL_sv_undef )
1428
1429
utbufp = NULL ;
1429
1430
else {
1430
- if (SvNV (accessed ) < 0.0 || SvNV (modified ) < 0.0 )
1431
+ NV modified_nv = SvNV (modified );
1432
+ NV accessed_nv = SvNV (accessed );
1433
+ if (accessed_nv < 0.0 || modified_nv < 0.0 )
1431
1434
croak ("%s(%" NVgf ", %" NVgf "%s" , "Time::HiRes::utime" ,
1432
- SvNV ( accessed ), SvNV ( modified ) ,
1435
+ accessed_nv , modified_nv ,
1433
1436
"): negative time not invented yet" );
1434
1437
Zero (& utbuf , sizeof utbuf , char );
1435
1438
1436
- utbuf [0 ].tv_sec = (Time_t )SvNV ( accessed ) ; /* time accessed */
1439
+ utbuf [0 ].tv_sec = (Time_t )accessed_nv ; /* time accessed */
1437
1440
utbuf [0 ].tv_nsec = (long )(
1438
- (SvNV ( accessed ) - (NV )utbuf [0 ].tv_sec )
1441
+ (accessed_nv - (NV )utbuf [0 ].tv_sec )
1439
1442
* NV_1E9 + (NV )0.5 );
1440
1443
1441
- utbuf [1 ].tv_sec = (Time_t )SvNV ( modified ) ; /* time modified */
1444
+ utbuf [1 ].tv_sec = (Time_t )modified_nv ; /* time modified */
1442
1445
utbuf [1 ].tv_nsec = (long )(
1443
- (SvNV ( modified ) - (NV )utbuf [1 ].tv_sec )
1446
+ (modified_nv - (NV )utbuf [1 ].tv_sec )
1444
1447
* NV_1E9 + (NV )0.5 );
1445
1448
}
1446
1449
1447
1450
while (items > 0 ) {
1451
+ PerlIO * pio ;
1448
1452
file = POPs ; items -- ;
1449
1453
1450
- if (SvROK (file ) && GvIO (SvRV (file )) && IoIFP (sv_2io (SvRV (file )))) {
1451
- int fd = PerlIO_fileno (IoIFP ( sv_2io ( file )) );
1454
+ if (SvROK (file ) && GvIO (SvRV (file )) && ( pio = IoIFP (sv_2io (SvRV (file ) )))) {
1455
+ int fd = PerlIO_fileno (pio );
1452
1456
if (fd < 0 ) {
1453
1457
SETERRNO (EBADF ,RMS_IFI );
1454
1458
} else {
@@ -1469,7 +1473,7 @@ PROTOTYPE: $$@
1469
1473
# ifdef HAS_UTIMENSAT
1470
1474
if (UTIMENSAT_AVAILABLE ) {
1471
1475
STRLEN len ;
1472
- char * name = SvPV (file , len );
1476
+ const char * name = SvPV_const (file , len );
1473
1477
if (IS_SAFE_PATHNAME (name , len , "utime" ) &&
1474
1478
utimensat (AT_FDCWD , name , utbufp , 0 ) == 0 ) {
1475
1479
0 commit comments