From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,589d16556c145528 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 21 Mar 2005 16:37:32 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: non-library level finalization References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Mon, 21 Mar 2005 16:37:32 -0600 NNTP-Posting-Host: 67.161.24.234 X-Trace: sv3-WMcXCj9FVHjUrxWwywdZKzDlVf/VTdUbS+PebJ8Jy2fxq7T9HtuDhy3MDQa2GD8W9M5P5v8Mco/KX4L!pzig8770Eta8bmpgPEVsnzSR28TOkUn5syWhTqzPHVqvfCs3oBTci44iZbRFlg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:9702 Date: 2005-03-21T16:37:32-06:00 List-Id: >I forgot the obvious. The problem is not with a controlled *object*, but >rather declaring a controlled *type*. So, you can do this by declaring a >controlled type outside of the generic. Now, to make that useful, you'd have >to figure out some way to figure out how to do the needed actions inside of >the generic -- and *that* might prove difficult depending on what you need >done. (For instance, registering a handler would work, but it too would have >to be at library-level -- so you wouldn't have gained anything.) I considered the obvious package Finalization_Helper is type Ptr_Type is access procedure; type Finalizer_Type is new Ada.Finalization.Limited_Controlled with record Last_Wishes_Ptr : Ptr_Type; end record; procedure Finalize(Finalizer : in out Finalizer_Type) ... is begin Finalizer.Last_Wishes_Ptr.all; exception when others=>null; end Finalize; and then putting in the generic procedure Cleanup; Finalizer : Finalization_Helper.Finalizer_Type := (Last_Wishes_Ptr=>Cleanup'access); but that has an access level problem. >For a lot of generics, restricting to library level isn't a major concern >(or, it's happened already, as is usually the case for tagged types). But >your case may be different. It's merely unpleasing and maintenance error-prone to add an extra package to instantiate the generic, and a Use clause to hide the fact of the extra package.