From: Simon Wright <simon@pushface.org>
Subject: Re: Streams and abnormality
Date: Tue, 12 Jun 2012 20:49:23 +0100
Date: 2012-06-12T20:49:23+01:00 [thread overview]
Message-ID: <m2lijsjoos.fsf@pushface.org> (raw)
In-Reply-To: b05bd568-3d76-4816-ad25-95bb8175b802@googlegroups.com
Adam Beneschan <adam@irvine.com> writes:
> On Tuesday, June 12, 2012 10:32:00 AM UTC-7, Simon Wright wrote:
>
>
>> Looking at the AI[2], I must say I don't see quite where the
>> "discriminants or if the component_declaration has a default_expression"
>> comes from.
>
> Well, the wording was there in the first version of Ada 95 (AI95-195
> didn't change it). !summary 7 has to do with discriminants that don't
> match when 'Read is called, the discriminants have default expressions
> (otherwise they're not read from the stream), and the actual parameter
> is constrained. It doesn't address the issue of invalid
> representations.
>
> In RM12, the wording will be changed to "for each scalar component
> that is a discriminant or that has an implicit initial value". But I
> think this indicates that the wording was deliberate. I don't know
> why it was important to specify this for components with default
> expressions (or implicit initial values), and the Ada 95 Rationale
> doesn't say. Anyway, your thinking that maybe they meant that it
> applies only to discriminants with default expressions, doesn't make
> sense; it has to apply to all discriminants, because the discriminant
> could be used to control a variant part, and reading a discriminant
> with an invalid value is going to wreak havoc regardless of whether it
> has a default expression.
>
> -- Adam
>
>> It looks to me as though this should have read "discriminants whose
>> component_declaration has a default_expression" (see !summary 7).
Yes, I see. But nevertheless it seems that maybe the result of 'Input
(or 'Read) needn't be checked in the case of a bare scalar.
Would it be actually wrong for a compiler to check (in its default
mode)? Looks like it ("For other components, no check is made.").
Anyway, I'm writing an Ada implementation of Message_Pack[1]; since I'm
not re-implementing 'Read or 'Input, I have to check values read from
the stream.
A Message_Pack stream contains items, where an item consists of an
item-type byte followed, possibly, by more data; for example, 8388608
(2**23) would be {0xd2, 0x0, 0x80, 0x0, 0x0} ("int32" type byte, 4 bytes
of big-endian data).
Considering the (generic) code to read an integer type (range <>), I was
thinking that if the item-type byte doesn't correspond to an integer
value - for example, it might be 0xc2, false - I would raise Data_Error,
whereas if the integral value read wouldn't match the required
constraints I'd raise Constraint_Error. Does that seem reasonable?
[1] http://msgpack.org
next prev parent reply other threads:[~2012-06-14 19:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-12 9:31 Streams and abnormality Simon Wright
2012-06-12 15:01 ` Adam Beneschan
2012-06-12 17:03 ` Dmitry A. Kazakov
2012-06-12 17:32 ` Simon Wright
2012-06-12 18:06 ` Adam Beneschan
2012-06-12 19:49 ` Simon Wright [this message]
2012-06-21 18:29 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox