debug: factor out logfile size check
[samba.git] / lib / util / talloc_stack.h
1 /*
2    Unix SMB/CIFS implementation.
3    Implement a stack of talloc contexts
4    Copyright (C) Volker Lendecke 2007
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*
21  * Implement a stack of talloc frames.
22  *
23  * When a new talloc stackframe is allocated with talloc_stackframe(), then
24  * the TALLOC_CTX returned with talloc_tos() is reset to that new
25  * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
26  * happens: The previous talloc_tos() is restored.
27  *
28  * This API is designed to be robust in the sense that if someone forgets to
29  * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
30  * resets the talloc_tos().
31  *
32  */
33
34 #ifndef _TALLOC_STACK_H
35 #define _TALLOC_STACK_H
36
37 #include <talloc.h>
38
39 /*
40  * Create a new talloc stack frame.
41  *
42  * When free'd, it frees all stack frames that were created after this one and
43  * not explicitly freed.
44  */
45
46 #define talloc_stackframe() _talloc_stackframe(__location__)
47 #define talloc_stackframe_pool(sz) _talloc_stackframe_pool(__location__, (sz))
48 TALLOC_CTX *_talloc_stackframe(const char *location);
49 TALLOC_CTX *_talloc_stackframe_pool(const char *location, size_t poolsize);
50
51 /*
52  * Get us the current top of the talloc stack.
53  */
54
55 #define talloc_tos() _talloc_tos(__location__)
56 TALLOC_CTX *_talloc_tos(const char *location);
57
58 /*
59  * return true if a talloc stackframe exists
60  * this can be used to prevent memory leaks for code that can
61  * optionally use a talloc stackframe (eg. nt_errstr())
62  */
63
64 bool talloc_stackframe_exists(void);
65
66 #endif