[M3commit] [M3devel] Fwd: Strange code in Rd.CharsReady

Rodney M. Bates rodney_bates at lcwb.coop
Tue Dec 12 18:27:11 CET 2017


Looking at this briefly,

This change is mine, and yes, it is a bug.  But I am doubtful that just reverting
it will fix without introducing other problems.  If you are not reading any
Unicode or doing multi-character ungets, it will probably be fine.

This change appears in several other places, where it is necessary (and correct, I think)
to support multi-character unget, which in turn is needed for Unicode, since a single
code point can be encoded in up to 4 bytes, and another reason I don't recall off hand.
CharsReady needs to be different to avoid blocking.

I'll be looking at it more as I get time.

On 12/10/2017 03:19 PM, Mika Nystrom wrote:
> not sure the list allows my other email address to email to it...
>
> ---------- Forwarded message ----------
> From: *Mika Nystrom* <mika at alum.mit.edu <mailto:mika at alum.mit.edu>>
> Date: Sun, Dec 10, 2017 at 1:07 PM
> Subject: Strange code in Rd.CharsReady
> To: m3devel at elegosoft.com <mailto:m3devel at elegosoft.com>
>
>
> Hello m3devel,
>
> Long time no see!
>
> I am trying to resurrect some old code I have, and I have run into a strange issue.
>
> According to
>
> https://github.com/modula3/cm3/blame/master/m3-libs/libm3/src/rw/Rd.m3 <https://github.com/modula3/cm3/blame/master/m3-libs/libm3/src/rw/Rd.m3>
>
> the current source code for the routine Rd.CharsReady is as follows below.
>
> I am truly suspicious of line 389, which says it comes from some Unicode merge.
>
> IF NextBuff (rd) THEN RETURN 1 END (*line 389*)
>
> I have a program that misbehaves.
>
> This program appears to be BLOCKING in CharsReady.  This behavior obviously defeats the purpose of CharsReady.  I can't seem to cut and paste the traceback for some reason but it's calling Rd__NextBuff at line 151 and further then to ConnRW__RdSeek  with dontBlock FALSE (so "OK to block") and then SchedulerPosix__AlertWait.
>
> The old version of line 389 I believe was
>
> IF rd.seek(rd.cur, TRUE) = SeekResult.Eof THEN RETURN 1 END
>
> where TRUE means "don't block".
>
> Can someone tell me the rationale for the change and whether I am correct if I say that the new version is wrong?
>
> I am wonder how this change could even have gotten into the code in the first place if it's causing CharsReady to block, seems like a pretty obvious bug and I don't see a reason for tthe change in the first place.
>
> Mika
>
>
>
> PROCEDURE CharsReady(rd: T): CARDINAL
> 383
> RAISES {Failure} =
> @hosking <https://github.com/hosking>
> Hide warning. <https://github.com/modula3/cm3/commit/dbbcc11269c5aa10a13a61572e67a78cb03a7030>
> 3 years ago
> <https://github.com/modula3/cm3/blame/7032bc21f3fa31450a6600b61de7f0523516309f/m3-libs/libm3/src/rw/Rd.m3>
> 384
> <*FATAL Thread.Alerted*>
> @jaykrell <https://github.com/jaykrell>
> initial diff from ../config/PPC_LINUX <https://github.com/modula3/cm3/commit/2412437e3043bdfcb5f13463b5b445c78aeb4c9b>
> 10 years ago
> 385
> BEGIN
> @RodneyBates <https://github.com/RodneyBates>
> Merge Unicode branch into head. For a summary of the changes, see <https://github.com/modula3/cm3/commit/ea494d1b46c34a6c4c805322cfe6b1c02bfb2bf0>
> 4 years ago
> <https://github.com/modula3/cm3/blame/e5a6e4ae7feabce4e375a1445ea28dc66a174d58/m3-libs/libm3/src/rw/Rd.m3>
> 386
> LOCK rd DO
> @jaykrell <https://github.com/jaykrell>
> initial diff from ../config/PPC_LINUX <https://github.com/modula3/cm3/commit/2412437e3043bdfcb5f13463b5b445c78aeb4c9b>
> 10 years ago
> 387
> IF rd.cur = rd.hi THEN
> 388
> IF rd.closed THEN Die() END;
> @RodneyBates <https://github.com/RodneyBates>
> Merge Unicode branch into head. For a summary of the changes, see <https://github.com/modula3/cm3/commit/ea494d1b46c34a6c4c805322cfe6b1c02bfb2bf0>
> 4 years ago
> <https://github.com/modula3/cm3/blame/e5a6e4ae7feabce4e375a1445ea28dc66a174d58/m3-libs/libm3/src/rw/Rd.m3>
> 389
> IF NextBuff (rd) THEN RETURN 1 END
> @jaykrell <https://github.com/jaykrell>
> initial diff from ../config/PPC_LINUX <https://github.com/modula3/cm3/commit/2412437e3043bdfcb5f13463b5b445c78aeb4c9b>
> 10 years ago
> 390
> END;
> 391
> RETURN rd.hi - rd.cur;
> @RodneyBates <https://github.com/RodneyBates>
> Merge Unicode branch into head. For a summary of the changes, see <https://github.com/modula3/cm3/commit/ea494d1b46c34a6c4c805322cfe6b1c02bfb2bf0>
> 4 years ago
> <https://github.com/modula3/cm3/blame/e5a6e4ae7feabce4e375a1445ea28dc66a174d58/m3-libs/libm3/src/rw/Rd.m3>
> 392
> END;
> @jaykrell <https://github.com/jaykrell>
> initial diff from ../config/PPC_LINUX <https://github.com/modula3/cm3/commit/2412437e3043bdfcb5f13463b5b445c78aeb4c9b>
> 10 years ago
> 393
> END CharsReady;
>
>
>
>
>
>
>
> _______________________________________________
> M3devel mailing list
> M3devel at elegosoft.com
> https://m3lists.elegosoft.com/mailman/listinfo/m3devel
>

-- 
Rodney Bates
rodney.m.bates at acm.org


More information about the M3commit mailing list