From: Dmitry A. Kazakov on 22 Nov 2009 12:41 On Sun, 22 Nov 2009 08:52:05 -0800 (PST), xorque wrote: > On Nov 22, 4:42�pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> > wrote: >> On Sun, 22 Nov 2009 08:27:59 -0800 (PST), xorque wrote: >>> Not sure which part of the code you're referring to here. >> >> The function Open_Archive returns a new object. In Main you call it and >> then apply the function Stream to the result. Stream returns an access to >> the component File of the temporal object created by Open_Archive. Then >> this object is destroyed and a dangling pointer is assigned to S. When you >> call Integer'Inpit on S, it accesses a garbage. > > Ah, I see what you mean. > > In the process of trying to save the result of Open_Archive so that I > can test > if this problem still occurs, I've run into another problem: > > A : Archiver.Archiver_t; > O : constant Archiver.Archive_t := Archiver.Archive_t > (Archiver.Open_Archive (A, "file.zip")); > S : constant Stream_IO.Stream_Access := Archiver.Stream (O); > > main.adb:9:46: illegal context for call to function with limited > result > > I have to admit to not understanding that error. And I don't understand your design. If Archive is a Stream derive then it from Root_Stream_Type. If it deals with a stream then pass Root_Stream_Type'Class to the operations that need it. But never ever return pointers to components without an urgent need. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: xorque on 22 Nov 2009 13:03 On Nov 22, 5:41 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > On Sun, 22 Nov 2009 08:52:05 -0800 (PST), xorque wrote: > > > I have to admit to not understanding that error. > > And I don't understand your design. If Archive is a Stream derive then it > from Root_Stream_Type. If it deals with a stream then pass > Root_Stream_Type'Class to the operations that need it. The design is both irrelevant and obsolete. I'm just trying to find out if the problem is *definitely* that code so that I can close a bug in the GCC tracker. > But never ever return pointers to components without an urgent need. Is it possible to save the return value of Open_Archive, or not? Regards, xw
From: xorque on 22 Nov 2009 13:08 If it's not already obvious, I'm aware that there's a bug in the above code but am not currently convinced that it's the cause of *this* crash as the crash occurs before the archive is finalized.
From: Dmitry A. Kazakov on 22 Nov 2009 13:28 On Sun, 22 Nov 2009 10:03:22 -0800 (PST), xorque wrote: > On Nov 22, 5:41�pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> > wrote: >> On Sun, 22 Nov 2009 08:52:05 -0800 (PST), xorque wrote: >> >>> I have to admit to not understanding that error. >> >> And I don't understand your design. If Archive is a Stream derive then it >> from Root_Stream_Type. If it deals with a stream then pass >> Root_Stream_Type'Class to the operations that need it. > > The design is both irrelevant and obsolete. I'm just trying to find out if > the problem is *definitely* that code so that I can close a bug in the > GCC tracker. The problem semantically is that you convert type, which would/should create a copy of a limited object. Within a declaration ":=" denotes initialization. You may not convert anything initializing a limited object. Proper ways to go: O : constant Archiver.Archive_t'Class := Archiver.Open_Archive (A, "file.zip"); or O :Archiver.Archive_t'Class renames Archiver.Open_Archive (A, "file.zip"); or (with type casing, which is a *view* conversion) O : Archiver.Archive_t renames Archiver.Archive_t (Archiver.Open_Archive (A, "file.zip")); >> But never ever return pointers to components without an urgent need. > > Is it possible to save the return value of Open_Archive, or not? No, the type is limited it does not have "values", which can be saved (copied). You can create an object initialized in a way that its state would correspond to the desired value. P.S. ":=" for initialization of limited objects might look misleading (and does look misleading to me), but that would be another discussion on Ada design, in which nobody would agree with me. So I prefer not to go into it. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: xorque on 22 Nov 2009 13:41
On Nov 22, 6:28 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > On Sun, 22 Nov 2009 10:03:22 -0800 (PST), xorque wrote: > > The problem semantically is that you convert type, which would/should > create a copy of a limited object... > <snipped> > Ok, thanks for the explanation. I made the change you suggest to initialize ("save") the archive and the crash doesn't occur. I've closed the bug on the GCC due to the discussion of the bug becoming confused between two issues (one of them - this one - invalid and another that's definitely valid). Regards, xw |