r1983: a completely new implementation of talloc
[bbaumbach/samba-autobuild/.git] / source4 / include / talloc.h
1 #ifndef _TALLOC_H_
2 #define _TALLOC_H_
3 /* 
4    Unix SMB/CIFS implementation.
5    Samba temporary memory allocation functions
6
7    Copyright (C) Andrew Tridgell 2004
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /* this is only needed for compatibility with the old talloc */
25 typedef void TALLOC_CTX;
26
27 /* useful macros for creating type checked pointers */
28 #define talloc_p(ctx, type) (type *)talloc(ctx, sizeof(type))
29 #define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count)
30 #define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count)
31
32 #define talloc_destroy(ctx) talloc_free(ctx)
33
34 #define malloc_p(type) (type *)malloc(sizeof(type))
35 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
36 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
37
38 #endif
39