Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The road to hell is paved with NAND gates. -- J. Gooding


devel / comp.lang.ada / Valid attribute and input operations

SubjectAuthor
* Valid attribute and input operationsMaciej Sobczak
`* Re: Valid attribute and input operationsJeffrey R.Carter
 `* Re: Valid attribute and input operationsRandy Brukardt
  `* Re: Valid attribute and input operationsNiklas Holsti
   `- Re: Valid attribute and input operationsRandy Brukardt

1
Valid attribute and input operations

<22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10106&group=comp.lang.ada#10106

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:5983:0:b0:655:baed:c94b with SMTP id ek3-20020ad45983000000b00655baedc94bmr41486qvb.0.1695500530508;
Sat, 23 Sep 2023 13:22:10 -0700 (PDT)
X-Received: by 2002:a05:6870:1aad:b0:1d6:4b44:a3d0 with SMTP id
ef45-20020a0568701aad00b001d64b44a3d0mr1277667oab.6.1695500530351; Sat, 23
Sep 2023 13:22:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 23 Sep 2023 13:22:09 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=213.108.152.51; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S
NNTP-Posting-Host: 213.108.152.51
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
Subject: Valid attribute and input operations
From: see.my.homepage@gmail.com (Maciej Sobczak)
Injection-Date: Sat, 23 Sep 2023 20:22:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2858
 by: Maciej Sobczak - Sat, 23 Sep 2023 20:22 UTC

Hi there,

I am in the middle of a heated debate with Richard Riehle on LinkedIn, where we cannot get to terms with regard to the exact semantics of X'Valid in the context of input operations performed by standard Get procedure.
In short, consider the following example:

with Ada.Text_IO;
with Ada.Integer_Text_IO;
procedure Is_Valid_Test is
X : Integer range 0..200;
begin
Ada.Text_IO.Put("Get an Integer: ");
Ada.Integer_Text_IO.Get(X);
if X'Valid then
Ada.Text_IO.Put_Line("The Input is Valid ");
else
Ada.Text_IO.Put_Line("The Input is not Valid ");
end if;
end Is_Valid_Test;

When the input is 500, what should be the behavior of this program?
There are two interpretations:

1. Get is an input operation and can create invalid representations (as stated in 13.9.2, p.7). Then, the X'Valid test that follows Get(X) can be used to safely recognize whether the value is in the range or not. The program should print the second string (from the else branch), but should not raise any exceptions for this input (500).

2. Get is not an input operation in the meaning referred to in 13.9.2/7, or is an input, but only for type Integer (and it cannot create invalid integer representations on typical computers anyway). The X variable is an actual parameter that has a subtype that is different from the formal parameter and is subject to conversions when the Get subprogram exits normally (6.4.1/17,17a). This conversion should raise Constraint_Error for this input (500).

I have checked the above program on several on-line compilers, all of them behave according to interpretation 2 above.
Richard claims to get behavior 1 on his compiler.

What is your take on this? Any language lawyers?

Regards,
Maciej Sobczak

Re: Valid attribute and input operations

<uenmg1$qctd$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10107&group=comp.lang.ada#10107

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Valid attribute and input operations
Date: Sat, 23 Sep 2023 23:48:49 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uenmg1$qctd$1@dont-email.me>
References: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 21:48:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a668e66705aa660e13291e0b6dc9ea64";
logging-data="865197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I1GAt8eflnghpTF8RIQ2tMfXSXoN9Nbk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:QMJwwsQ7PaSe+nDT8C89BOiIwVE=
In-Reply-To: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Sat, 23 Sep 2023 21:48 UTC

On 2023-09-23 22:22, Maciej Sobczak wrote:
>
> I have checked the above program on several on-line compilers, all of them behave according to interpretation 2 above.
> Richard claims to get behavior 1 on his compiler.
>
> What is your take on this? Any language lawyers?

The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM
A.10.8(7-10)]:

"... skips any leading blanks, line terminators, or page terminators, then reads
a plus sign if present or (for a signed type only) a minus sign if present, then
reads the longest possible sequence of characters matching the syntax of a
numeric literal without a point. ...

"Returns, in the parameter Item, the value of type Num that corresponds to the
sequence input.

"The exception Data_Error is propagated if the sequence of characters read does
not form a legal integer literal or if the value obtained is not of the subtype
Num."

So a call to Get can only return a valid value of type Num (Integer for your
case) or raise Data_Error.

