comp.lang.ada
 help / color / mirror / Atom feed
From: Craig Carey <research@ijs.co.nz>
Subject: Re: C's trikery semantic opens up backdoor in new Linux kernel
Date: Tue, 25 Nov 2003 23:06:52 +1300
Date: 2003-11-25T23:06:52+13:00	[thread overview]
Message-ID: <8776svslu9qqo4tp7mump5car7m5asa1fb@4ax.com> (raw)
In-Reply-To: sma9rvssreln3i6ft2kgsg16imis4ra95c@4ax.com

On Fri, 14 Nov 2003 11:16:22 +0100, Dmitry A. Kazakov wrote:
>On Fri, 14 Nov 2003 10:44:47 +0100, Vinzent 'Gadget' Hoefler wrote:
...
>>>On Fri, 14 Nov 2003 10:04:02 +1300
>>>Craig Carey <research@ijs.co.nz> wrote:
...
>>>> Ada 95 could be enhanced so that specified record fields could be
>>>> read-only.
>>
>>BTW, this is a neat idea. OTOH, for this approach to be practical
>>someone *must* have write access.
>
>1. Not always. We already have constant "record" fields in Ada. They
>are called discriminants.
>2. Constructor
...

1. Perhaps Mr Kazakov would priovide more details about the
 "Not Always" comment.It could be the default assignment of a pointer
  pointing into the interior of the same record.

2. Since Ada 95 lacks read-only fields, so would the "We" of the
  message I reply to.

A solution is to replace field "X : Integer" with

  X  : Integer_Access_Constant_Ptr
  XA : Private_Type_Supposedly_Integer;

Maybe the record has to the tagged to get the pointer initialized.
It is awkward inide of the package and outside too.

All external statements like this

       "if X.Denom /= Y.Denom .."

would be changed to

       "if X.Denom.all /= Y.Denom.all".

A better solution might be to make every field be read-only, and
then remove read-only statuse from fields only by one.

The package is rewritten so that its procedures expect an
"access constant" pointer to the record, instead of record.

   Data_ZZZ : aliased P.D_Priv_Rec;      --  Real record, don't use
   Data     : constant P.D_Type := Data_ZZZX'Access;  --  100% R/O

To write to a single field, dereference a pointer function. E.g.:

   Ptr_Field_Bigness (X).all := (3, 2);

ObjectAda compiler easily finds that discriminants are not the
hoped for read-only feature:

   -------------
   type num is
      record
         Num, Den : Integer;
      end record;

   type Arbitrary (Pool_Const : Num) is      --  <-- Invalid Ada
      record
         Arb   : Num;
      end record;

      --   ObjectAda 7.2.2 says  "Error: LRM:3.7(9), the subtype of a
      --    discriminant must be a discrete or access subtype"
      --  [or defined using "access subtype_mark"].
   -------------

Discrimannts are not actually read-only since they don't need to be
supplied when the variable is declared but can be changed simply
afterwards. It does not sound like something that is read-only.


Craig Carey
Ada mailing lists: http://www.ijs.co.nz/ada_95.htm




  reply	other threads:[~2003-11-25 10:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-12  3:17 C's trikery semantic opens up backdoor in new Linux kernel Adrian Hoe
2003-11-12  4:26 ` Stephane Richard
2003-11-12  5:13   ` J Cusick
2003-11-12  7:18     ` Vinzent 'Gadget' Hoefler
2003-11-12  7:50       ` Duncan Sands
2003-11-12 12:08         ` Vinzent 'Gadget' Hoefler
2003-11-12 13:38           ` Duncan Sands
2003-11-12 14:09             ` Vinzent 'Gadget' Hoefler
2003-11-13 21:04               ` Craig Carey
2003-11-14  6:45                 ` Freejack
2003-11-14  8:33                 ` Erlo Haugen
2003-11-14  9:44                   ` Vinzent 'Gadget' Hoefler
2003-11-14 10:16                     ` Dmitry A. Kazakov
2003-11-25 10:06                       ` Craig Carey [this message]
2003-11-25 11:20                         ` Dmitry A. Kazakov
2003-11-14 15:31                 ` Robert I. Eachus
2003-11-14 13:12               ` Georg Bauhaus
2003-11-14 13:31                 ` Duncan Sands
2003-11-14 14:56                 ` Vinzent 'Gadget' Hoefler
2003-11-14 15:08                   ` Georg Bauhaus
2003-11-14 15:38                     ` Duncan Sands
2003-11-14 17:57                       ` Georg Bauhaus
2003-11-14 15:47               ` Robert I. Eachus
2003-11-14 16:38                 ` Vinzent 'Gadget' Hoefler
2003-11-19  4:13             ` Dave Thompson
2003-11-21 15:34               ` Martin Krischik
2003-11-23  2:20                 ` Hyman Rosen
2003-11-27  4:22                 ` Dave Thompson
2003-11-28 14:01                   ` Hyman Rosen
2003-11-12 17:37       ` tmoran
2003-11-12 18:03       ` Warren W. Gay VE3WWG
2003-11-12  8:51     ` Adrian Hoe
2003-11-12 12:32       ` Preben Randhol
2003-11-13  5:50         ` Chad R. Meiners
2003-11-12 22:59       ` Wes Groleau
2003-11-14  3:31         ` Adrian Hoe
2003-11-14 11:00           ` Dmytry Lavrov
2003-11-15  5:00             ` Adrian Hoe
2003-11-15  5:02             ` Adrian Hoe
2003-11-16 11:29               ` Dmytry Lavrov
2003-11-17 17:07                 ` Warren W. Gay VE3WWG
2003-11-16 11:35             ` Dmytry Lavrov
2003-11-15 19:30           ` Wes Groleau
2003-11-12  8:52   ` Adrian Hoe
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox