[M3devel] Text processing

Mika Nystrom mika at async.caltech.edu
Tue Apr 28 18:55:00 CEST 2009


I think whenever Modula-3 TEXTs are represented as arrays (including
*all* m3 TEXTs in SRC and P M3), there's a null at the end.

It's not included in the "length of the string" but obviously it
*is* included in the "length of the array".  That's precisely the
source of the bug.  The old version allocates "length of string
plus one", which is the wrong number to pass to the new interfaces
(which don't expose the trailing zero, but keep it, just the same).

Yes, the idea is you can pass Modula-3 TEXTs freely (cheaply) to C
routines.  Well, you used to be able to, before TEXTs were "improved"
by Critical Mass.  The code would have been something like this...?

IMPORT TextF;

    VAR txt : TEXT;
    ...
    some_c_function(ADR(txt[0]))
    ...

No I don't miss this feature much.  There are other improvements that
bug me a lot more.  But this is all about to be fixed with the new
Text implementation, right? :-)

     Mika

Jay writes:
>
>Are the nulls included in the length?
> 
>If so, that'd be a likely bug. If not, it'd be a /possible/ feature. Seriously
>.
>I deal with "lengthed" strings a lot, but my "duplicate" and "concat" function
>s add them, and don't put them in the length, for interop with all the other c
>ode out there..
>But it is a little sleazy my pattern and we do have explicit functions for C i
>nterop.
> 
> 
> - Jay
>
>
>----------------------------------------
>> To: rcoleburn at scires.com
>> Date: Tue, 28 Apr 2009 09:26:24 -0700
>> From: mika at async.caltech.edu
>> CC: m3devel at elegosoft.com
>> Subject: Re: [M3devel] Text processing
>>
>> Hmm cm3ide has its own Wx. It doesn't use that? It looks different
>> from the standard one in cm3.
>>
>> In the *standard* one, that is, m3-libs/libbuf/src/Wx.m3,
>> the fix is the following:
>>
>> PROCEDURE ToText (t: T): TEXT =
>> VAR txt := Text8.Create(t.nFull * ChunkSize + t.next);
>> c := t.head; n := 0;
>> BEGIN
>>
>> There used to be a "+ 1" in the call to Text8.Create. It's crud
>> from converting from the old array TEXTs.
>>
>> I've already checked this in to the cm3 distribution.
>>
>> Mika
>>
>> "Randy Coleburn" writes:
>>>This is a MIME message. If you are reading this text, you may want to
>>>consider changing to a mail reader or gateway that understands how to
>>>properly handle MIME multipart messages.
>>>
>>>--=__Part6C44DF9F.0__=
>>>Content-Type: text/plain; charset=US-ASCII
>>>Content-Transfer-Encoding: quoted-printable
>>>
>>>There is a bug in CM3IDE that may be the result of this problem. I'll =
>>>need to get your fix and try it.
>>>--Randy
>>>
>>>>>> Mika Nystrom 4/28/2009 11:36 AM>>>
>>>
>>>Speaking of text processing, I was very surprised at the bug I found
>>>in Wx the other day (and checked in a fix for). I'm 99% certain my
>>>fix is correct, but I'm very surprised no one found this bug before.
>>>
>>>Wx was inserting spurious nulls at the end of every generated TEXT.
>>>
>>>Is it possible someone is using this interface and depending on the
>>>buggy behavior? m3ide and m3browser import it.
>>>
>>> Mika
>>>
>>>
>>>CONFIDENTIALITY NOTICE: This email and any attachments are intended =
>>>solely for the use of the named recipient(s). This e-mail may contain =
>>>confidential and/or proprietary information of Scientific Research =
>>>Corporation. If you are not a named recipient, you are prohibited from =
>>>making any use of the information in the email and attachments. If you =
>>>believe you have received this email in error, please notify the sender =
>>>immediately and permanently delete the email, any attachments, and all =
>>>copies thereof from any drives or storage media and destroy any printouts =
>>>of the email or attachments.
>>>
>>>EXPORT COMPLIANCE NOTICE: This email and any attachments may contain =
>>>technical data subject to U.S export restrictions under the International =
>>>Traffic in Arms Regulations (ITAR) or the Export Administration Regulations=
>>> (EAR). Export or transfer of this technical data and/or related =
>>>information to any foreign person(s) or entity(ies), either within the =
>>>U.S. or outside of the U.S., may require export authorization by the =
>>>appropriate U.S. Government agency prior to export or transfer. In =
>>>addition, technical data may not be exported or transferred to certain =
>>>countries or specified designated nationals identified by U.S. embargo =
>>>controls without prior export authorization. By accepting this email and =
>>>any attachments, all recipients confirm that they understand and will =
>>>comply with all applicable ITAR, EAR and embargo compliance requirements.
>>>
>>>
>>>--=__Part6C44DF9F.0__=
>>>Content-Type: text/html; charset=US-ASCII
>>>Content-Transfer-Encoding: quoted-printable
>>>Content-Description: HTML
>>>
>>>
>>>>>">
>>>
>
>>>
>>>
>There is a bug in CM3IDE that may be the result of this problem. =
>>> I'll need to get your fix and try it.
>>>
>--Randy
>
>>>> Mika Nystrom =
>>>; 4/28/2009 11:36 AM>>>
>
>Speaking of text processing, I =
>>>was very surprised at the bug I found
>in Wx the other day (and checked =
>>>in a fix for).  I'm 99% certain my
>fix is correct, but I'm very =
>>>surprised no one found this bug before.
>
>Wx was inserting spurious =
>>>nulls at the end of every generated TEXT.
>
>Is it possible someone is =
>>>using this interface and depending on the
>buggy behavior?  m3ide =
>>>and m3browser import it.
>
>     Mika
>
>=
>>>
>>>
>>>--=__Part6C44DF9F.0__=--



More information about the M3devel mailing list