summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore1
-rw-r--r--Makefile20
-rw-r--r--ccan/alloc/alloc.c2
-rw-r--r--ccan/talloc/talloc.c18
-rw-r--r--ccan/talloc/talloc.h6
-rw-r--r--tools/run_tests.c7
6 files changed, 30 insertions, 24 deletions
diff --git a/.bzrignore b/.bzrignore
index a1564670..54becb0d 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -10,3 +10,4 @@ tools/ccanlint/generated-init-tests
inter-depends
test-depends
lib-depends
+tools/_infotojson/infotojson
diff --git a/Makefile b/Makefile
index 03d0b82b..0e31fa64 100644
--- 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
diff --git a/ccan/alloc/alloc.c b/ccan/alloc/alloc.c
index c70b7fa7..5c851d82 100644
--- a/ccan/alloc/alloc.c
+++ b/ccan/alloc/alloc.c
@@ -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]));
}
diff --git a/ccan/talloc/talloc.c b/ccan/talloc/talloc.c
index 59a981b4..ba998f54 100644
--- a/ccan/talloc/talloc.c
+++ b/ccan/talloc/talloc.c
@@ -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);
}
diff --git a/ccan/talloc/talloc.h b/ccan/talloc/talloc.h
index da416a4b..8b0f8a38 100644
--- a/ccan/talloc/talloc.h
+++ b/ccan/talloc/talloc.h
@@ -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__)
diff --git a/tools/run_tests.c b/tools/run_tests.c
index 2f657d05..a1fbc614 100644
--- a/tools/run_tests.c
+++ b/tools/run_tests.c
@@ -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",