If Get is reading "500" then that certainly represents a valid value of type
Integer, and Get should copy that back to the actual parameter.

If you are using Ada (a language with run-time checks), then a check should be
made that the value is in the range of the actual parameter's subtype, here
Integer range 0 .. 200. That should fail and Constraint_Error should be raised.

However, if you are not using Ada because that check has been suppressed, then
the actual parameter will be left with the invalid value 500 and
Constraint_Error will not be raised.

If I build your program with checks enabled, I get Constraint_Error. If I build
it with checks suppressed, I get the not-valid message (GNAT 12.3).

--
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32

Re: Valid attribute and input operations

<uetsq8$2cgii$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10127&group=comp.lang.ada#10127

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Valid attribute and input operations
Date: Tue, 26 Sep 2023 01:13:53 -0500
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <uetsq8$2cgii$1@dont-email.me>
References: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com> <uenmg1$qctd$1@dont-email.me>
Injection-Date: Tue, 26 Sep 2023 06:13:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f0a5cbfd923c9b47a54100ea42585311";
logging-data="2507346"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TSD/jCRP9gq79mekMvs/KUhh72baZV7k="
Cancel-Lock: sha1:3hV/YpMy5WAE/7r1zl0kTtw/bCY=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-RFC2646: Format=Flowed; Response
X-MSMail-Priority: Normal
 by: Randy Brukardt - Tue, 26 Sep 2023 06:13 UTC

I believe Jeffrey's analysis is correct.

Note that there are some special cases for validity that are intended to
make it easier to write code like that you have. But they only make sense
for base subtypes (and the type you have is not that). Moreover, they are
not foolproof -- exceution is not erroneous in these cases, but they still
are a bounded error, and it is always correct for a bounded error to be
detected and raise Program_Error.

This can happen in practice, too. For instance, for Janus/Ada, enumeration
types with specified representations operate internally on the position
numbers, and thus reading an enumeration variable will convert the
representation to a position number with a table lookup. If the lookup
fails, Program_Error is raised, and that happens before the value ever can
be assigned to a named variable (and thus before any possible test of
validity). I believe that we identified other similar cases back in the day.
Probably one of them is the signalling NaN. Some bit patterns for float
values represent signalling NaNs, which trap instantly if read. That's at
the hardware level on most processors, so the only hope is the handle the
resulting exception. It's too late by the time you get to 'Valid.

Moral: to make truly bulletproof code, you have to handle exceptions AND use
'Valid. You probably can skip the exceptions if everything is typed with
integer basetypes, but if any other kinds of types are involved, they are
necessary.

Randy.

"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message
news:uenmg1$qctd$1@dont-email.me...
> On 2023-09-23 22:22, Maciej Sobczak wrote:
>>
>> I have checked the above program on several on-line compilers, all of
>> them behave according to interpretation 2 above.
>> Richard claims to get behavior 1 on his compiler.
>>
>> What is your take on this? Any language lawyers?
>
> The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM
> A.10.8(7-10)]:
>
> "... skips any leading blanks, line terminators, or page terminators, then
> reads a plus sign if present or (for a signed type only) a minus sign if
> present, then reads the longest possible sequence of characters matching
> the syntax of a numeric literal without a point. ...
>
> "Returns, in the parameter Item, the value of type Num that corresponds to
> the sequence input.
>
> "The exception Data_Error is propagated if the sequence of characters read
> does not form a legal integer literal or if the value obtained is not of
> the subtype Num."
>
> So a call to Get can only return a valid value of type Num (Integer for
> your case) or raise Data_Error.
>
> If Get is reading "500" then that certainly represents a valid value of
> type Integer, and Get should copy that back to the actual parameter.
>
> If you are using Ada (a language with run-time checks), then a check
> should be made that the value is in the range of the actual parameter's
> subtype, here Integer range 0 .. 200. That should fail and
> Constraint_Error should be raised.
>
> However, if you are not using Ada because that check has been suppressed,
> then the actual parameter will be left with the invalid value 500 and
> Constraint_Error will not be raised.
>
> If I build your program with checks enabled, I get Constraint_Error. If I
> build it with checks suppressed, I get the not-valid message (GNAT 12.3).
>
> --
> Jeff Carter
> "If you don't get the President of the United States on that
> phone, ... you're going to have to answer to the Coca-Cola
> Company."
> Dr. Strangelove
> 32
>

Re: Valid attribute and input operations

