[M3devel] Unnecessary(?) range confusion in ThreadPosix.m3
Mika Nystrom
mika at async.caltech.edu
Sat Oct 25 05:16:56 CEST 2008
Dear Modula-3 people,
I had a crash in my program from a range error that I believe
shouldn't have happened the way it did, although it's not in my
code, so I'm not sure if there's a reason for the way it's done (matching
a C declaration somewhere, maybe??).
Here it is, from ThreadPosix.m3:
PROCEDURE IOWait(fd: INTEGER; read: BOOLEAN;
timeoutInterval: LONGREAL := -1.0D0): WaitResult =
<*FATAL Alerted*>
BEGIN
self.alertable := FALSE;
RETURN XIOWait(fd, read, timeoutInterval);
END IOWait;
PROCEDURE IOAlertWait(fd: INTEGER; read: BOOLEAN;
timeoutInterval: LONGREAL := -1.0D0): WaitResult
RAISES {Alerted} =
BEGIN
self.alertable := TRUE;
RETURN XIOWait(fd, read, timeoutInterval);
END IOAlertWait;
PROCEDURE XIOWait (fd: CARDINAL; read: BOOLEAN; interval: LONGREAL): WaitResult
RAISES {Alerted} =
VAR res: INTEGER;
fdindex := fd DIV FDSetSize;
fdset := FDSet{fd MOD FDSetSize};
... rest omitted ...
Note that IOWait calls XIOWait. IOWait is declared as taking an
INTEGER, but XIOWait takes a CARDINAL.
So I really should use a CARDINAL in passing to IOWait, but since
IOWait is the interface function it's not clear that I should do
that (until my program crashes after passing -1 from some carelessly
wrapped C code). I don't like the fact that I get a range error
*inside* the library when it appears unnecessary---it should have
happened in my code, as I make the call.
Suggested improvement: declare all the FDs in SchedulerPosix.i3
(the interface that exports these routines) to be CARDINAL instead
of INTEGER.
Mika
More information about the M3devel
mailing list