comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using Class wide types as factories, is this legit?
Date: Tue, 23 Sep 2014 21:28:55 +0200
Date: 2014-09-23T21:28:55+02:00	[thread overview]
Message-ID: <1ow7xs34a7j7z.1f0806cgaoh7r$.dlg@40tude.net> (raw)
In-Reply-To: 4a7d6542-d4c1-4d79-8def-d4b74e06dacd@googlegroups.com

On Tue, 23 Sep 2014 01:21:58 -0700 (PDT), David Botton wrote:

>> It is hard to say without seeing Initialize, Finalize and Adjust. I would
>> guess that Adjust is wrong, e.g. not making a deep copy of the things
>> killed in Finalize, which may lead to deallocating these twice in the first
>> variant of your code.
> 
> There is no adjust or finalize. Initialize looks like this:
> 
>    procedure Initialize (Object : in out Active_Record) is
>       use Gnoga.Server.Database;
>    begin
>       if Object.Connection = null then
>          raise Connection_Error;
>       end if;
> 
>       Object.Fields :=
>         Object.Connection.List_Fields_Of_Table
>           (Object.Table_Name.all);
>    end Initialize;

You should check controlled components as well.

For debugging, create a controlled type Foo with Initialize, Finalize,
Adjust printing some texts. Insert a member of this type at different
places of the record to determine which component causes crash. Type's
Finalize is called before finalization of components, type's Initialize is
called after initialization of components. Use GNAT.Most_Recent_Exception
to determine of the problem is secondary happens upon exception
propagation. Very often finalization issues hide the actual problem. Use
GNAT.Exception_Traces to find exceptions that silently kill the program.

Regarding your design. The rule of thumb is that controlled and other
copyable objects shall not have access discriminants.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  reply	other threads:[~2014-09-23 19:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23  5:19 Using Class wide types as factories, is this legit? David Botton
2014-09-23  7:23 ` Dmitry A. Kazakov
2014-09-23  8:21   ` David Botton
2014-09-23 19:28     ` Dmitry A. Kazakov [this message]
2014-09-23 21:27       ` David Botton
2014-09-24  7:22         ` Dmitry A. Kazakov
2014-09-23  8:37   ` briot.emmanuel
2014-09-23  8:52     ` David Botton
replies disabled

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