comp.lang.ada
 help / color / mirror / Atom feed
* Problem with access parameter
@ 2004-05-25 10:52 Jano
  2004-05-25 14:00 ` Jim Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jano @ 2004-05-25 10:52 UTC (permalink / raw)


Hi,

I'm trying to finalize data inside a protected type, using the
approach pasted at the end. I'm not sure if I get this bizarre error
because of a Gnat 3.15p bug or because what I'm trying is illegal:

agpl-counter-multi.ads:59:04: expected an access type with designated
type "Object" defined at line 59
agpl-counter-multi.ads:59:04: found an access type with designated
type derived from "Object" defined at line 59
agpl-counter-multi.ads:59:04:   ==> in call to "_Init_Proc" at line 73

The package code is: (trimmed)

package Agpl.Counter.Multi is

   type Object;
   type Object_Access is access all Object;

   type Destructor_Type (Parent : access Object) is limited private; 

   ----------------------------------------------------------------
   -- Object                                                     --
   ----------------------------------------------------------------
   protected type Object is
      -- Things
   private
      procedure Destroy;
      Destructor : Destructor_Type (Object'Access);
      Values     : Counter_Map.Container_Type;
   end Object;

private

   type Destructor_Type (Parent : access Object) is new   
   Finalization.Limited_Controlled with null record;

   procedure Finalize (This : in out Destructor_Type);
   -- Here call to This.Parent.Destroy;

end Agpl.Counter.Multi;



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-25 10:52 Problem with access parameter Jano
@ 2004-05-25 14:00 ` Jim Rogers
  2004-05-25 15:32   ` Dmitry A. Kazakov
  2004-05-25 14:58 ` Jano
  2004-05-25 15:48 ` Jano
  2 siblings, 1 reply; 9+ messages in thread
From: Jim Rogers @ 2004-05-25 14:00 UTC (permalink / raw)


402450@cepsz.unizar.es (Jano) wrote in message news:<5d6fdb61.0405250252.3a1f1f68@posting.google.com>...
> Hi,
> 
> I'm trying to finalize data inside a protected type, using the
> approach pasted at the end. I'm not sure if I get this bizarre error
> because of a Gnat 3.15p bug or because what I'm trying is illegal:
> 
> agpl-counter-multi.ads:59:04: expected an access type with designated
> type "Object" defined at line 59
> agpl-counter-multi.ads:59:04: found an access type with designated
> type derived from "Object" defined at line 59
> agpl-counter-multi.ads:59:04:   ==> in call to "_Init_Proc" at line 73
> 
> The package code is: (trimmed)
> 
> package Agpl.Counter.Multi is
> 
>    type Object;
>    type Object_Access is access all Object;
> 
>    type Destructor_Type (Parent : access Object) is limited private; 

The discriminant type is not the same as Object_Access. It is an
anonymous type. If you want to use Object_Access as the discriminant type
then specify this clearly.

> 
>    ----------------------------------------------------------------
>    -- Object                                                     --
>    ----------------------------------------------------------------
>    protected type Object is
>       -- Things
>    private
>       procedure Destroy;
>       Destructor : Destructor_Type (Object'Access);

Object is the name of a type. You cannot take the access value of a type,
only of an instance.

It looks like you are trying to create something equivalent to a C++ or Java
"this" reference. What are you trying to achieve?

>       Values     : Counter_Map.Container_Type;
>    end Object;
> 
> private
> 
>    type Destructor_Type (Parent : access Object) is new   
>    Finalization.Limited_Controlled with null record;
> 
>    procedure Finalize (This : in out Destructor_Type);
>    -- Here call to This.Parent.Destroy;

You are trying to destroy a protected object from within itself. 
Such an operation can cause a large number of problems. What happens to
tasks waiting in an entry queue for the protected object? Are they
released from the queue? I do not believe the Ada Reference Manual
specifies the results of such an operation.

> 
> end Agpl.Counter.Multi;

Remember that Ada protected objects are used as communication buffers between
two or more tasks. Destroying a protected object because of a finalization
call on one of its members appears to be a very wobbly design.

Jim Rogers



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-25 10:52 Problem with access parameter Jano
  2004-05-25 14:00 ` Jim Rogers
@ 2004-05-25 14:58 ` Jano
  2004-05-25 15:48 ` Jano
  2 siblings, 0 replies; 9+ messages in thread
From: Jano @ 2004-05-25 14:58 UTC (permalink / raw)


Forget about it, I've found some flaws in my reasoning to do this. Thanks anyway.

