From: Rusty Russell Date: Tue, 10 Jun 2014 03:36:16 +0000 (+0930) Subject: strset: use tal instead of talloc in examples and tools. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=f3eecc2c76e7ebbd0024b1528326bbb18a7d7742 strset: use tal instead of talloc in examples and tools. Signed-off-by: Rusty Russell --- diff --git a/ccan/strset/_info b/ccan/strset/_info index 1c7426e6..4984959c 100644 --- a/ccan/strset/_info +++ b/ccan/strset/_info @@ -15,7 +15,7 @@ * Example: * // Print all words in order. * #include - * #include + * #include * #include * #include * @@ -31,7 +31,7 @@ * char *file, *word; * * strset_init(&words); - * file = grab_fd(NULL, 0, NULL); + * file = grab_fd(NULL, 0); * if (!file) * err(1, "Reading stdin"); * diff --git a/ccan/strset/tools/Makefile b/ccan/strset/tools/Makefile index 77b1f7d7..3222e34e 100644 --- a/ccan/strset/tools/Makefile +++ b/ccan/strset/tools/Makefile @@ -1,11 +1,31 @@ -CFLAGS=-Wall -Werror -O3 -I../../.. -#CFLAGS=-Wall -Werror -g -I../../.. +CCANDIR=../../.. +CFLAGS=-Wall -Werror -O3 -I$(CCANDIR) +#CFLAGS=-Wall -Werror -g -I$(CCANDIR) all: cbspeed speed -cbspeed: cbspeed.o ../../talloc.o ../../str_talloc.o ../../grab_file.o ../../str.o ../../time.o ../../noerr.o +CCAN_OBJS:=ccan-tal.o ccan-tal-str.o ccan-tal-grab_file.o ccan-take.o ccan-time.o ccan-str.o ccan-noerr.o ccan-list.o -speed: speed.o ../../talloc.o ../../str_talloc.o ../../grab_file.o ../../str.o ../../time.o ../../noerr.o +cbspeed: cbspeed.o $(CCAN_OBJS) + +speed: speed.o $(CCAN_OBJS) clean: - rm -f cbspeed speed speed.o cbspeed.o + rm -f cbspeed speed speed.o cbspeed.o *.o + +ccan-tal.o: $(CCANDIR)/ccan/tal/tal.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-tal-str.o: $(CCANDIR)/ccan/tal/str/str.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-take.o: $(CCANDIR)/ccan/take/take.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-tal-grab_file.o: $(CCANDIR)/ccan/tal/grab_file/grab_file.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-time.o: $(CCANDIR)/ccan/time/time.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-list.o: $(CCANDIR)/ccan/list/list.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-str.o: $(CCANDIR)/ccan/str/str.c + $(CC) $(CFLAGS) -c -o $@ $< +ccan-noerr.o: $(CCANDIR)/ccan/noerr/noerr.c + $(CC) $(CFLAGS) -c -o $@ $< diff --git a/ccan/strset/tools/cbspeed.c b/ccan/strset/tools/cbspeed.c index 3018da98..9763efcb 100644 --- a/ccan/strset/tools/cbspeed.c +++ b/ccan/strset/tools/cbspeed.c @@ -19,9 +19,9 @@ #15: Post-Churn lookup (miss): 189-197(191) #16: Post-Churn lookup (random): 500-531(506) */ -#include -#include -#include +#include +#include +#include #include #include #include @@ -395,23 +395,22 @@ int main(int argc, char *argv[]) critbit0_tree ct; char **words, **misswords; - words = strsplit(NULL, grab_file(NULL, - argv[1] ? argv[1] : "/usr/share/dict/words", - NULL), "\n"); + words = tal_strsplit(NULL, grab_file(NULL, + argv[1] ? argv[1] : "/usr/share/dict/words"), "\n", STR_NO_EMPTY); ct.root = NULL; - num = talloc_array_length(words) - 1; + num = tal_count(words) - 1; printf("%zu words\n", num); /* Append and prepend last char for miss testing. */ - misswords = talloc_array(words, char *, num); + misswords = tal_arr(words, char *, num); for (i = 0; i < num; i++) { char lastc; if (strlen(words[i])) lastc = words[i][strlen(words[i])-1]; else lastc = 'z'; - misswords[i] = talloc_asprintf(misswords, "%c%s%c%c", - lastc, words[i], lastc, lastc); + misswords[i] = tal_fmt(misswords, "%c%s%c%c", + lastc, words[i], lastc, lastc); } printf("#01: Initial insert: "); diff --git a/ccan/strset/tools/speed.c b/ccan/strset/tools/speed.c index 0006517f..972d52f7 100644 --- a/ccan/strset/tools/speed.c +++ b/ccan/strset/tools/speed.c @@ -19,8 +19,8 @@ #15: Post-Churn lookup (miss): 175-186(176) #16: Post-Churn lookup (random): 522-534(525) */ -#include -#include +#include +#include #include #include #include @@ -46,23 +46,23 @@ int main(int argc, char *argv[]) struct strset set; char **words, **misswords; - words = strsplit(NULL, grab_file(NULL, - argv[1] ? argv[1] : "/usr/share/dict/words", - NULL), "\n"); + words = tal_strsplit(NULL, grab_file(NULL, + argv[1] ? argv[1] : "/usr/share/dict/words"), + "\n", STR_NO_EMPTY); strset_init(&set); - num = talloc_array_length(words) - 1; + num = tal_count(words) - 1; printf("%zu words\n", num); /* Append and prepend last char for miss testing. */ - misswords = talloc_array(words, char *, num); + misswords = tal_arr(words, char *, num); for (i = 0; i < num; i++) { char lastc; if (strlen(words[i])) lastc = words[i][strlen(words[i])-1]; else lastc = 'z'; - misswords[i] = talloc_asprintf(misswords, "%c%s%c%c", - lastc, words[i], lastc, lastc); + misswords[i] = tal_fmt(misswords, "%c%s%c%c", + lastc, words[i], lastc, lastc); } printf("#01: Initial insert: ");