]> git.ozlabs.org Git - ccan/commitdiff
merge
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2008 03:47:09 +0000 (13:47 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2008 03:47:09 +0000 (13:47 +1000)
.bzrignore
Makefile
ccan/alloc/alloc.c
ccan/talloc/talloc.c
ccan/talloc/talloc.h
tools/run_tests.c

index a1564670d8f36f45e9df85ec241a96899f7681eb..54becb0d0bd9ee33df55568e6cc2f05b485b9e20 100644 (file)
@@ -10,3 +10,4 @@ tools/ccanlint/generated-init-tests
 inter-depends
 test-depends
 lib-depends
+tools/_infotojson/infotojson
index 03d0b82b2c9867caed2cc5f039cad8ecbe153492..0e31fa641dcb62dd9a0279fb9012133e78841206 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,9 +6,12 @@ CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
 ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
 ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
-ALL_LIBS=$(patsubst %, ccan/lib%.a, $(ALL))
+ALL_LIBS=$(patsubst %, ccan/%.o, $(ALL))
 
-test: $(ALL_DIRS:%=test-%)
+libccan.a: $(ALL_LIBS)
+       $(AR) r $@ $^
+
+check: $(ALL_DIRS:%=test-%)
 
 distclean: clean
        rm -f */_info
@@ -19,30 +22,27 @@ $(ALL_DEPENDS): $(ALL_DIRS:=/_info)
 $(ALL_DEPENDS): %/.depends: tools/ccan_depends
        tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
 
-foo:
-       echo $(ALL_LIBS)
-
 $(ALL_LIBS):
-       $(AR) r $@ $^
+       $(LD) -r -o $@ $^ /dev/null
 
-test-ccan/%: tools/run_tests ccan/lib%.a
+test-ccan/%: tools/run_tests ccan/%.o
        @echo Testing $*...
        @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
 
 ccanlint: tools/ccanlint/ccanlint
 
 clean: tools-clean
-       $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`
+       $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name _info`
        $(RM) inter-depends lib-depends test-depends
 
 inter-depends: $(ALL_DEPENDS)
-       for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),ccan/lib\1.a,p' < $$f`; done > $@
+       for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),ccan/\1.o,p' < $$f`; done > $@
 
 test-depends: $(ALL_DEPENDS)
        for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@
 
 lib-depends: $(foreach D,$(ALL),$(wildcard $D/*.[ch]))
-       for c in $(ALL); do echo ccan/lib$$c.a: `ls ccan/$$c/*.c | grep -v /_info.c | sed 's/.c$$/.o/'`; done > $@
+       for c in $(ALL); do echo ccan/$$c.o: `ls ccan/$$c/*.c | grep -v /_info.c | sed 's/.c$$/.o/'`; done > $@
 
 include tools/Makefile
 -include inter-depends
index c70b7fa7817a40da51f15cddedb7ddfb6db6aa18..5c851d824469b334c2425d83ef2ce36d9a317cbb 100644 (file)
@@ -1061,7 +1061,7 @@ void alloc_visualize(FILE *out, void *pool, unsigned long poolsize)
                        if (meta[j / 8] & (1 << (j % 8)))
                                total++;
 
-               printf("  %u: %u/%u (%u%% density)\n",
+               printf("  %u: %u/%zu (%zu%% density)\n",
                       uc->size[j], total, SUBPAGE_METAOFF / uc->size[i],
                       (total * 100) / (SUBPAGE_METAOFF / uc->size[i]));
        }
index 59a981b48c8631dde962ee5326c1dcfde4d92a00..ba998f5424b6570571a3bbe64b0bbdff82bba2ba 100644 (file)
@@ -35,6 +35,8 @@
 #include <string.h>
 #include <stdint.h>
 #include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 /* use this to force every realloc to change the pointer, to stress test
    code that might not cope */
@@ -78,7 +80,7 @@
    NULL
 */
 static void *null_context;
-static void *autofree_context;
+static pid_t *autofree_context;
 
 static void *(*tc_external_alloc)(void *parent, size_t size);
 static void (*tc_external_free)(void *ptr, void *parent);
@@ -378,8 +380,10 @@ static inline int _talloc_free(void *ptr)
                tc->destructor = NULL;
        }
 
+       if (unlikely(tc->flags & TALLOC_FLAG_EXT_ALLOC))
+               oldparent = talloc_parent(ptr);
+
        if (tc->parent) {
-               oldparent = TC_PTR_FROM_CHUNK(tc->parent);
                _TLIST_REMOVE(tc->parent->child, tc);
                if (tc->parent->child) {
                        tc->parent->child->parent = tc->parent;
@@ -1334,7 +1338,8 @@ static int talloc_autofree_destructor(void *ptr)
 
 static void talloc_autofree(void)
 {
-       _talloc_free(autofree_context);
+       if (autofree_context && *autofree_context == getpid())
+               _talloc_free(autofree_context);
 }
 
 /*
@@ -1343,8 +1348,11 @@ static void talloc_autofree(void)
 */
 void *talloc_autofree_context(void)
 {
-       if (autofree_context == NULL) {
-               autofree_context = _talloc_named_const(NULL, 0, "autofree_context");
+       if (autofree_context == NULL || *autofree_context != getpid()) {
+               autofree_context = talloc(NULL, pid_t);
+               *autofree_context = getpid();
+               talloc_set_name_const(autofree_context, "autofree_context");
+               
                talloc_set_destructor(autofree_context, talloc_autofree_destructor);
                atexit(talloc_autofree);
        }
index da416a4b77e27acc619b10f4e676286444be1784..8b0f8a38bc82d6782dbe29c2a56c4d3c1daaab63 100644 (file)
@@ -442,12 +442,12 @@ void talloc_free_children(void *ptr);
 #define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
 
 /**
- * talloc_zero_array - allocate an array of zeroed types
+ * talloc_array_size - allocate an array of elements of the given size
  * @ctx: context to be parent of this allocation, or NULL.
- * @type: the type to be allocated.
+ * @size: the size of each element
  * @count: the number of elements to be allocated.
  *
- * Just like talloc_array, but zeroes the memory.
+ * Typeless form of talloc_array.
  */
 #define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
 
index 2f657d0533ee8c92e5916ca09c529407b80d5257..a1fbc614918851e50657adb8bfa53caeba695297 100644 (file)
@@ -106,14 +106,11 @@ static int build(const char *dir, const char *name, int fail)
        char **deps;
 
        for (deps = get_deps(objs, dir); *deps; deps++) {
-               char *end;
                if (!strstarts(*deps, "ccan/"))
                        continue;
 
-               end = strrchr(*deps, '/') + 1;
-               /* ccan/foo -> ccan/libfoo.a */
-               externals = talloc_asprintf_append(externals,
-                                                  " ccan/lib%s.a", end);
+               /* ccan/foo -> ccan/foo.o */
+               externals = talloc_asprintf_append(externals, " %s.o", *deps);
        }
 
        cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s%s%s",