From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Interfaces.C.Strings chars_ptr memory management strategy
Date: Thu, 31 May 2018 17:25:01 -0500
Date: 2018-05-31T17:25:01-05:00 [thread overview]
Message-ID: <pepsoa$jh7$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: peoj3f$8ti$1@dont-email.me
"Alejandro R. Mosteo" <alejandro@mosteo.com> wrote in message
news:peoj3f$8ti$1@dont-email.me...
> On 30/05/2018 21:56, Randy Brukardt wrote:
...
>>> Is the in-place built limited tagged type guaranteed to live during the
>>> call to the C function? (In other words, is the pointer safe (as long as
>>> the C side does not make a copy, of course)?
>>
>> That depends on the master of the parameter. I believe that the master of
>> a
>> parameter is that of the call (each call being it's own master for the
>> parameters) -- you'd have to look in 7.6.1 to be sure. So they stay
>> around
>> as long as the call.
>
> Might that be 6.4.1? 7 deals with packages (in 2012).
No. The rules for masters are defined with finalization in 7.6, and
specifically in 7.6.1(3/2). The single middle sentence in that paragraph (a
classic RM run-on sentence) defines completely where every object in an Ada
program is finalized -- and also defines large parts of the accessibility
and tasking models (which mainly follow the same master rules).
> Although it was too dense for me anyway :(
That's why I didn't want to give you a definitive answer. It takes a lot of
mental effort to do that, and I need to save that effort for things people
pay me to do. ;-)
...
>> Foo (Bar (Ugh (...))
>>
>> The result of Ugh is finalized when the call to Bar ends, so if it is
>> somehow in the result of Bar, you could get trouble in Foo. You can avoid
>> that by declaring the parameter "aliased" (those belong to the *result*
>> of
>> the function, so they stick around longer).
>
> The parameter is actually aliased already. So I hope your impressions are
> right and I'm on firm ground then, a pleasant surprise.
Turns out I was wrong: 7.6.1(3/2) says that only the outer function call is
a master. So there is no problem in even the case I suggested.
Randy.
next prev parent reply other threads:[~2018-05-31 22:25 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 [this message]
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
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