comp.lang.ada
 help / color / mirror / Atom feed
From: Natasha Kerensikova <lithiumcat@instinctive.eu>
Subject: Type_Invariant and Finalize
Date: Thu, 17 Jul 2014 18:15:26 +0000 (UTC)
Date: 2014-07-17T18:15:26+00:00	[thread overview]
Message-ID: <slrnlsg4lu.i0l.lithiumcat@nat.rebma.instinctive.eu> (raw)

Hello,

I have been trying out the new contrat-oriented aspects on Ada 2012, and
wondered how Type_Invariant interacts with user-defined finalization.

I have several types for which a Type_Invariant makes sense (and is
often already mostly implemented the old-fashionned way, with pragma
Assert at the end of subprograms), except after the first call to
Finalize.

The latest example is a sorted array of non-null
paccess-to-indefinite-type values, where the "sortedness" is a natural
type inveriant, but in Finalize I release the memory using an instance
of Unchecked_Deallocation.

I'm already a bit uneasy with not having "not null except after
Finalize" access types, but in the example above after the first call to
Finalize I get an array of either null or invalid access values, and the
natural type invariant can't be computed.

Searching through the ARM, I can't see any special treatment of the
Finalize procedure with regard to Type_Invariant aspect, so presumably
the type inveriant is also checked at the end of Finalize.

Have I missed something that allows Finalize to make an object not fit
the type invariant?

Or should I prepare for it, e.g. with an explicit boolean record
component that is False for the most of the lifetime of the object,
until the first call to Finalize?


Thanks in advance for your insights,
Natasha

             reply	other threads:[~2014-07-17 18:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 18:15 Natasha Kerensikova [this message]
2014-07-17 20:49 ` Type_Invariant and Finalize Simon Wright
2014-07-18  6:56   ` Natasha Kerensikova
2014-07-18 21:48     ` Robert A Duff
2014-07-17 21:30 ` Type_Invariant and instance creation (was: Type_Invariant and Finalize) Simon Wright
2014-07-21 23:29   ` Randy Brukardt
2014-07-22  1:13     ` Type_Invariant and instance creation Shark8
replies disabled

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