<knff56Fdjg6U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10129&group=comp.lang.ada#10129

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Valid attribute and input operations
Date: Tue, 26 Sep 2023 10:22:14 +0300
Organization: Tidorum Ltd
Lines: 30
Message-ID: <knff56Fdjg6U1@mid.individual.net>
References: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
<uenmg1$qctd$1@dont-email.me> <uetsq8$2cgii$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net uM7TAkFEDMtp4tZ3MGuJnw4Dvk0CX9bc44XKhpB3HbAPNSy5zg
Cancel-Lock: sha1:kExowTF0CE+/D0uNgrzoYi5QoqQ= sha256:hXcqadZsOJHwem7y5jVPWPVQZze2GhItDAVKwEKKOao=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.12.0
Content-Language: en-US
In-Reply-To: <uetsq8$2cgii$1@dont-email.me>
 by: Niklas Holsti - Tue, 26 Sep 2023 07:22 UTC

On 2023-09-26 9:13, Randy Brukardt wrote:

> ... for Janus/Ada, enumeration types with specified representations
> operate internally on the position numbers

Hm, that's interesting. Is that also the representation for record
components of such an enumerated type?

For example, if I have:

type Command is (Off, On) with Size => 4;
for Command use (Off => 2, On => 5);
type Two_Commands is record
C1, C2: Command;
end record
with Pack, Size => 8;

TwoC : Two_Commands := (C1 => On, C2 => Off);

will the record components (in memory) have the values C1 = 1 and C2 = 0
(position numbers) or C1 = 5, C2 = 2 (specified representation)?

If they are represented by position numbers in the record, many if not
most of my embedded Ada programs would fail if compiled with Janus/Ada,
because the record values stored in I/O control registers or accessed
via DMA would be wrong.

Damn, I thought those programs were not so compiler-dependent :-(

Re: Valid attribute and input operations

<uf2rql$3h3dr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10138&group=comp.lang.ada#10138

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Valid attribute and input operations
Date: Wed, 27 Sep 2023 22:27:41 -0500
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <uf2rql$3h3dr$1@dont-email.me>
References: <22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com> <uenmg1$qctd$1@dont-email.me> <uetsq8$2cgii$1@dont-email.me> <knff56Fdjg6U1@mid.individual.net>
Injection-Date: Thu, 28 Sep 2023 03:27:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4260f7b3e8705760fb05d2d372cfaa1b";
logging-data="3706299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CBjyojJ/kizPBThXnjeS4NMFyR+Z9i3Q="
Cancel-Lock: sha1:orBFv7V6t11Hh3T0A90Aq03ATLQ=
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
 by: Randy Brukardt - Thu, 28 Sep 2023 03:27 UTC

No, the specified representation is always used when storing to memory (with
the single exception of loop parameters, which cannot have address clauses
or other representation specifications). I think even enum parameters are
written in the representation. However, any time an enumeration value is
read into a register it is converted to a position number. Usually, such
values are used in indexing, comparing, or an attribute like 'Pos or 'Succ,
all of which are defined to work on position numbers. But if you simply
assign the value out again, it will get converted both ways. We do have an
optimization to remove pairs of TOREP/DEREP, but not the reverse since
Program_Error is a possibility from DEREP. (Well, unless unsafe
optimizations are on, but I don't recommend using those for the obvious
reasons.)

Randy.

"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message
news:knff56Fdjg6U1@mid.individual.net...
> On 2023-09-26 9:13, Randy Brukardt wrote:
>
>> ... for Janus/Ada, enumeration types with specified representations
>> operate internally on the position numbers
>
>
> Hm, that's interesting. Is that also the representation for record
> components of such an enumerated type?
>
> For example, if I have:
>
> type Command is (Off, On) with Size => 4;
> for Command use (Off => 2, On => 5);
> type Two_Commands is record
> C1, C2: Command;
> end record
> with Pack, Size => 8;
>
> TwoC : Two_Commands := (C1 => On, C2 => Off);
>
> will the record components (in memory) have the values C1 = 1 and C2 = 0
> (position numbers) or C1 = 5, C2 = 2 (specified representation)?
>
> If they are represented by position numbers in the record, many if not
> most of my embedded Ada programs would fail if compiled with Janus/Ada,
> because the record values stored in I/O control registers or accessed via
> DMA would be wrong.
>
> Damn, I thought those programs were not so compiler-dependent :-(
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor