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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:b00c:: with SMTP id d12-v6mr2753188itf.14.1528056202350; Sun, 03 Jun 2018 13:03:22 -0700 (PDT) X-Received: by 2002:a9d:740d:: with SMTP id n13-v6mr419318otk.12.1528056202055; Sun, 03 Jun 2018 13:03:22 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feeder4.usenet.farm!feed.usenet.farm!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!85.12.16.69.MISMATCH!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!v8-v6no4453891itc.0!news-out.google.com!f20-v6ni3107itd.0!nntp.google.com!v8-v6no4453885itc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Jun 2018 13:03:21 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2400:416e:1ba5:1200:91e3:9198:6925:ea8c; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj NNTP-Posting-Host: 2400:416e:1ba5:1200:91e3:9198:6925:ea8c References: <6ff31dc6-31e7-4755-bda0-1b53fa02f31f@googlegroups.com> <735fd76c-c0a7-4e8c-a534-857772cada9b@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8816050d-27e6-42e2-b6e8-fd85b31e8e04@googlegroups.com> Subject: Re: Interfaces.C.Strings chars_ptr memory management strategy From: ytomino Injection-Date: Sun, 03 Jun 2018 20:03:22 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 2434 X-Received-Body-CRC: 755510973 Xref: reader02.eternal-september.org comp.lang.ada:52890 Date: 2018-06-03T13:03:21-07:00 List-Id: On Monday, June 4, 2018 at 4:33:20 AM UTC+9, Dmitry A. Kazakov wrote: > On 2018-06-03 20:31, ytomino wrote: > > Perhaps, malloc is better than New_String in this case. > > > > function malloc (s : Interfaces.C.size_t) return Interfaces.C.Strings.chars_ptr > > with Import, Convention => C; > > I had a case when that caused the application crashed. > > I guess it was because of mixed Visual Studio and GCC run-times. The > pointer returned by the malloc from one was freed in a third-party C > library by another. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de What!? New_String calls malloc in the end, too, in mingw runtime. (It calls Memory_Alloc, Memory_Alloc is _gnat_malloc, and __gnat_malloc calls malloc.) https://gcc.gnu.org/svn/gcc/trunk/gcc/ada/libgnat/i-cstrin.adb https://gcc.gnu.org/svn/gcc/trunk/gcc/ada/libgnat/s-parame.ads https://gcc.gnu.org/svn/gcc/trunk/gcc/ada/libgnat/s-memory__mingw.adb If Interfaces.C.Strings.Free (malloc) is crashed, New_String would be same.