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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6e857f2d820a5f3b X-Google-Attributes: gid103376,public From: adam@irvine.com (Adam Beneschan) Subject: Re: Passing out unconstrained arrays?? Date: 1998/07/02 Message-ID: <6ngn1n$l4i$1@krusty.irvine.com>#1/1 X-Deja-AN: 368185354 References: <6ne0gl$631$1@news.bctel.net> <6nghkl$ch3$1@nnrp1.dejanews.com> Organization: Irvine Compiler Corporation - Irvine, CA, USA Newsgroups: comp.lang.ada Date: 1998-07-02T00:00:00+00:00 List-Id: In article <6nghkl$ch3$1@nnrp1.dejanews.com> dennison@telepath.com writes: > > Max_Returned_Items : constant := 5_000; > -- Bump this up if you get a Too_Many_Items exception > > type Item_List is array (Natural range <>) of Integer > > subtype Returned_Item_List is Item_List (1..Max_Returned_Items); Is there any reason not to just make the upper bound Integer'Last? You're not actually allocating anything of this subtype, and you're not going to access any array components beyond Num_Items anyway. > type Item_List_Ptr is access Returned_Item_List; > > type Integer_Ptr is access Integer; > > procedure C_Get_Data (Num_Data_Items : in System.Address; > Data_Items : in System.Address); > pragma Import (C, "get_data", C_Get_Data); > procedure C_Dealloc (Location : in Item_List_Ptr); > pragma Import (C, "dealloc", C_Dealloc); > > function Get_Data return Item_List is > Num_Items : Integer; > Data_Returned : Item_List_Ptr; > Data : Returned_Item_List; > begin > C_Get_Data (Num_Items'address, Data_Returned'address); > > -- Do error handling > if Num_Items.all = 0 then > -- return a null array > return (2..1 => 0); > elsif Num_Items.all > Max_Returned_Items then > -- Wow. We need to raise the limit. > raise Too_Many_Items; > end if; > > Data(1..Num_Items.all) := Data_Returned.all(1..Num_Items.all); > C_Dealloc(Data_Returned); > return Data(1..Num_Items.all); > > end Get_Data; > > T.E.D. -- Adam