1 diff -c -r talloc-2.0.1/talloc.c talloc/talloc.c
2 *** talloc-2.0.1/talloc.c Tue Dec 15 06:16:57 2009
3 --- talloc/talloc.c Fri Mar 18 13:03:11 2011
6 inspired by http://swapped.cc/halloc/
12 #ifdef TALLOC_BUILD_VERSION_MAJOR
14 inspired by http://swapped.cc/halloc/
17 ! /* Commented out for building within Chromium */
18 ! /* #include "replace.h" */
21 #ifdef TALLOC_BUILD_VERSION_MAJOR
28 + /* inline isn't supported in C files in Visual Studio 2008 on Windows */
32 + #define INLINE inline
35 /* this null_context is only used if talloc_enable_leak_report() or
36 talloc_enable_leak_report_full() is called, otherwise it remains
42 /* panic if we get a bad magic value */
43 ! static inline struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
45 const char *pp = (const char *)ptr;
46 struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
50 /* panic if we get a bad magic value */
51 ! static INLINE struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
53 const char *pp = (const char *)ptr;
54 struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
58 return the parent chunk of a pointer
60 ! static inline struct talloc_chunk *talloc_parent_chunk(const void *ptr)
62 struct talloc_chunk *tc;
66 return the parent chunk of a pointer
68 ! static INLINE struct talloc_chunk *talloc_parent_chunk(const void *ptr)
70 struct talloc_chunk *tc;
75 Allocate a bit of memory as a child of an existing pointer
77 ! static inline void *__talloc(const void *context, size_t size)
79 struct talloc_chunk *tc = NULL;
83 Allocate a bit of memory as a child of an existing pointer
85 ! static INLINE void *__talloc(const void *context, size_t size)
87 struct talloc_chunk *tc = NULL;
91 more efficient way to add a name to a pointer - the name must point to a
94 ! static inline void _talloc_set_name_const(const void *ptr, const char *name)
96 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
99 more efficient way to add a name to a pointer - the name must point to a
102 ! static INLINE void _talloc_set_name_const(const void *ptr, const char *name)
104 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
109 internal talloc_named_const()
111 ! static inline void *_talloc_named_const(const void *context, size_t size, const char *name)
117 internal talloc_named_const()
119 ! static INLINE void *_talloc_named_const(const void *context, size_t size, const char *name)
126 internal talloc_free call
128 ! static inline int _talloc_free_internal(void *ptr, const char *location)
130 struct talloc_chunk *tc;
134 internal talloc_free call
136 ! static INLINE int _talloc_free_internal(void *ptr, const char *location)
138 struct talloc_chunk *tc;
142 talloc_reference() has done. The context and pointer arguments
143 must match those given to a talloc_reference()
145 ! static inline int talloc_unreference(const void *context, const void *ptr)
147 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
148 struct talloc_reference_handle *h;
150 talloc_reference() has done. The context and pointer arguments
151 must match those given to a talloc_reference()
153 ! static INLINE int talloc_unreference(const void *context, const void *ptr)
155 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
156 struct talloc_reference_handle *h;
160 add a name to an existing pointer - va_list version
162 ! static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
164 ! static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap)
166 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
167 tc->name = talloc_vasprintf(ptr, fmt, ap);
170 add a name to an existing pointer - va_list version
172 ! static INLINE const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
174 ! static INLINE const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap)
176 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
177 tc->name = talloc_vasprintf(ptr, fmt, ap);
184 + static INLINE size_t min_size(size_t a, size_t b)
186 + return a > b ? b : a;
190 A talloc version of realloc. The context argument is only used if
194 struct talloc_chunk *tc;
196 ! bool malloced = false;
198 /* size zero is equivalent to free() */
199 if (unlikely(size == 0)) {
202 struct talloc_chunk *tc;
206 /* size zero is equivalent to free() */
207 if (unlikely(size == 0)) {
211 if (new_ptr == NULL) {
212 new_ptr = malloc(TC_HDR_SIZE+size);
217 ! memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
223 if (new_ptr == NULL) {
224 new_ptr = malloc(TC_HDR_SIZE+size);
229 ! memcpy(new_ptr, tc, min_size(tc->size,size) + TC_HDR_SIZE);
238 ! static inline char *__talloc_strlendup(const void *t, const char *p, size_t len)
246 ! static INLINE char *__talloc_strlendup(const void *t, const char *p, size_t len)
253 return __talloc_strlendup(t, p, strlen(p));
256 + #ifndef HAVE_STRNLEN
257 + #define strnlen rep_strnlen
258 + static size_t rep_strnlen(const char* s, size_t n)
260 + if (unlikely(!s)) return 0;
262 + while (i < n && *s++ != '\0')
269 strndup with a talloc
273 return __talloc_strlendup(t, p, strnlen(p, n));
276 ! static inline char *__talloc_strlendup_append(char *s, size_t slen,
277 const char *a, size_t alen)
281 return __talloc_strlendup(t, p, strnlen(p, n));
284 ! static INLINE char *__talloc_strlendup_append(char *s, size_t slen,
285 const char *a, size_t alen)
295 - /* this call looks strange, but it makes it work on older solaris boxes */
297 ! len = vsnprintf(&c, 1, fmt, ap2);
299 if (unlikely(len < 0)) {
307 ! len = vsnprintf(NULL, 0, fmt, ap2);
309 if (unlikely(len < 0)) {
316 ! static inline char *__talloc_vaslenprintf_append(char *s, size_t slen,
317 const char *fmt, va_list ap)
318 PRINTF_ATTRIBUTE(3,0);
320 ! static inline char *__talloc_vaslenprintf_append(char *s, size_t slen,
321 const char *fmt, va_list ap)
328 ! alen = vsnprintf(&c, 1, fmt, ap2);
336 ! static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen,
337 const char *fmt, va_list ap)
338 PRINTF_ATTRIBUTE(3,0);
340 ! static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen,
341 const char *fmt, va_list ap)
343 + /* ssize_t isn't present on Windows. */
352 ! alen = vsnprintf(NULL, 0, fmt, ap2);
356 diff -c -r talloc-2.0.1/talloc.h talloc/talloc.h
357 *** talloc-2.0.1/talloc.h Wed Oct 28 16:14:20 2009
358 --- talloc/talloc.h Fri Mar 18 13:03:02 2011
366 + #include <stdint.h>
368 + #include <string.h>
370 #define TALLOC_VERSION_MAJOR 2
371 #define TALLOC_VERSION_MINOR 0