comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types
Date: Fri, 28 Jan 2011 07:13:03 -0800 (PST)
Date: 2011-01-28T07:13:03-08:00	[thread overview]
Message-ID: <0dec16be-da2b-4b9e-afb8-285e8e6d8acb@g19g2000yqi.googlegroups.com> (raw)
In-Reply-To: 510d779c-d15b-4fc1-b831-bfc578ecdb4b@z3g2000prz.googlegroups.com

On Jan 27, 11:35 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:

> > Adjust is not called on limited objects.
>
> Yeah, sure. :-D

[...]

I have some more news on this.

Previously my observations were that:

> So, to summarise: yes, Adjust is randomly called on Controlled_Limited
> types and it even dispatches properly (wow!), and no, my own
> operations do not dispatch and instead something dummy gives me
> equally dummy results.

Interesting observation #2: my operation is the *third* primitive
operation of Some_Interface.

Interesting observation #3: Adjust is also the *third* primitive
operation of System.Finalization_Root.

Hm...

I have changed the order of declarations in my spec file, so that the
operation in question is now the *second* one.

Guess what? :-)

Now Finalize is called instead of Adjust. Yes, Finalize is the second
primitive operation in System.Finalization_Root.

It looks like the compiler has overwritten one virtual function table
with another one and since the operations have very similar
signatures, what happened is that the wrong operation was executed.

If anybody from AdaCore is reading this, please take the above as a
hint, I believe these observations are enough to show the proper
direction.

> But in addition to downcasting, there is an alternative solution which
> I have discovered later on, although have not yet tested.
> The idea is if I know the actual type (T) in the procedure that
> accepts base interface, then apparently I'm working with a closed set
> of types, which is actually true. So instead of relying on class-wide
> types and dispatching in this particular place I will add another
> version of the same operation that accepts T and operates on it.

It works. I will stick to this solution instead of "if X in T
then ..." as it is fully static instead of dynamic and it offers a
better granularity for later editing - I will just remove that
additional operation without touching the original one when the GNAT
bug is fixed.

Thanks to everybody who offered solution to my original problem.

--
Maciej Sobczak * http://www.inspirel.com



  parent reply	other threads:[~2011-01-28 15:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 15:46 Equivalent of dynamic_cast (downcast) for tagged types Maciej Sobczak
2011-01-27 16:18 ` Dmitry A. Kazakov
2011-01-27 17:10   ` J-P. Rosen
2011-01-27 17:35     ` Dmitry A. Kazakov
2011-01-27 22:49     ` Maciej Sobczak
2011-01-27 17:50   ` Georg Bauhaus
2011-01-27 22:35   ` Maciej Sobczak
2011-01-28  5:07     ` Yannick Duchêne (Hibou57)
2011-01-28  9:16     ` Dmitry A. Kazakov
2011-01-28 13:11       ` AdaMagica
2011-01-28 14:13         ` Dmitry A. Kazakov
2011-01-28 23:51           ` Randy Brukardt
2011-01-29  0:55             ` Adam Beneschan
2011-01-28 16:44       ` Adam Beneschan
2011-01-28 17:21         ` Dmitry A. Kazakov
2011-01-29  0:12           ` Randy Brukardt
2011-01-29  8:47             ` Dmitry A. Kazakov
2011-01-28 17:33         ` Adam Beneschan
2011-01-28 15:13     ` Maciej Sobczak [this message]
2011-01-28 17:47       ` Robert A Duff
2011-01-28 22:04         ` Maciej Sobczak
2011-01-30 20:22           ` Stephen Leake
2011-01-31  9:04             ` AdaCore, user community and communication channels Maciej Sobczak
2011-01-31 10:42               ` Georg Bauhaus
2011-01-27 19:33 ` Equivalent of dynamic_cast (downcast) for tagged types Adam Beneschan
replies disabled

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