Updated package list to match new versions / new packages.
[beastbuild.git] / ccache-win32-xmemfuncs.diff
1 Common subdirectories: ./.svn and /c/beastbuild/src/ccache-win32-20090430/.svn
2 diff -u ./args.c /c/beastbuild/src/ccache-win32-20090430/args.c
3 --- ./args.c    2009-04-30 14:09:34 +0000
4 +++ /c/beastbuild/src/ccache-win32-20090430/args.c      2009-05-27 07:00:17 +0000
5 @@ -48,7 +48,7 @@
6  {
7         while (n--) {
8                 args->argc--;
9 -               free(args->argv[args->argc]);
10 +               x_free(args->argv[args->argc]);
11                 args->argv[args->argc] = NULL;
12         }
13  }
14 @@ -56,7 +56,7 @@
15  /* remove the first element of the argument list */
16  void args_remove_first(ARGS *args)
17  {
18 -       free(args->argv[0]);
19 +       x_free(args->argv[0]);
20         memmove(&args->argv[0], 
21                 &args->argv[1],
22                 args->argc * sizeof(args->argv[0]));
23 @@ -79,7 +79,7 @@
24         int i;
25         for (i=0; i<args->argc; ) {
26                 if (strncmp(args->argv[i], prefix, strlen(prefix)) == 0) {
27 -                       free(args->argv[i]);
28 +                       x_free(args->argv[i]);
29                         memmove(&args->argv[i], 
30                                 &args->argv[i+1], 
31                                 args->argc * sizeof(args->argv[i]));
32 diff -u ./ccache.c /c/beastbuild/src/ccache-win32-20090430/ccache.c
33 --- ./ccache.c  2009-05-27 07:03:42 +0000
34 +++ /c/beastbuild/src/ccache-win32-20090430/ccache.c    2009-05-27 07:02:13 +0000
35 @@ -99,14 +99,14 @@
36                 if (!direct_i_file) {
37                         unlink(i_tmpfile);
38                 }
39 -               free(i_tmpfile);
40 +               x_free(i_tmpfile);
41                 i_tmpfile = NULL;
42         }
43  
44         /* delete the cpp stderr file if necessary */
45         if (cpp_stderr) {
46                 unlink(cpp_stderr);
47 -               free(cpp_stderr);
48 +               x_free(cpp_stderr);
49                 cpp_stderr = NULL;
50         }
51  
52 @@ -246,10 +246,10 @@
53         cc_log("Placed %s into cache\n", output_file);
54         stats_tocache(file_size(&st1) + file_size(&st2));
55  
56 -       free(tmp_hashname);
57 -       free(tmp_stderr);
58 -       free(tmp_stdout);
59 -       free(path_stderr);
60 +       x_free(tmp_hashname);
61 +       x_free(tmp_stderr);
62 +       x_free(tmp_stdout);
63 +       x_free(path_stderr);
64  }
65  
66  /* find the hash for a command. The hash includes all argument lists,
67 @@ -343,7 +343,7 @@
68                 char *cwd = gnu_getcwd();
69                 if (cwd) {
70                         hash_string(cwd);
71 -                       free(cwd);
72 +                       x_free(cwd);
73                 }
74         }
75  
76 @@ -422,7 +422,7 @@
77                 cpp_stderr = path_stderr;
78         } else {        
79                 unlink(path_stderr);
80 -               free(path_stderr);
81 +               x_free(path_stderr);
82         }
83  
84         /* we use a N level subdir for the cache path to reduce the impact
85 @@ -438,7 +438,7 @@
86                         failed();
87                 }
88                 x_asprintf(&p, "%s/%c", hash_dir, s[i]);
89 -               free(hash_dir);
90 +               x_free(hash_dir);
91                 hash_dir = p;
92         }
93         if (create_dir(hash_dir) != 0) {
94 @@ -446,7 +446,7 @@
95                 failed();
96         }
97         x_asprintf(&hashname, "%s/%s", hash_dir, s+nlevels);
98 -       free(hash_dir);
99 +       x_free(hash_dir);
100  }
101  
102  
103 @@ -465,7 +465,7 @@
104         fd_stderr = open(stderr_file, O_RDONLY | O_BINARY);
105         if (fd_stderr == -1) {
106                 /* it isn't in cache ... */
107 -               free(stderr_file);
108 +               x_free(stderr_file);
109                 return;
110         }
111  
112 @@ -473,7 +473,7 @@
113         if (stat(hashname, &st) != 0) {
114                 close(fd_stderr);
115                 unlink(stderr_file);
116 -               free(stderr_file);
117 +               x_free(stderr_file);
118                 return;
119         }
120  
121 @@ -481,7 +481,7 @@
122         if (first && getenv("CCACHE_RECACHE")) {
123                 close(fd_stderr);
124                 unlink(stderr_file);
125 -               free(stderr_file);
126 +               x_free(stderr_file);
127                 return;
128         }
129  
130 @@ -521,7 +521,7 @@
131                 unlink(stderr_file);
132                 return;
133         }
134 -       free(stderr_file);
135 +       x_free(stderr_file);
136  
137         if (ret == -1) {
138                 ret = copy_file(hashname, output_file);
139 @@ -542,7 +542,7 @@
140                 if (!direct_i_file) {
141                         unlink(i_tmpfile);
142                 }
143 -               free(i_tmpfile);
144 +               x_free(i_tmpfile);
145                 i_tmpfile = NULL;
146         }
147  
148 @@ -552,7 +552,7 @@
149                 copy_fd(fd_cpp_stderr, 2);
150                 close(fd_cpp_stderr);
151                 unlink(cpp_stderr);
152 -               free(cpp_stderr);
153 +               x_free(cpp_stderr);
154                 cpp_stderr = NULL;
155         }
156  
157 @@ -583,7 +583,7 @@
158         /* we might be being invoked like "ccache gcc -c foo.c" */
159         if (strcmp(base, MYNAME) == 0) {
160                 args_remove_first(orig_args);
161 -               free(base);
162 +               x_free(base);
163                 // if (strchr(argv[1],'/')) {
164                 if (strchr(argv[1],'/') || strchr(argv[1],'\\')) {
165                         /* a full path was given */
166 Only in /c/beastbuild/src/ccache-win32-20090430/: ccache.c.rej
167 Only in /c/beastbuild/src/ccache-win32-20090430/: ccache.c~
168 diff -u ./ccache.h /c/beastbuild/src/ccache-win32-20090430/ccache.h
169 --- ./ccache.h  2009-04-30 14:09:34 +0000
170 +++ /c/beastbuild/src/ccache-win32-20090430/ccache.h    2009-05-27 07:00:17 +0000
171 @@ -97,6 +97,7 @@
172  char *x_strdup(const char *s);
173  void *x_realloc(void *ptr, size_t size);
174  void *x_malloc(size_t size);
175 +void x_free (void *ptr);
176  void traverse(const char *dir, void (*fn)(const char *, struct stat *));
177  char *str_basename(const char *s);
178  char *dirname(char *s);
179 Only in /c/beastbuild/src/ccache-win32-20090430/: ccache.h~
180 diff -u ./cleanup.c /c/beastbuild/src/ccache-win32-20090430/cleanup.c
181 --- ./cleanup.c 2009-04-30 14:09:34 +0000
182 +++ /c/beastbuild/src/ccache-win32-20090430/cleanup.c   2009-05-27 07:00:17 +0000
183 @@ -54,10 +54,10 @@
184  
185         p = str_basename(fname);
186         if (strcmp(p, "stats") == 0) {
187 -               free(p);
188 +               x_free(p);
189                 return;
190         }
191 -       free(p);
192 +       x_free(p);
193  
194         if (num_files == allocated) {
195                 allocated = 10000 + num_files*2;
196 @@ -123,11 +123,11 @@
197  
198         /* free it up */
199         for (i=0;i<num_files;i++) {
200 -               free(files[i]->fname);
201 -               free(files[i]);
202 +               x_free(files[i]->fname);
203 +               x_free(files[i]);
204                 files[i] = NULL;
205         }
206 -       if (files) free(files);
207 +       if (files) x_free(files);
208         allocated = 0;
209         files = NULL;
210  
211 @@ -152,8 +152,8 @@
212                 cleanup_dir(dname, 
213                             counters[STATS_MAXFILES], 
214                             counters[STATS_MAXSIZE]);
215 -               free(dname);
216 -               free(sfile);
217 +               x_free(dname);
218 +               x_free(sfile);
219         }
220  }
221  
222 @@ -167,10 +167,10 @@
223  
224         p = str_basename(fname);
225         if (strcmp(p, "stats") == 0) {
226 -               free(p);
227 +               x_free(p);
228                 return;
229         }
230 -       free(p);
231 +       x_free(p);
232  
233         unlink(fname);
234  }
235 @@ -185,7 +185,7 @@
236         for (i=0;i<=0xF;i++) {
237                 x_asprintf(&dname, "%s/%1x", dir, i);
238                 traverse(dir, wipe_fn);
239 -               free(dname);
240 +               x_free(dname);
241         }
242  
243         /* and fix the counters */
244 diff -u ./execute.c /c/beastbuild/src/ccache-win32-20090430/execute.c
245 --- ./execute.c 2009-05-27 07:03:42 +0000
246 +++ /c/beastbuild/src/ccache-win32-20090430/execute.c   2009-05-27 07:00:17 +0000
247 @@ -213,20 +213,20 @@
248                                         char *p = str_basename(buf);
249                                         if (strcmp(p, exclude_name) == 0) {
250                                                 /* its a link to "ccache" ! */
251 -                                               free(p);
252 -                                               free(buf);
253 +                                               x_free(p);
254 +                                               x_free(buf);
255                                                 continue;
256                                         }
257 -                                       free(buf);
258 -                                       free(p);
259 +                                       x_free(buf);
260 +                                       x_free(p);
261                                 }
262                         }
263  
264                         /* found it! */
265 -                       free(path);
266 +                       x_free(path);
267                         return fname;
268                 }
269 -               free(fname);
270 +               x_free(fname);
271         }
272  
273         return NULL;
274 Only in /c/beastbuild/src/ccache-win32-20090430/: execute.c~
275 diff -u ./stats.c /c/beastbuild/src/ccache-win32-20090430/stats.c
276 --- ./stats.c   2009-04-30 14:09:34 +0000
277 +++ /c/beastbuild/src/ccache-win32-20090430/stats.c     2009-05-27 07:00:17 +0000
278 @@ -168,7 +168,7 @@
279         if (need_cleanup) {
280                 char *p = dirname(stats_file);
281                 cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE]);
282 -               free(p);
283 +               x_free(p);
284         }
285  }
286  
287 @@ -221,7 +221,7 @@
288                 }
289  
290                 stats_read(fname, counters);
291 -               free(fname);
292 +               x_free(fname);
293  
294                 /* oh what a nasty hack ... */
295                 if (dir == -1) {
296 @@ -261,13 +261,13 @@
297  
298         x_asprintf(&fname, "%s/stats", cache_dir);
299         unlink(fname);
300 -       free(fname);
301 +       x_free(fname);
302  
303         for (dir=0;dir<=0xF;dir++) {
304                 x_asprintf(&fname, "%s/%1x/stats", cache_dir, dir);
305                 fd = safe_open(fname);
306                 if (fd == -1) {
307 -                       free(fname);
308 +                       x_free(fname);
309                         continue;
310                 }
311                 memset(counters, 0, sizeof(counters));
312 @@ -280,7 +280,7 @@
313                 }
314                 write_stats(fd, counters);
315                 close(fd);
316 -               free(fname);
317 +               x_free(fname);
318         }
319  }
320  
321 @@ -308,7 +308,7 @@
322                 x_asprintf(&cdir, "%s/%1x", cache_dir, dir);
323                 create_dir(cdir);
324                 x_asprintf(&fname, "%s/stats", cdir);
325 -               free(cdir);
326 +               x_free(cdir);
327  
328                 memset(counters, 0, sizeof(counters));
329                 fd = safe_open(fname);
330 @@ -324,7 +324,7 @@
331                         write_stats(fd, counters);
332                         close(fd);
333                 }
334 -               free(fname);
335 +               x_free(fname);
336         }
337  }
338  
339 @@ -350,5 +350,5 @@
340                 close(fd);
341         }
342  
343 -       free(stats_file);
344 +       x_free(stats_file);
345  }
346 diff -u ./util.c /c/beastbuild/src/ccache-win32-20090430/util.c
347 --- ./util.c    2009-05-27 07:03:42 +0000
348 +++ /c/beastbuild/src/ccache-win32-20090430/util.c      2009-05-27 07:00:17 +0000
349 @@ -81,14 +81,14 @@
350  
351         fd1 = open(src, O_RDONLY|O_BINARY);
352         if (fd1 == -1) {
353 -               free(tmp_name);
354 +               x_free(tmp_name);
355                 return -1;
356         }
357  
358         fd2 = mkstemp(tmp_name);
359         if (fd2 == -1) {
360                 close(fd1);
361 -               free(tmp_name);
362 +               x_free(tmp_name);
363                 return -1;
364         }
365  
366 @@ -97,7 +97,7 @@
367                         close(fd2);
368                         close(fd1);
369                         unlink(tmp_name);
370 -                       free(tmp_name);
371 +                       x_free(tmp_name);
372                         return -1;
373                 }
374         }
375 @@ -114,7 +114,7 @@
376         /* the close can fail on NFS if out of space */
377         if (close(fd2) == -1) {
378                 unlink(tmp_name);
379 -               free(tmp_name);
380 +               x_free(tmp_name);
381                 return -1;
382         }
383  
384 @@ -122,11 +122,11 @@
385  
386         if (rename(tmp_name, dest) == -1) {
387                 unlink(tmp_name);
388 -               free(tmp_name);
389 +               x_free(tmp_name);
390                 return -1;
391         }
392  
393 -       free(tmp_name);
394 +       x_free(tmp_name);
395  
396         return 0;
397  }
398 @@ -158,17 +158,22 @@
399  /*
400    this is like asprintf() but dies if the malloc fails
401    note that we use vsnprintf in a rather poor way to make this more portable
402 +
403 +  we return an x_strdup copy of the string so that it can be freed with x_free
404 +  or reallocated with x_realloc
405  */
406  void x_asprintf(char **ptr, const char *format, ...)
407  {
408         va_list ap;
409 +       char *str = NULL;
410  
411 -       *ptr = NULL;
412         va_start(ap, format);
413 -       vasprintf(ptr, format, ap);
414 +       vasprintf(&str, format, ap);
415         va_end(ap);
416         
417 -       if (!ptr) fatal("out of memory in x_asprintf");
418 +       if (!str) fatal("out of memory in x_asprintf");
419 +       *ptr = x_strdup (str);
420 +       free (str);
421  }
422  
423  /*
424 @@ -176,24 +181,25 @@
425  */
426  char *x_strdup(const char *s)
427  {
428 -       char *ret;
429 -       ret = strdup(s);
430 -       if (!ret) {
431 -               fatal("out of memory in strdup\n");
432 -       }
433 +       size_t size = strlen (s) + 1;
434 +       char *ret = x_malloc (size);
435 +       memcpy (ret, s, size);
436         return ret;
437  }
438  
439 +#define X_MEM_OFFSET 32            /* largest alignment requirement */
440 +
441  /*
442    this is like malloc() but dies if the malloc fails
443  */
444  void *x_malloc(size_t size)
445  {
446 -       void *ret;
447 -       ret = malloc(size);
448 +       void *ret = malloc(size + X_MEM_OFFSET);
449         if (!ret) {
450                 fatal("out of memory in malloc\n");
451         }
452 +       *(size_t *)ret = size;
453 +       ret += X_MEM_OFFSET;
454         return ret;
455  }
456  
457 @@ -203,18 +209,34 @@
458  void *x_realloc(void *ptr, size_t size)
459  {
460         void *p2;
461 -       if (!ptr) return x_malloc(size);
462 -       p2 = malloc(size);
463 -       if (!p2) {
464 -               fatal("out of memory in x_realloc");
465 +
466 +       if (size == 0) {
467 +               x_free (ptr);
468 +               return NULL;
469         }
470 -       if (ptr) {
471 -               memcpy(p2, ptr, size);
472 -               free(ptr);
473 +       p2 = x_malloc (size);
474 +       if (!ptr) {
475 +               return p2;
476 +       }
477 +       else
478 +       {
479 +               char *cptr = (char *)ptr;
480 +               size_t old_size = *(size_t *)(cptr - X_MEM_OFFSET);
481 +               size_t copy_size = (size < old_size) ? size : old_size;
482 +               memcpy(p2, ptr, copy_size);
483 +               x_free(ptr);
484         }
485         return p2;
486  }
487  
488 +void x_free(void *ptr)
489 +{
490 +       if (ptr) {
491 +               char *cptr = ptr;
492 +               free (cptr - X_MEM_OFFSET);
493 +       }
494 +}
495 +
496  
497  /* 
498     revsusive directory traversal - used for cleanup
499 @@ -246,7 +268,7 @@
500                         if (errno != ENOENT) {
501                                 perror(fname);
502                         }
503 -                       free(fname);
504 +                       x_free(fname);
505                         continue;
506                 }
507  
508 @@ -255,7 +277,7 @@
509                 }
510  
511                 fn(fname, &st);
512 -               free(fname);
513 +               x_free(fname);
514         }
515  
516         closedir(d);
517 @@ -425,7 +447,7 @@
518         {
519                 int len = readlink(path, ret, maxlen-1);
520                 if (len == -1) {
521 -                       free(ret);
522 +                       x_free(ret);
523                         return NULL;
524                 }
525                 ret[len] = 0;
526 @@ -434,10 +456,10 @@
527  #endif
528         if (p) {
529                 p = x_strdup(p);
530 -               free(ret);
531 +               x_free(ret);
532                 return p;
533         }
534 -       free(ret);
535 +       x_free(ret);
536         return NULL;
537  #endif
538  }
539 @@ -452,7 +474,7 @@
540                 if (getcwd(buffer, size) == buffer) {
541                         return buffer;
542                 }
543 -               free(buffer);
544 +               x_free(buffer);
545                 if (errno != ERANGE) {
546                         return 0;
547                 }
548 Only in /c/beastbuild/src/ccache-win32-20090430/: util.c~