Skip to content

scan(..., skip=1e11): infinite loop; cannot interrupt

1 message · Suharto Anggono Suharto Anggono

#
With

?if?(!j--)?{
?????R_CheckUserInterrupt();
?????j?=?10000;
?}

as?in?current?R?devel?(r83976),?j goes negative (-1) and interrupt is checked every 10001 instead of 10000. I?prefer

?if?(!--j)?{
?????R_CheckUserInterrupt();
?????j?=?10000;
?}

.


In?current?R?devel?(r83976),?if?EOF?is?reached,?the?outer?loop?keeps?going,?i?keeps?incrementing?until?nskip.

The?outer?loop?could?be?made?to?also?stop?on?EOF.

Alternatively,?not?using?nested?loop?is?possible,?like?the?following.

?if?(nskip)?for?(R_xlen_t?i?=?0,?j?=?10000;?;?)?{?/*?MBCS-safe?*/
?c?=?scanchar(FALSE,?&data);
?if?(!j--)?{
?????R_CheckUserInterrupt();
?????j?=?10000;
?}
?if?((c?==?'\n'?&&?++i?==?nskip)?||?c?==?R_EOF)
?????break;
?}


-----------
On?2/11/23?09:33,?Ivan?Krylov?wrote:
Thanks,?I've?updated?the?implementation?of?scan()?in?R-devel?to?be
interruptible?while?skipping?lines.

I've?done?it?slightly?differently?as?I?found?there?already?was?a?memory
leak,?which?could?be?fixed?by?creating?the?context?a?bit?earlier.

I've?also?avoided?modulo?on?the?fast?path?as?I?saw?13%?performance
overhead?on?my?mailbox?file.?Decrementing?and?checking?against?zero
didn't?have?measurable?overhead.

Best
Tomas

[snip]