402450@cepsz.unizar.es (Jano) wrote in message news:<5d6fdb61.0405250252.3a1f1f68@posting.google.com>...
> Hi,
> 
> I'm trying to finalize data inside a protected type, using the
> approach pasted at the end. I'm not sure if I get this bizarre error
> because of a Gnat 3.15p bug or because what I'm trying is illegal:
> 
> agpl-counter-multi.ads:59:04: expected an access type with designated
> type "Object" defined at line 59
> agpl-counter-multi.ads:59:04: found an access type with designated
> type derived from "Object" defined at line 59
> agpl-counter-multi.ads:59:04:   ==> in call to "_Init_Proc" at line 73
> 
> The package code is: (trimmed)
> 
> package Agpl.Counter.Multi is
> 
>    type Object;
>    type Object_Access is access all Object;
> 
>    type Destructor_Type (Parent : access Object) is limited private; 
> 
>    ----------------------------------------------------------------
>    -- Object                                                     --
>    ----------------------------------------------------------------
>    protected type Object is
>       -- Things
>    private
>       procedure Destroy;
>       Destructor : Destructor_Type (Object'Access);
>       Values     : Counter_Map.Container_Type;
>    end Object;
> 
> private
> 
>    type Destructor_Type (Parent : access Object) is new   
>    Finalization.Limited_Controlled with null record;
> 
>    procedure Finalize (This : in out Destructor_Type);
>    -- Here call to This.Parent.Destroy;
> 
> end Agpl.Counter.Multi;



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-25 14:00 ` Jim Rogers
@ 2004-05-25 15:32   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2004-05-25 15:32 UTC (permalink / raw)


On 25 May 2004 07:00:48 -0700, jimmaureenrogers@worldnet.att.net (Jim
Rogers) wrote:

>402450@cepsz.unizar.es (Jano) wrote in message news:<5d6fdb61.0405250252.3a1f1f68@posting.google.com>...

>> I'm trying to finalize data inside a protected type, using the
>> approach pasted at the end. I'm not sure if I get this bizarre error
>> because of a Gnat 3.15p bug or because what I'm trying is illegal:
>> 
>> agpl-counter-multi.ads:59:04: expected an access type with designated
>> type "Object" defined at line 59
>> agpl-counter-multi.ads:59:04: found an access type with designated
>> type derived from "Object" defined at line 59
>> agpl-counter-multi.ads:59:04:   ==> in call to "_Init_Proc" at line 73
>> 
>> The package code is: (trimmed)
>> 
>> package Agpl.Counter.Multi is
>> 
>>    type Object;
>>    type Object_Access is access all Object;
>> 
>>    type Destructor_Type (Parent : access Object) is limited private; 
>
>The discriminant type is not the same as Object_Access. It is an
>anonymous type. If you want to use Object_Access as the discriminant type
>then specify this clearly.

It is pretty legal for record types. For example:

   type Object;
   type Destructor_Type (Parent : access Object) is limited private; 
   type Object is limited record
      Destructor : Destructor_Type (Object'Access);
   end record;
private
   type Destructor_Type (Parent : access Object) is
      new Ada.Finalization.Limited_Controlled with null record;
   procedure Finalize (This : in out Destructor_Type);

I am not sure, but it seems to be allowed for record types only
3.8(12).

>>    ----------------------------------------------------------------
>>    -- Object                                                     --
>>    ----------------------------------------------------------------
>>    protected type Object is
>>       -- Things
>>    private
>>       procedure Destroy;
>>       Destructor : Destructor_Type (Object'Access);
>
>Object is the name of a type. You cannot take the access value of a type,
>only of an instance.

See above.

>It looks like you are trying to create something equivalent to a C++ or Java
>"this" reference. What are you trying to achieve?

It looks that he wants a destructor for a protected object. A rightful
wish, or? Because protected types are not and cannot be derived from
Limited_Controlled, he tries to inject a controlled member pointing to
the protected parent. When parent gets finalized, the member's
Finalize is called with access to parent's as the discriminant.

>>       Values     : Counter_Map.Container_Type;
>>    end Object;
>> 
>> private
>> 
>>    type Destructor_Type (Parent : access Object) is new   
>>    Finalization.Limited_Controlled with null record;
>> 
>>    procedure Finalize (This : in out Destructor_Type);
>>    -- Here call to This.Parent.Destroy;
>
>You are trying to destroy a protected object from within itself.
>Such an operation can cause a large number of problems. What happens to
>tasks waiting in an entry queue for the protected object? Are they
>released from the queue? I do not believe the Ada Reference Manual
>specifies the results of such an operation.

That's no problem, because Finalize will be called upon parent's
finalization. At that point the parent is out of scope of anybody who
might use it. (if no dangling pointers used)

-----------------------------
Well, it seems that the trick won't work. So one should pack the
protected object into a limited controlled type and make proxies to
its entries and subprograms.

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-25 10:52 Problem with access parameter Jano
  2004-05-25 14:00 ` Jim Rogers
  2004-05-25 14:58 ` Jano
@ 2004-05-25 15:48 ` Jano
  2004-05-26  7:05   ` Martin Krischik
  2 siblings, 1 reply; 9+ messages in thread
From: Jano @ 2004-05-25 15:48 UTC (permalink / raw)


Dmitry A. Kazakov wrote:

> It looks that he wants a destructor for a protected object. A rightful
> wish, or? Because protected types are not and cannot be derived from
> Limited_Controlled, he tries to inject a controlled member pointing to
> the protected parent. When parent gets finalized, the member's
> Finalize is called with access to parent's as the discriminant.

Exactly what I wanted.

> -----------------------------
> Well, it seems that the trick won't work. So one should pack the
> protected object into a limited controlled type and make proxies to
> its entries and subprograms.

That's the way I've taken. It's indeed better than my original
approach (except for the need of stubs, but I don't like to expose
protected types anyway) because I wanted to free data in a Charles
polymorphic list of classwide pointers, and I didn't want to depend on
what was finalized first: the container or my destructor (even if
there are strict rules for that, it's too fine a detail to depend on
for my tastes).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-25 15:48 ` Jano
@ 2004-05-26  7:05   ` Martin Krischik
  2004-05-26 14:35     ` Jano
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Krischik @ 2004-05-26  7:05 UTC (permalink / raw)


Jano wrote:

> Dmitry A. Kazakov wrote:
 
> That's the way I've taken. It's indeed better than my original
> approach (except for the need of stubs, but I don't like to expose
> protected types anyway) because I wanted to free data in a Charles
> polymorphic list of classwide pointers, and I didn't want to depend on
> what was finalized first: the container or my destructor (even if
> there are strict rules for that, it's too fine a detail to depend on
> for my tastes).

Any deeper reason why you want to store pointers?

Charles, or at least Ada.Containers from the same author has support for
indefinite types and can therefore store 'Class types directly without the
need of access.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-26  7:05   ` Martin Krischik
@ 2004-05-26 14:35     ` Jano
  2004-05-26 16:11       ` Martin Krischik
  0 siblings, 1 reply; 9+ messages in thread
From: Jano @ 2004-05-26 14:35 UTC (permalink / raw)


Martin Krischik <krischik@users.sourceforge.net> wrote in message news:<1671188.WHz8GCEAgr@linux1.krischik.com>...

> Any deeper reason why you want to store pointers?
> 
> Charles, or at least Ada.Containers from the same author has support for
> indefinite types and can therefore store 'Class types directly without the
> need of access.

No reason; but Charles doesn't allow indefinite elements. I've not
used Ada.Containers but I'm very pleased to know about this new
feature.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-26 14:35     ` Jano
@ 2004-05-26 16:11       ` Martin Krischik
  2004-05-27  9:01         ` Jano
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Krischik @ 2004-05-26 16:11 UTC (permalink / raw)


Jano wrote:

> Martin Krischik <krischik@users.sourceforge.net> wrote in message
> news:<1671188.WHz8GCEAgr@linux1.krischik.com>...
> 
>> Any deeper reason why you want to store pointers?
>> 
>> Charles, or at least Ada.Containers from the same author has support for
>> indefinite types and can therefore store 'Class types directly without
>> the need of access.
> 
> No reason; but Charles doesn't allow indefinite elements.

Well AdaCL has support for indefinete element. But the support is based on
the booch componentes. I store 'Class quite often - quite helpfull.

> I've not 
> used Ada.Containers but I'm very pleased to know about this new
> feature.

Ada.Containers is based on Charles. At some ends scaled down at some other
ends extended. If you are a Charles user you might consider to switch to
Ada.Containers for use with indefinite elements.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problem with access parameter
  2004-05-26 16:11       ` Martin Krischik
@ 2004-05-27  9:01         ` Jano
  0 siblings, 0 replies; 9+ messages in thread
From: Jano @ 2004-05-27  9:01 UTC (permalink / raw)


Martin Krischik <krischik@users.sourceforge.net> wrote in message news:<1713125.oG3p9nqcOY@linux1.krischik.com>...

> Ada.Containers is based on Charles. At some ends scaled down at some other
> ends extended. If you are a Charles user you might consider to switch to
> Ada.Containers for use with indefinite elements.

There are two reasons I don't plan to switch now: one, my project is
too entrenched wich Charles. Porting would demand a respectable
effort. Two, I see the spec is still changing... undoubtly once the
final form for 0Y is stablished I'll jump to it at once for any new
project.

Interesting the bit about AdaCL. I'll keep it in mind.

Thanks!



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-05-27  9:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-25 10:52 Problem with access parameter Jano
2004-05-25 14:00 ` Jim Rogers
2004-05-25 15:32   ` Dmitry A. Kazakov
2004-05-25 14:58 ` Jano
2004-05-25 15:48 ` Jano
2004-05-26  7:05   ` Martin Krischik
2004-05-26 14:35     ` Jano
2004-05-26 16:11       ` Martin Krischik
2004-05-27  9:01         ` Jano

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