Fix race in WebRTC logging.
[chromium-blink-merge.git] / third_party / talloc / chromium.patch
blobd9354516c7cb21278c8afa64cb660ba014e3cb99
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 */
9 ! #include "replace.h"
10 #include "talloc.h"
12 #ifdef TALLOC_BUILD_VERSION_MAJOR
13 --- 30,37 ----
14 inspired by http://swapped.cc/halloc/
17 ! /* Commented out for building within Chromium */
18 ! /* #include "replace.h" */
19 #include "talloc.h"
21 #ifdef TALLOC_BUILD_VERSION_MAJOR
22 ***************
23 *** 97,102 ****
24 --- 98,110 ----
25 #endif
26 #endif
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
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 ****
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);
47 --- 232,238 ----
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);
55 ***************
56 *** 277,283 ****
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;
64 --- 285,291 ----
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;
72 ***************
73 *** 384,390 ****
74 /*
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;
81 --- 392,398 ----
82 /*
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;
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
94 ! static inline void _talloc_set_name_const(const void *ptr, const char *name)
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
102 ! static INLINE void _talloc_set_name_const(const void *ptr, const char *name)
104 struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
105 tc->name = name;
106 ***************
107 *** 509,515 ****
109 internal talloc_named_const()
111 ! static inline void *_talloc_named_const(const void *context, size_t size, const char *name)
113 void *ptr;
115 --- 517,523 ----
117 internal talloc_named_const()
119 ! static INLINE void *_talloc_named_const(const void *context, size_t size, const char *name)
121 void *ptr;
123 ***************
124 *** 559,565 ****
126 internal talloc_free call
128 ! static inline int _talloc_free_internal(void *ptr, const char *location)
130 struct talloc_chunk *tc;
132 --- 567,573 ----
134 internal talloc_free call
136 ! static INLINE int _talloc_free_internal(void *ptr, const char *location)
138 struct talloc_chunk *tc;
140 ***************
141 *** 797,803 ****
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;
149 --- 805,811 ----
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;
157 ***************
158 *** 877,885 ****
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);
168 --- 885,893 ----
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);
178 ***************
179 *** 1134,1139 ****
180 --- 1142,1151 ----
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
191 ***************
192 *** 1143,1149 ****
194 struct talloc_chunk *tc;
195 void *new_ptr;
196 ! bool malloced = false;
198 /* size zero is equivalent to free() */
199 if (unlikely(size == 0)) {
200 --- 1155,1161 ----
202 struct talloc_chunk *tc;
203 void *new_ptr;
204 ! int malloced = 0;
206 /* size zero is equivalent to free() */
207 if (unlikely(size == 0)) {
208 ***************
209 *** 1196,1206 ****
211 if (new_ptr == NULL) {
212 new_ptr = malloc(TC_HDR_SIZE+size);
213 ! malloced = true;
216 if (new_ptr) {
217 ! memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
220 else {
221 --- 1208,1218 ----
223 if (new_ptr == NULL) {
224 new_ptr = malloc(TC_HDR_SIZE+size);
225 ! malloced = 1;
228 if (new_ptr) {
229 ! memcpy(new_ptr, tc, min_size(tc->size,size) + TC_HDR_SIZE);
232 else {
233 ***************
234 *** 1558,1564 ****
235 return newp;
238 ! static inline char *__talloc_strlendup(const void *t, const char *p, size_t len)
240 char *ret;
242 --- 1570,1576 ----
243 return newp;
246 ! static INLINE char *__talloc_strlendup(const void *t, const char *p, size_t len)
248 char *ret;
250 ***************
251 *** 1581,1586 ****
252 --- 1593,1609 ----
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;
261 + int i = 0;
262 + while (i < n && *s++ != '\0')
263 + ++i;
264 + return i;
266 + #endif
269 strndup with a talloc
271 ***************
272 *** 1590,1596 ****
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)
279 char *ret;
280 --- 1613,1619 ----
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)
287 char *ret;
288 ***************
289 *** 1699,1709 ****
290 int len;
291 char *ret;
292 va_list ap2;
293 - char c;
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;
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;
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)
323 ssize_t alen;
324 va_list ap2;
325 - char c;
327 va_copy(ap2, ap);
328 ! alen = vsnprintf(&c, 1, fmt, ap2);
329 va_end(ap2);
331 if (alen <= 0) {
332 --- 1757,1779 ----
333 return ret;
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. */
344 + #ifndef _MSC_VER
345 ssize_t alen;
346 + #else
347 + size_t alen;
348 + #endif
349 va_list ap2;
351 va_copy(ap2, ap);
352 ! alen = vsnprintf(NULL, 0, fmt, ap2);
353 va_end(ap2);
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>
370 #define TALLOC_VERSION_MAJOR 2
371 #define TALLOC_VERSION_MINOR 0