On Fri, 4 Mar 2022, Riccardo (Jack) Lucchetti wrote:
I just pushed to git a micro-fix to avoid the sleep() function
freezing
gretl.
Try for example
<hansl>
sleep(-1)
sleep(0.1)
</hansl>
now it's fixed (the first case is equivalent to sleep(0)).
Hmm, I'd be more inclined to flag an error if the argument to
sleep() is negative. We should probably also flag an error if the
argument to sleep would result in overflow of the "unsigned long"
argument to the underlying function, g_usleep(). As in:
<C>
double secs = node_get_scalar(n, p);
if (secs < 0 || secs * G_USEC_PER_SEC > G_MAXULONG) {
p->err = E_INVARG;
} else {
g_usleep(G_USEC_PER_SEC * secs);
ret->v.xval = 0;
}
</C>
And if we retain your modification to allow a general scalar
argument (rather than an integer) for sleep() -- which seems fine to
me if there's an overflow guard in place -- the doc for sleep should
be modified accordingly.
I can do that, or go ahead if you prefer.
Allin