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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Strange crash on custom iterator Date: Sat, 30 Jun 2018 15:25:36 +0100 Organization: A noiseless patient Spider Message-ID: References: <70c11a71-3832-4f57-8127-f3f1c48a052f@googlegroups.com> <62e38ee4-f72f-4ed8-bef1-952040fb7f8d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b23009edf2eaee529bf927e1c0a9ec62"; logging-data="22039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TsnwYerRwUR/LdbtoLhJ9JGEuwg3v4M8=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:sLXNNLNvrE/K8a7YINAD+3IFj2M= sha1:1C18rlL594Lfovr5VbAtYOYDmFA= Xref: reader02.eternal-september.org comp.lang.ada:53475 Date: 2018-06-30T15:25:36+01:00 List-Id: Lucretia writes: > On Saturday, 30 June 2018 12:32:14 UTC+1, Simon Wright wrote: >> Lucretia <> writes: >> >> > I finally got around to getting back to my iterator and on a first >> > test implementation, i.e. to just iterate over each element of the >> > array, the thing crashes in the Element function when accessing the >> > array through the cursor. >> > >> > The source is https://bpaste.net/show/6c5fca4c0ffd and the gdb session >> > is https://bpaste.net/show/5b0cf9d2be79 >> >> UCA.Encoding missing? > > Balls! https://bpaste.net/show/a0d108820ce6 First, I think Has_Element should probably be function Has_Element (Position : in Cursor) return Boolean is begin return Position.Index in Position.Data'Range; end Has_Element; Second, there's something odd about the Address_To_Access_Conversions: in Iterate, the address of the passed Container (which is on the stack!!!) appears in I.Data, but I.Data's length is 0. I got it to work (at first glance) with type Cursor is record Data : Unicode_String_Access := null; Index : Positive := Positive'Last; end record; type Code_Point_Iterator is new Limited_Controlled and Code_Point_Iterators.Forward_Iterator with record Data : Unicode_String_Access := null; end record; and in Iterate return I : Code_Point_Iterator := (Limited_Controlled with Data => new Unicode_String'(Container)) do but of course you probably don't want the copy.