2003-08-13 01:53:07 +00:00
# ifndef _TALLOC_H_
# define _TALLOC_H_
/*
Unix SMB / CIFS implementation .
Samba temporary memory allocation functions
2004-08-21 01:54:46 +00:00
2005-01-12 11:45:43 +00:00
Copyright ( C ) Andrew Tridgell 2004 - 2005
2003-08-13 01:53:07 +00:00
2005-12-01 00:25:06 +00:00
* * NOTE ! The following LGPL license applies to the talloc
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
2003-08-13 01:53:07 +00:00
2005-12-01 00:25:06 +00:00
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This library is distributed in the hope that it will be useful ,
2003-08-13 01:53:07 +00:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2005-12-01 00:25:06 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2003-08-13 01:53:07 +00:00
*/
2004-08-21 01:54:46 +00:00
/* this is only needed for compatibility with the old talloc */
typedef void TALLOC_CTX ;
2003-08-13 01:53:07 +00:00
2004-09-26 04:59:03 +00:00
/*
this uses a little trick to allow __LINE__ to be stringified
*/
# define _STRING_LINE_(s) #s
# define _STRING_LINE2_(s) _STRING_LINE_(s)
# define __LINESTR__ _STRING_LINE2_(__LINE__)
# define __location__ __FILE__ ":" __LINESTR__
2005-01-07 04:39:16 +00:00
# ifndef TALLOC_DEPRECATED
# define TALLOC_DEPRECATED 0
# endif
2006-05-24 07:31:02 +00:00
# ifndef PRINTF_ATTRIBUTE
# if (__GNUC__ >= 3)
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format , and a2 the index of the first
* argument . Note that some gcc 2. x versions don ' t handle this
* properly * */
# define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
# else
# define PRINTF_ATTRIBUTE(a1, a2)
# endif
# endif
/* try to make talloc_set_destructor() and talloc_steal() type safe,
if we have a recent gcc */
# if (__GNUC__ >= 3)
# define _TALLOC_TYPEOF(ptr) __typeof__(ptr)
# define talloc_set_destructor(ptr, function) \
do { \
2006-08-28 15:36:12 +00:00
int ( * _talloc_destructor_fn ) ( _TALLOC_TYPEOF ( ptr ) ) = ( function ) ; \
2006-08-28 17:38:49 +00:00
_talloc_set_destructor ( ( ptr ) , ( int ( * ) ( void * ) ) _talloc_destructor_fn ) ; \
2006-05-24 07:31:02 +00:00
} while ( 0 )
2006-08-21 01:27:22 +00:00
/* this extremely strange macro is to avoid some braindamaged warning
stupidity in gcc 4.1 . x */
2006-08-28 15:36:12 +00:00
# define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr)); __talloc_steal_ret; })
2006-08-28 18:21:21 +00:00
# define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr))
2006-05-24 07:31:02 +00:00
# else
# define talloc_set_destructor(ptr, function) \
_talloc_set_destructor ( ( ptr ) , ( int ( * ) ( void * ) ) ( function ) )
# define _TALLOC_TYPEOF(ptr) void *
2006-08-21 01:27:22 +00:00
# define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr))
2006-08-28 18:21:21 +00:00
# define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr))
2006-05-24 07:31:02 +00:00
# endif
2003-12-13 02:20:40 +00:00
/* useful macros for creating type checked pointers */
2005-01-16 23:21:52 +00:00
# define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
2005-01-06 03:06:58 +00:00
# define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
2006-08-28 16:55:51 +00:00
# define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr))talloc_size(ctx, sizeof(*(ptr)))
2005-01-07 04:39:16 +00:00
2005-01-06 02:32:43 +00:00
# define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
2005-01-07 04:39:16 +00:00
# define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
# define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__)
2005-01-16 23:21:52 +00:00
# define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
# define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
2005-01-07 04:39:16 +00:00
# define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
2006-08-28 16:55:51 +00:00
# define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
2005-01-07 04:39:16 +00:00
2005-01-16 23:21:52 +00:00
# define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, #type)
2005-01-07 04:39:16 +00:00
# define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
2004-09-26 06:41:59 +00:00
# define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
2004-08-21 01:54:46 +00:00
2005-01-16 23:21:52 +00:00
# define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type)
# define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type)
2005-06-20 05:03:54 +00:00
# define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type)
2005-01-07 04:39:16 +00:00
# if TALLOC_DEPRECATED
# define talloc_zero_p(ctx, type) talloc_zero(ctx, type)
# define talloc_p(ctx, type) talloc(ctx, type)
# define talloc_array_p(ctx, type, count) talloc_array(ctx, type, count)
# define talloc_realloc_p(ctx, p, type, count) talloc_realloc(ctx, p, type, count)
2005-01-12 11:45:43 +00:00
# define talloc_destroy(ctx) talloc_free(ctx)
2005-01-07 04:39:16 +00:00
# endif
2005-01-16 23:21:52 +00:00
/* The following definitions come from talloc.c */
2004-09-29 06:31:14 +00:00
void * _talloc ( const void * context , size_t size ) ;
2006-05-24 07:31:02 +00:00
void _talloc_set_destructor ( const void * ptr , int ( * destructor ) ( void * ) ) ;
2006-08-28 18:21:21 +00:00
int talloc_increase_ref_count ( const void * ptr ) ;
void * _talloc_reference ( const void * context , const void * ptr ) ;
2004-10-03 00:04:30 +00:00
int talloc_unlink ( const void * context , void * ptr ) ;
2006-06-21 19:28:24 +00:00
const char * talloc_set_name ( const void * ptr , const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
2004-09-29 06:31:14 +00:00
void talloc_set_name_const ( const void * ptr , const char * name ) ;
void * talloc_named ( const void * context , size_t size ,
const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 3 , 4 ) ;
void * talloc_named_const ( const void * context , size_t size , const char * name ) ;
const char * talloc_get_name ( const void * ptr ) ;
2005-01-16 23:21:52 +00:00
void * talloc_check_name ( const void * ptr , const char * name ) ;
2005-01-11 15:38:25 +00:00
void talloc_report_depth ( const void * ptr , FILE * f , int depth ) ;
void * talloc_parent ( const void * ptr ) ;
2004-09-29 06:31:14 +00:00
void * talloc_init ( const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 1 , 2 ) ;
int talloc_free ( void * ptr ) ;
2006-07-26 17:32:47 +00:00
void talloc_free_children ( void * ptr ) ;
2004-09-29 06:31:14 +00:00
void * _talloc_realloc ( const void * context , void * ptr , size_t size , const char * name ) ;
2006-05-24 07:31:02 +00:00
void * _talloc_steal ( const void * new_ctx , const void * ptr ) ;
2006-07-21 10:34:10 +00:00
size_t talloc_total_size ( const void * ptr ) ;
size_t talloc_total_blocks ( const void * ptr ) ;
2004-09-29 06:31:14 +00:00
void talloc_report_full ( const void * ptr , FILE * f ) ;
void talloc_report ( const void * ptr , FILE * f ) ;
2005-03-26 10:47:44 +00:00
void talloc_enable_null_tracking ( void ) ;
2006-08-28 17:50:26 +00:00
void talloc_disable_null_tracking ( void ) ;
2004-09-29 06:31:14 +00:00
void talloc_enable_leak_report ( void ) ;
void talloc_enable_leak_report_full ( void ) ;
2004-10-19 06:29:41 +00:00
void * _talloc_zero ( const void * ctx , size_t size , const char * name ) ;
2004-09-29 06:31:14 +00:00
void * _talloc_memdup ( const void * t , const void * p , size_t size , const char * name ) ;
char * talloc_strdup ( const void * t , const char * p ) ;
char * talloc_strndup ( const void * t , const char * p , size_t n ) ;
2005-06-26 23:59:22 +00:00
char * talloc_append_string ( const void * t , char * orig , const char * append ) ;
2004-09-29 06:31:14 +00:00
char * talloc_vasprintf ( const void * t , const char * fmt , va_list ap ) PRINTF_ATTRIBUTE ( 2 , 0 ) ;
2005-12-31 04:26:34 +00:00
char * talloc_vasprintf_append ( char * s , const char * fmt , va_list ap ) PRINTF_ATTRIBUTE ( 2 , 0 ) ;
2004-09-29 06:31:14 +00:00
char * talloc_asprintf ( const void * t , const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
char * talloc_asprintf_append ( char * s ,
const char * fmt , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
2005-01-07 04:39:16 +00:00
void * _talloc_array ( const void * ctx , size_t el_size , unsigned count , const char * name ) ;
void * _talloc_zero_array ( const void * ctx , size_t el_size , unsigned count , const char * name ) ;
void * _talloc_realloc_array ( const void * ctx , void * ptr , size_t el_size , unsigned count , const char * name ) ;
2005-01-02 07:47:34 +00:00
void * talloc_realloc_fn ( const void * context , void * ptr , size_t size ) ;
2005-01-02 12:55:33 +00:00
void * talloc_autofree_context ( void ) ;
2005-05-07 15:22:45 +00:00
size_t talloc_get_size ( const void * ctx ) ;
2005-06-20 05:03:54 +00:00
void * talloc_find_parent_byname ( const void * ctx , const char * name ) ;
2005-06-20 06:15:35 +00:00
void talloc_show_parents ( const void * context , FILE * file ) ;
2006-08-28 17:38:49 +00:00
int talloc_is_parent ( const void * context , const void * ptr ) ;
2004-09-29 06:31:14 +00:00
2004-08-21 01:54:46 +00:00
# endif
2003-08-13 01:53:07 +00:00