comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@NoSpam.cogeco.ca>
Subject: Re: GNAT Ada.Streams Bug?
Date: Thu, 25 Nov 2004 23:11:04 -0500
Date: 2004-11-25T23:11:04-05:00	[thread overview]
Message-ID: <z0ypd.16283$14.192@read1.cgocable.net> (raw)
In-Reply-To: <Myqpd.565108$mD.208023@attbi_s02>

Jeff C r e e.m wrote:
> "Warren W. Gay VE3WWG" <ve3wwg@NoSPAM.cogeco.ca> wrote in message 
> news:fOopd.59177$Le1.1221311@news20.bellglobal.com...
> 
>>This is on gnat-3.14p on debian (debian's package library doesn't
>>seem to provide 3.15p), so this may be fixed by now:
>>
>>I am running into a Ada.Streams problem with 24 bit values (3 bytes).
>>For example, if you use Ada.Streams to read in a partition table,
>>defined as follows, with 3.14p, you'll read more bytes than needed
>>(thus messing things up):
> 
> These might be helpful
> 
> http://groups.google.com/groups?hl=en&lr=&threadm=t3f6rg54jlkfee%40corp.supernews.com&rnum=2&prev=/groups%3Fq%3Dstreams%2Bcreem%2Bsize%26hl%3Den%26lr%3D%26selm%3Dt3f6rg54jlkfee%2540corp.supernews.com%26rnum%3D2
> 
> http://groups.google.com/groups?q=streams+creem+size&hl=en&lr=&selm=t739enmlcvuo2d%40corp.supernews.com&rnum=1
> 
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00270.TXT?rev=1.6

Interesting. So the bug is in the RM ;-)

> In any case, you can "work around" this and get more efficient code to boot 
> by writing your own 'read and 'write for  your record to read the whole
> "hunk" of data in at once (based on the 'size of the record in terms of 
> stream elements).

I am not concerned at all about the efficiency of this case, as you
read the partition 4 times at boot time (less if you have fewer disks).
I know however, that you were stating the more general case.

It is disappointing to learn that basically Ada95 is "portability
busted" when it comes to Ada.Streams. As Randy (I think) mentioned
in the AI link, it is very difficult to adapt a stream to external
formats - more impossible to be compiler independent at the same
time. Since I am trying to interface a stream to the boot sector,
this becomes a real problem that I'll have to "work around".

This is real disappointing for someone doing O/S work.
C code bypasses any difficulty here, because you just
give read(2) a pointer (essentially Var'Address) and tell it
how many bytes to deposit there. Type is not checked, lengths
not checked etc. Dangerous, and of course you could resort
to this same technique in Ada as well.

In Ada95 however, you don't want a custom Read routine for
every O/S type you create (else you have to resign
yourself to a small set of unsigned types and dispense
with one of advantages of strong typing). You also don't
want to do "conversions" all over the place. Finally,
generic adapters would be too many and Unchecked_Conversion
is not efficient or pleasant. So what to do?

STREAMS lets you do your I/O in a safe, but strongly typed
way. It seems like the right thing to do. It seems that
for GNAT and Intel, you can work around it if you are
careful. For some platforms however, where the base
types for all types are 32 bits, this sounds impossible.

Based upon the links you provided, THERE IS HOPE in
Ada200Y for Streams. I welcome those changes.

The point about efficiency is also a good one to raise. For
example, if you String'Read(Stream,Var), GNAT calls the
'Read routine for each and every Character of the string.
One pines for something more efficient than this, and I
hope for the day when this improves in GNAT. (hint)

Thanks for the links.

wwg.
--
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg



  reply	other threads:[~2004-11-26  4:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-25 17:41 GNAT Ada.Streams Bug? Warren W. Gay VE3WWG
2004-11-25 19:40 ` Jeff C r e e.m
2004-11-26  4:11   ` Warren W. Gay VE3WWG [this message]
2004-11-26  9:49     ` Georg Bauhaus
2004-11-26 17:30       ` Warren W. Gay VE3WWG
2004-11-27  7:34         ` Martin Krischik
2004-11-28  1:10           ` Warren W. Gay VE3WWG
2004-11-29  7:50         ` tmoran
2004-11-29 17:47           ` Warren W. Gay VE3WWG
2004-11-26 22:47     ` Simon Wright
2004-11-27 14:42       ` Warren W. Gay VE3WWG
2004-11-27 17:25         ` Simon Wright
replies disabled

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