The precise meaning of talloc_tos()

Michael Adam obnox at samba.org
Sat Apr 7 17:35:48 MDT 2012


Hi Richard,

Richard Sharpe wrote:
> Hi folks,
> 
> I noticed this comment in lib/util/talloc_stack.h
> 
> /*
>  * Implement a stack of talloc frames.
>  *
>  * When a new talloc stackframe is allocated with talloc_stackframe(), then
>  * the TALLOC_CTX returned with talloc_tos() is reset to that new
>  * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
>  * happens: The previous talloc_tos() is restored.
>  *
> 
> My question hinges around the use of the word reset above in "the
> TALLOC_CTX returned with talloc_tos() is *reset* to that new frame."

Maybe it should read "set" instead of "reset".

> I think that the code in talloc_stackframe.c shows that reset is the
> wrong word there and it simply returns the context associated with the
> current top of the talloc stack or a new one if no stack yet exists,
> however, given my recent demonstrated ability to mis-read code, can
> someone confirm :-)

talloc_tos / talloc_stackframe / talloc_free implements a stack
of talloc contexts. It is roughly meant to accompany the stack
of function calls to provide temporary memory for the function
context.

* talloc_tos() always returns the current top of stack (tos)

* talloc_stackframe() creates a new talloc context and puts it
  on top of the stack (and also returns the new context).
  This means that the next call to talloc_tos() will return
  this newly created context.

  This is what is meant with "reset" in the comment quoted above.

* talloc_free() applied to the top of stack pops the context
  off the stack, in partictular, it also so changes the value
  of the next talloc_tos() call.

Does this help?

Cheers - Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 206 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20120408/11451254/attachment.pgp>


More information about the samba-technical mailing list