comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Modes (was unbounded_string)
Date: Mon, 13 Oct 2003 12:12:43 +0200
Date: 2003-10-13T12:12:43+02:00	[thread overview]
Message-ID: <8etkov82e5et9d9m58i806mbt73odg4t96@4ax.com> (raw)
In-Reply-To: rquib.4914$zw4.1688@nwrdny01.gnilink.net

On Mon, 13 Oct 2003 09:40:39 GMT, "Stephane Richard"
<stephane.richard@verizon.net> wrote:

>"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>news:94skovca8efqisiip65q37of63g28n1284@4ax.com...
>> On Fri, 10 Oct 2003 19:06:00 GMT, Jeffrey Carter <spam@spam.com>
>> wrote:
>>
>> >Since GNAT.OS_Lib.Getenv returns type String_Access, you have to use
>> >String_Access if you want to use Getenv. But note the description of
>> >Getenv from GNAT.OS_Lib:
>> >
>> >--  Get the value of the environment variable. Returns an access
>> >--  to the empty string if the environment variable does not exist
>> >--  or has an explicit null value (in some operating systems these
>> >--  are distinct cases, in others they are not; this interface
>> >--  abstracts away that difference. The argument is allocated on
>> >--  the heap (even in the null case), and needs to be freed explicitly
>> >--  when no longer needed to avoid memory leaks.
>>
>> Awful, I didn't expected that from ACT. The design above is definitely
>> not Ada's idiom.
>>
>> ---
>> Regards,
>> Dmitry Kazakov
>> www.dmitry-kazakov.de
>
>Perhaps as in many OS it's the only way as the OS (probably written in C or
>some other language simply returns it this way?

In which way? Neither Win32 nor UNIX getenv require to call free on
the result. It just returns a pointer to some chunk of memory which
probably cannot be deallocated at all. Then even if a particular OS
requires further deallocation then it is not Ada's deallocation. It is
freeing resources, which has nothing to do with calling a deallocator
on the result. If a resource has to be freed then we either

1. return a copy and free the resource before return;

2. return a controlled object, which will free the resource upon
destruction.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-10-13 10:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20031010074015.761204C40C1@lovelace.ada-france.org>
2003-10-10  8:27 ` Modes (was unbounded_string) Andrew Carroll
2003-10-10  9:15   ` Dmitry A. Kazakov
2003-10-11  7:16     ` Simon Wright
2003-10-13  9:28       ` Dmitry A. Kazakov
2003-10-10 15:18   ` Stephen Leake
2003-10-10 16:21     ` Martin Dowie
2003-10-14 18:47     ` Craig Carey
2003-10-10 19:06   ` Jeffrey Carter
2003-10-13  9:33     ` Dmitry A. Kazakov
2003-10-13  9:40       ` Stephane Richard
2003-10-13 10:12         ` Dmitry A. Kazakov [this message]
2003-10-15  2:16         ` Warren W. Gay VE3WWG
2003-10-15  3:36           ` Jeff C,
2003-10-16 16:45             ` Warren W. Gay VE3WWG
     [not found] <20031010094017.680474C40C1@lovelace.ada-france.org>
2003-10-10 10:58 ` Andrew Carroll
replies disabled

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