OLD | NEW |
| (Empty) |
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 | |
4 *************** | |
5 *** 30,36 **** | |
6 inspired by http://swapped.cc/halloc/ | |
7 */ | |
8 | |
9 ! #include "replace.h" | |
10 #include "talloc.h" | |
11 | |
12 #ifdef TALLOC_BUILD_VERSION_MAJOR | |
13 --- 30,37 ---- | |
14 inspired by http://swapped.cc/halloc/ | |
15 */ | |
16 | |
17 ! /* Commented out for building within Chromium */ | |
18 ! /* #include "replace.h" */ | |
19 #include "talloc.h" | |
20 | |
21 #ifdef TALLOC_BUILD_VERSION_MAJOR | |
22 *************** | |
23 *** 97,102 **** | |
24 --- 98,110 ---- | |
25 #endif | |
26 #endif | |
27 | |
28 + /* inline isn't supported in C files in Visual Studio 2008 on Windows */ | |
29 + #ifdef _MSC_VER | |
30 + #define INLINE | |
31 + #else | |
32 + #define INLINE inline | |
33 + #endif | |
34 + | |
35 /* this null_context is only used if talloc_enable_leak_report() or | |
36 talloc_enable_leak_report_full() is called, otherwise it remains | |
37 NULL | |
38 *************** | |
39 *** 224,230 **** | |
40 } | |
41 | |
42 /* panic if we get a bad magic value */ | |
43 ! static inline struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr) | |
44 { | |
45 const char *pp = (const char *)ptr; | |
46 struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_H
DR_SIZE); | |
47 --- 232,238 ---- | |
48 } | |
49 | |
50 /* panic if we get a bad magic value */ | |
51 ! static INLINE struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr) | |
52 { | |
53 const char *pp = (const char *)ptr; | |
54 struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_H
DR_SIZE); | |
55 *************** | |
56 *** 277,283 **** | |
57 /* | |
58 return the parent chunk of a pointer | |
59 */ | |
60 ! static inline struct talloc_chunk *talloc_parent_chunk(const void *ptr) | |
61 { | |
62 struct talloc_chunk *tc; | |
63 | |
64 --- 285,291 ---- | |
65 /* | |
66 return the parent chunk of a pointer | |
67 */ | |
68 ! static INLINE struct talloc_chunk *talloc_parent_chunk(const void *ptr) | |
69 { | |
70 struct talloc_chunk *tc; | |
71 | |
72 *************** | |
73 *** 384,390 **** | |
74 /* | |
75 Allocate a bit of memory as a child of an existing pointer | |
76 */ | |
77 ! static inline void *__talloc(const void *context, size_t size) | |
78 { | |
79 struct talloc_chunk *tc = NULL; | |
80 | |
81 --- 392,398 ---- | |
82 /* | |
83 Allocate a bit of memory as a child of an existing pointer | |
84 */ | |
85 ! static INLINE void *__talloc(const void *context, size_t size) | |
86 { | |
87 struct talloc_chunk *tc = NULL; | |
88 | |
89 *************** | |
90 *** 500,506 **** | |
91 more efficient way to add a name to a pointer - the name must point to a | |
92 true string constant | |
93 */ | |
94 ! static inline void _talloc_set_name_const(const void *ptr, const char *name) | |
95 { | |
96 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
97 tc->name = name; | |
98 --- 508,514 ---- | |
99 more efficient way to add a name to a pointer - the name must point to a | |
100 true string constant | |
101 */ | |
102 ! static INLINE void _talloc_set_name_const(const void *ptr, const char *name) | |
103 { | |
104 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
105 tc->name = name; | |
106 *************** | |
107 *** 509,515 **** | |
108 /* | |
109 internal talloc_named_const() | |
110 */ | |
111 ! static inline void *_talloc_named_const(const void *context, size_t size, cons
t char *name) | |
112 { | |
113 void *ptr; | |
114 | |
115 --- 517,523 ---- | |
116 /* | |
117 internal talloc_named_const() | |
118 */ | |
119 ! static INLINE void *_talloc_named_const(const void *context, size_t size, cons
t char *name) | |
120 { | |
121 void *ptr; | |
122 | |
123 *************** | |
124 *** 559,565 **** | |
125 /* | |
126 internal talloc_free call | |
127 */ | |
128 ! static inline int _talloc_free_internal(void *ptr, const char *location) | |
129 { | |
130 struct talloc_chunk *tc; | |
131 | |
132 --- 567,573 ---- | |
133 /* | |
134 internal talloc_free call | |
135 */ | |
136 ! static INLINE int _talloc_free_internal(void *ptr, const char *location) | |
137 { | |
138 struct talloc_chunk *tc; | |
139 | |
140 *************** | |
141 *** 797,803 **** | |
142 talloc_reference() has done. The context and pointer arguments | |
143 must match those given to a talloc_reference() | |
144 */ | |
145 ! static inline int talloc_unreference(const void *context, const void *ptr) | |
146 { | |
147 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
148 struct talloc_reference_handle *h; | |
149 --- 805,811 ---- | |
150 talloc_reference() has done. The context and pointer arguments | |
151 must match those given to a talloc_reference() | |
152 */ | |
153 ! static INLINE int talloc_unreference(const void *context, const void *ptr) | |
154 { | |
155 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
156 struct talloc_reference_handle *h; | |
157 *************** | |
158 *** 877,885 **** | |
159 /* | |
160 add a name to an existing pointer - va_list version | |
161 */ | |
162 ! static inline const char *talloc_set_name_v(const void *ptr, const char *fmt,
va_list ap) PRINTF_ATTRIBUTE(2,0); | |
163 | |
164 ! static inline const char *talloc_set_name_v(const void *ptr, const char *fmt,
va_list ap) | |
165 { | |
166 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
167 tc->name = talloc_vasprintf(ptr, fmt, ap); | |
168 --- 885,893 ---- | |
169 /* | |
170 add a name to an existing pointer - va_list version | |
171 */ | |
172 ! static INLINE const char *talloc_set_name_v(const void *ptr, const char *fmt,
va_list ap) PRINTF_ATTRIBUTE(2,0); | |
173 | |
174 ! static INLINE const char *talloc_set_name_v(const void *ptr, const char *fmt,
va_list ap) | |
175 { | |
176 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr); | |
177 tc->name = talloc_vasprintf(ptr, fmt, ap); | |
178 *************** | |
179 *** 1134,1139 **** | |
180 --- 1142,1151 ---- | |
181 } | |
182 | |
183 | |
184 + static INLINE size_t min_size(size_t a, size_t b) | |
185 + { | |
186 + return a > b ? b : a; | |
187 + } | |
188 | |
189 /* | |
190 A talloc version of realloc. The context argument is only used if | |
191 *************** | |
192 *** 1143,1149 **** | |
193 { | |
194 struct talloc_chunk *tc; | |
195 void *new_ptr; | |
196 ! bool malloced = false; | |
197 | |
198 /* size zero is equivalent to free() */ | |
199 if (unlikely(size == 0)) { | |
200 --- 1155,1161 ---- | |
201 { | |
202 struct talloc_chunk *tc; | |
203 void *new_ptr; | |
204 ! int malloced = 0; | |
205 | |
206 /* size zero is equivalent to free() */ | |
207 if (unlikely(size == 0)) { | |
208 *************** | |
209 *** 1196,1206 **** | |
210 | |
211 if (new_ptr == NULL) { | |
212 new_ptr = malloc(TC_HDR_SIZE+size); | |
213 ! malloced = true; | |
214 } | |
215 | |
216 if (new_ptr) { | |
217 ! memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE); | |
218 } | |
219 } | |
220 else { | |
221 --- 1208,1218 ---- | |
222 | |
223 if (new_ptr == NULL) { | |
224 new_ptr = malloc(TC_HDR_SIZE+size); | |
225 ! malloced = 1; | |
226 } | |
227 | |
228 if (new_ptr) { | |
229 ! memcpy(new_ptr, tc, min_size(tc->size,size) + TC_HDR_SIZ
E); | |
230 } | |
231 } | |
232 else { | |
233 *************** | |
234 *** 1558,1564 **** | |
235 return newp; | |
236 } | |
237 | |
238 ! static inline char *__talloc_strlendup(const void *t, const char *p, size_t le
n) | |
239 { | |
240 char *ret; | |
241 | |
242 --- 1570,1576 ---- | |
243 return newp; | |
244 } | |
245 | |
246 ! static INLINE char *__talloc_strlendup(const void *t, const char *p, size_t le
n) | |
247 { | |
248 char *ret; | |
249 | |
250 *************** | |
251 *** 1581,1586 **** | |
252 --- 1593,1609 ---- | |
253 return __talloc_strlendup(t, p, strlen(p)); | |
254 } | |
255 | |
256 + #ifndef HAVE_STRNLEN | |
257 + #define strnlen rep_strnlen | |
258 + static size_t rep_strnlen(const char* s, size_t n) | |
259 + { | |
260 + if (unlikely(!s)) return 0; | |
261 + int i = 0; | |
262 + while (i < n && *s++ != '\0') | |
263 + ++i; | |
264 + return i; | |
265 + } | |
266 + #endif | |
267 + | |
268 /* | |
269 strndup with a talloc | |
270 */ | |
271 *************** | |
272 *** 1590,1596 **** | |
273 return __talloc_strlendup(t, p, strnlen(p, n)); | |
274 } | |
275 | |
276 ! static inline char *__talloc_strlendup_append(char *s, size_t slen, | |
277 const char *a, size_t alen) | |
278 { | |
279 char *ret; | |
280 --- 1613,1619 ---- | |
281 return __talloc_strlendup(t, p, strnlen(p, n)); | |
282 } | |
283 | |
284 ! static INLINE char *__talloc_strlendup_append(char *s, size_t slen, | |
285 const char *a, size_t alen) | |
286 { | |
287 char *ret; | |
288 *************** | |
289 *** 1699,1709 **** | |
290 int len; | |
291 char *ret; | |
292 va_list ap2; | |
293 - char c; | |
294 | |
295 - /* this call looks strange, but it makes it work on older solaris boxes
*/ | |
296 va_copy(ap2, ap); | |
297 ! len = vsnprintf(&c, 1, fmt, ap2); | |
298 va_end(ap2); | |
299 if (unlikely(len < 0)) { | |
300 return NULL; | |
301 --- 1722,1730 ---- | |
302 int len; | |
303 char *ret; | |
304 va_list ap2; | |
305 | |
306 va_copy(ap2, ap); | |
307 ! len = vsnprintf(NULL, 0, fmt, ap2); | |
308 va_end(ap2); | |
309 if (unlikely(len < 0)) { | |
310 return NULL; | |
311 *************** | |
312 *** 1736,1754 **** | |
313 return ret; | |
314 } | |
315 | |
316 ! static inline char *__talloc_vaslenprintf_append(char *s, size_t slen, | |
317 const char *fmt, va_list ap) | |
318 PRINTF_ATTRIBUTE(3,0); | |
319 | |
320 ! static inline char *__talloc_vaslenprintf_append(char *s, size_t slen, | |
321 const char *fmt, va_list ap) | |
322 { | |
323 ssize_t alen; | |
324 va_list ap2; | |
325 - char c; | |
326 | |
327 va_copy(ap2, ap); | |
328 ! alen = vsnprintf(&c, 1, fmt, ap2); | |
329 va_end(ap2); | |
330 | |
331 if (alen <= 0) { | |
332 --- 1757,1779 ---- | |
333 return ret; | |
334 } | |
335 | |
336 ! static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen, | |
337 const char *fmt, va_list ap) | |
338 PRINTF_ATTRIBUTE(3,0); | |
339 | |
340 ! static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen, | |
341 const char *fmt, va_list ap) | |
342 { | |
343 + /* ssize_t isn't present on Windows. */ | |
344 + #ifndef _MSC_VER | |
345 ssize_t alen; | |
346 + #else | |
347 + size_t alen; | |
348 + #endif | |
349 va_list ap2; | |
350 | |
351 va_copy(ap2, ap); | |
352 ! alen = vsnprintf(NULL, 0, fmt, ap2); | |
353 va_end(ap2); | |
354 | |
355 if (alen <= 0) { | |
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 | |
359 *************** | |
360 *** 28,33 **** | |
361 --- 28,37 ---- | |
362 #include <stdlib.h> | |
363 #include <stdio.h> | |
364 #include <stdarg.h> | |
365 + #ifndef _MSC_VER | |
366 + #include <stdint.h> | |
367 + #endif | |
368 + #include <string.h> | |
369 | |
370 #define TALLOC_VERSION_MAJOR 2 | |
371 #define TALLOC_VERSION_MINOR 0 | |
OLD | NEW |