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