comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Re: Interfaces.C.Strings chars_ptr memory management strategy
Date: Mon, 4 Jun 2018 00:47:43 -0700 (PDT)
Date: 2018-06-04T00:47:43-07:00	[thread overview]
Message-ID: <7801d793-9b0a-474e-94ca-e00151a34c86@googlegroups.com> (raw)
In-Reply-To: <pf2oed$35f$1@gioia.aioe.org>

On Monday, June 4, 2018 at 4:06:56 PM UTC+9, Dmitry A. Kazakov wrote:
> On 2018-06-03 10:03 PM, ytomino wrote:
> > 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.
> 
> No, not this free but the one called from the third-party library 
> because the pointer was passed there to handle.
> 
> Of course it is safe to call malloc-free or New_String-Free pairs. Other 
> combinations can be unsafe.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

> Of course it is safe to call malloc-free or New_String-Free pairs. Other 
> combinations can be unsafe.

That is only talking on the standard, probably is not the cause of the crash.

  reply	other threads:[~2018-06-04  7:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25 22:22 Interfaces.C.Strings chars_ptr memory management strategy NiGHTS
2018-05-26  2:52 ` Shark8
2018-05-26 12:44   ` NiGHTS
2018-05-26 13:56     ` Shark8
2018-05-30 13:10 ` Alejandro R. Mosteo
2018-05-30 19:56   ` Randy Brukardt
2018-05-31 10:34     ` Alejandro R. Mosteo
2018-05-31 22:25       ` Randy Brukardt
2018-06-05 12:42         ` Alejandro R. Mosteo
2018-06-03 18:31 ` ytomino
2018-06-03 19:33   ` Dmitry A. Kazakov
2018-06-03 20:03     ` ytomino
2018-06-04  7:06       ` Dmitry A. Kazakov
2018-06-04  7:47         ` ytomino [this message]
2018-06-03 20:37     ` ytomino
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox