Commit dc8042b4 authored by Rusty Russell's avatar Rusty Russell

tools: use tal instead of talloc.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent aabf300e
...@@ -2,13 +2,16 @@ ALL_TOOLS = tools/configurator/configurator tools/ccan_depends tools/doc_extract ...@@ -2,13 +2,16 @@ ALL_TOOLS = tools/configurator/configurator tools/ccan_depends tools/doc_extract
LDLIBS = -lrt LDLIBS = -lrt
DEP_OBJS = ccan/err/err.o \ DEP_OBJS = ccan/err/err.o \
ccan/foreach/foreach.o \ ccan/foreach/foreach.o \
ccan/list/list.o \
ccan/noerr/noerr.o \ ccan/noerr/noerr.o \
ccan/rbuf/rbuf.o \ ccan/rbuf/rbuf.o \
ccan/read_write_all/read_write_all.o \ ccan/read_write_all/read_write_all.o \
ccan/str/debug.o \ ccan/str/debug.o \
ccan/str/str.o \ ccan/str/str.o \
ccan/str_talloc/str_talloc.o \ ccan/take/take.o \
ccan/talloc/talloc.o \ ccan/tal/tal.o \
ccan/tal/link/link.o \
ccan/tal/str/str.o \
ccan/time/time.o \ ccan/time/time.o \
tools/read_config_header.o \ tools/read_config_header.o \
tools/ccan_dir.o \ tools/ccan_dir.o \
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <stdio.h> #include <stdio.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/talloc/talloc.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -43,11 +42,9 @@ int main(int argc, char *argv[]) ...@@ -43,11 +42,9 @@ int main(int argc, char *argv[])
errx(1, "--non-ccan needs --compile"); errx(1, "--non-ccan needs --compile");
if (compile) if (compile)
deps = get_deps(talloc_autofree_context(), argv[1], deps = get_deps(NULL, argv[1], style, recurse, compile_info);
style, recurse, compile_info);
else else
deps = get_safe_ccan_deps(talloc_autofree_context(), deps = get_safe_ccan_deps(NULL, argv[1], style, recurse);
argv[1], style, recurse);
for (i = 0; deps[i]; i++) for (i = 0; deps[i]; i++)
if (strstarts(deps[i], "ccan/") == ccan) if (strstarts(deps[i], "ccan/") == ccan)
......
#include <ccan/talloc/talloc.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include "tools.h" #include "tools.h"
#include <assert.h> #include <assert.h>
...@@ -27,14 +26,13 @@ const char *find_ccan_dir(const char *base) ...@@ -27,14 +26,13 @@ const char *find_ccan_dir(const char *base)
if (!ccan_dir) { if (!ccan_dir) {
if (base[0] != '/') { if (base[0] != '/') {
const char *tmpctx = talloc_getcwd(NULL); const char *tmpctx = tal_getcwd(NULL);
find_ccan_dir(talloc_asprintf(tmpctx, "%s/%s", find_ccan_dir(tal_fmt(tmpctx, "%s/%s", tmpctx, base));
tmpctx, base)); tal_free(tmpctx);
talloc_free(tmpctx);
} else { } else {
unsigned int prefix = ccan_dir_prefix(base); unsigned int prefix = ccan_dir_prefix(base);
if (prefix) if (prefix)
ccan_dir = talloc_strndup(NULL, base, prefix); ccan_dir = tal_strndup(NULL, base, prefix);
} }
} }
return ccan_dir; return ccan_dir;
......
...@@ -10,6 +10,7 @@ CORE_OBJS := \ ...@@ -10,6 +10,7 @@ CORE_OBJS := \
ccan/htable/htable.o \ ccan/htable/htable.o \
ccan/ilog/ilog.o \ ccan/ilog/ilog.o \
ccan/lbalance/lbalance.o \ ccan/lbalance/lbalance.o \
ccan/list/list.o \
ccan/noerr/noerr.o \ ccan/noerr/noerr.o \
ccan/opt/helpers.o \ ccan/opt/helpers.o \
ccan/opt/opt.o \ ccan/opt/opt.o \
...@@ -19,10 +20,11 @@ CORE_OBJS := \ ...@@ -19,10 +20,11 @@ CORE_OBJS := \
ccan/rbuf/rbuf.o \ ccan/rbuf/rbuf.o \
ccan/read_write_all/read_write_all.o \ ccan/read_write_all/read_write_all.o \
ccan/str/str.o ccan/str/debug.o \ ccan/str/str.o ccan/str/debug.o \
ccan/str_talloc/str_talloc.o \
ccan/strmap/strmap.o \ ccan/strmap/strmap.o \
ccan/talloc/talloc.o \ ccan/take/take.o \
ccan/talloc_link/talloc_link.o \ ccan/tal/tal.o \
ccan/tal/link/link.o \
ccan/tal/str/str.o \
ccan/time/time.o \ ccan/time/time.o \
tools/ccanlint/async.o \ tools/ccanlint/async.o \
tools/ccanlint/ccanlint.o \ tools/ccanlint/ccanlint.o \
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <ccan/lbalance/lbalance.h> #include <ccan/lbalance/lbalance.h>
#include <ccan/tlist/tlist.h> #include <ccan/tlist/tlist.h>
#include <ccan/time/time.h> #include <ccan/time/time.h>
#include <ccan/talloc/talloc.h>
static struct lbalance *lb; static struct lbalance *lb;
TLIST_TYPE(command, struct command); TLIST_TYPE(command, struct command);
...@@ -91,7 +90,7 @@ static void run_more(void) ...@@ -91,7 +90,7 @@ static void run_more(void)
} }
} }
static int destroy_command(struct command *command) static void destroy_command(struct command *command)
{ {
if (!command->done && command->pid) { if (!command->done && command->pid) {
kill(-command->pid, SIGKILL); kill(-command->pid, SIGKILL);
...@@ -100,7 +99,6 @@ static int destroy_command(struct command *command) ...@@ -100,7 +99,6 @@ static int destroy_command(struct command *command)
} }
tlist_del(command, list); tlist_del(command, list);
return 0;
} }
void run_command_async(const void *ctx, unsigned int time_ms, void run_command_async(const void *ctx, unsigned int time_ms,
...@@ -114,17 +112,18 @@ void run_command_async(const void *ctx, unsigned int time_ms, ...@@ -114,17 +112,18 @@ void run_command_async(const void *ctx, unsigned int time_ms,
if (!lb) if (!lb)
lb = lbalance_new(); lb = lbalance_new();
command = talloc(ctx, struct command); command = tal(ctx, struct command);
command->ctx = ctx; command->ctx = ctx;
command->time_ms = time_ms; command->time_ms = time_ms;
command->pid = 0; command->pid = 0;
command->output = talloc_strdup(command, ""); /* We want to track length, so don't use tal_strdup */
command->output = tal_arrz(command, char, 1);
va_start(ap, fmt); va_start(ap, fmt);
command->command = talloc_vasprintf(command, fmt, ap); command->command = tal_vfmt(command, fmt, ap);
va_end(ap); va_end(ap);
tlist_add_tail(&pending, command, list); tlist_add_tail(&pending, command, list);
command->done = false; command->done = false;
talloc_set_destructor(command, destroy_command); tal_add_destructor(command, destroy_command);
run_more(); run_more();
} }
...@@ -150,14 +149,12 @@ static void reap_output(void) ...@@ -150,14 +149,12 @@ static void reap_output(void)
if (FD_ISSET(c->output_fd, &in)) { if (FD_ISSET(c->output_fd, &in)) {
int old_len, len; int old_len, len;
/* This length includes nul terminator! */ /* This length includes nul terminator! */
old_len = talloc_array_length(c->output); old_len = tal_count(c->output);
c->output = talloc_realloc(c, c->output, char, tal_resize(&c->output, old_len + 1024);
old_len + 1024);
len = read(c->output_fd, c->output + old_len - 1, 1024); len = read(c->output_fd, c->output + old_len - 1, 1024);
if (len < 0) if (len < 0)
err(1, "Reading from async command"); err(1, "Reading from async command");
c->output = talloc_realloc(c, c->output, char, tal_resize(&c->output, old_len + len);
old_len + len);
c->output[old_len + len - 1] = '\0'; c->output[old_len + len - 1] = '\0';
if (len == 0) { if (len == 0) {
struct rusage ru; struct rusage ru;
...@@ -197,8 +194,8 @@ void *collect_command(bool *ok, char **output) ...@@ -197,8 +194,8 @@ void *collect_command(bool *ok, char **output)
*ok = (WIFEXITED(c->status) && WEXITSTATUS(c->status) == 0); *ok = (WIFEXITED(c->status) && WEXITSTATUS(c->status) == 0);
ctx = c->ctx; ctx = c->ctx;
*output = talloc_steal(ctx, c->output); *output = tal_steal(ctx, c->output);
talloc_free(c); tal_free(c);
return (void *)ctx; return (void *)ctx;
} }
......
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
#include <err.h> #include <err.h>
#include <ctype.h> #include <ctype.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h> #include <ccan/take/take.h>
#include <ccan/talloc/talloc.h>
#include <ccan/opt/opt.h> #include <ccan/opt/opt.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
...@@ -117,7 +116,7 @@ static bool run_test(struct dgraph_node *n, struct run_info *run) ...@@ -117,7 +116,7 @@ static bool run_test(struct dgraph_node *n, struct run_info *run)
if (i->done) if (i->done)
return true; return true;
score = talloc(run->m, struct score); score = tal(run->m, struct score);
list_head_init(&score->per_file_errors); list_head_init(&score->per_file_errors);
score->error = NULL; score->error = NULL;
score->pass = false; score->pass = false;
...@@ -213,7 +212,7 @@ static void register_test(struct ccanlint *test) ...@@ -213,7 +212,7 @@ static void register_test(struct ccanlint *test)
{ {
if (!strmap_add(&tests, test->key, test)) if (!strmap_add(&tests, test->key, test))
err(1, "Adding test %s", test->key); err(1, "Adding test %s", test->key);
test->options = talloc_array(NULL, char *, 1); test->options = tal_arr(NULL, char *, 1);
test->options[0] = NULL; test->options[0] = NULL;
dgraph_init_node(&test->node); dgraph_init_node(&test->node);
} }
...@@ -257,7 +256,7 @@ bool is_excluded(const char *name) ...@@ -257,7 +256,7 @@ bool is_excluded(const char *name)
static bool init_deps(const char *member, struct ccanlint *c, void *unused) static bool init_deps(const char *member, struct ccanlint *c, void *unused)
{ {
char **deps = strsplit(NULL, c->needs, " "); char **deps = tal_strsplit(NULL, c->needs, " ", STR_EMPTY_OK);
unsigned int i; unsigned int i;
for (i = 0; deps[i]; i++) { for (i = 0; deps[i]; i++) {
...@@ -269,7 +268,7 @@ static bool init_deps(const char *member, struct ccanlint *c, void *unused) ...@@ -269,7 +268,7 @@ static bool init_deps(const char *member, struct ccanlint *c, void *unused)
deps[i], c->key); deps[i], c->key);
dgraph_add_edge(&dep->node, &c->node); dgraph_add_edge(&dep->node, &c->node);
} }
talloc_free(deps); tal_free(deps);
return true; return true;
} }
...@@ -339,10 +338,9 @@ static void print_test_depends(void) ...@@ -339,10 +338,9 @@ static void print_test_depends(void)
} }
static int show_tmpdir(const char *dir) static void show_tmpdir(const char *dir)
{ {
printf("You can find ccanlint working files in '%s'\n", dir); printf("You can find ccanlint working files in '%s'\n", dir);
return 0;
} }
static char *keep_tests(void *unused) static char *keep_tests(void *unused)
...@@ -350,7 +348,8 @@ static char *keep_tests(void *unused) ...@@ -350,7 +348,8 @@ static char *keep_tests(void *unused)
keep_results = true; keep_results = true;
/* Don't automatically destroy temporary dir. */ /* Don't automatically destroy temporary dir. */
talloc_set_destructor(temp_dir(NULL), show_tmpdir); keep_temp_dir();
tal_add_destructor(temp_dir(), show_tmpdir);
return NULL; return NULL;
} }
...@@ -366,8 +365,7 @@ static char *exclude_test(const char *testname, void *unused) ...@@ -366,8 +365,7 @@ static char *exclude_test(const char *testname, void *unused)
{ {
struct ccanlint *i = find_test(testname); struct ccanlint *i = find_test(testname);
if (!i) if (!i)
return talloc_asprintf(NULL, "No test %s to --exclude", return tal_fmt(NULL, "No test %s to --exclude", testname);
testname);
/* Remove this, and everything which depends on it. */ /* Remove this, and everything which depends on it. */
dgraph_traverse_from(&i->node, remove_test, "excluded on command line"); dgraph_traverse_from(&i->node, remove_test, "excluded on command line");
...@@ -441,21 +439,6 @@ static char *test_dependency_graph(void *arg) ...@@ -441,21 +439,6 @@ static char *test_dependency_graph(void *arg)
exit(0); exit(0);
} }
/* Remove empty lines. */
static char **collapse(char **lines, unsigned int *nump)
{
unsigned int i, j;
for (i = j = 0; lines[i]; i++) {
if (lines[i][0])
lines[j++] = lines[i];
}
lines[j] = NULL;
if (nump)
*nump = j;
return lines;
}
static void add_options(struct ccanlint *test, char **options, static void add_options(struct ccanlint *test, char **options,
unsigned int num_options) unsigned int num_options)
{ {
...@@ -465,11 +448,9 @@ static void add_options(struct ccanlint *test, char **options, ...@@ -465,11 +448,9 @@ static void add_options(struct ccanlint *test, char **options,
num = 0; num = 0;
else else
/* -1, because last one is NULL. */ /* -1, because last one is NULL. */
num = talloc_array_length(test->options) - 1; num = tal_count(test->options) - 1;
test->options = talloc_realloc(NULL, test->options, tal_resize(&test->options, num + num_options + 1);
char *,
num + num_options + 1);
memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *)); memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
} }
...@@ -484,10 +465,9 @@ void add_info_options(struct ccan_file *info) ...@@ -484,10 +465,9 @@ void add_info_options(struct ccan_file *info)
continue; continue;
for (i = 0; i < d->num_lines; i++) { for (i = 0; i < d->num_lines; i++) {
unsigned int num_words; char **words = tal_strsplit(d, d->lines[i], " \t",
char **words = collapse(strsplit(d, d->lines[i], " \t"), STR_NO_EMPTY);
&num_words); if (!words[0])
if (num_words == 0)
continue; continue;
if (strncmp(words[0], "//", 2) == 0) if (strncmp(words[0], "//", 2) == 0)
...@@ -516,7 +496,7 @@ void add_info_options(struct ccan_file *info) ...@@ -516,7 +496,7 @@ void add_info_options(struct ccan_file *info)
if (!test->takes_options) if (!test->takes_options)
warnx("%s: %s doesn't take options", warnx("%s: %s doesn't take options",
info->fullname, words[0]); info->fullname, words[0]);
add_options(test, words+1, num_words-1); add_options(test, words+1, tal_count(words)-1);
} }
} }
} }
...@@ -532,7 +512,7 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f) ...@@ -532,7 +512,7 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
if (!test->options[0]) if (!test->options[0])
return test->options; return test->options;
ret = talloc_array(f, char *, talloc_array_length(test->options)); ret = tal_arr(f, char *, tal_count(test->options));
for (i = 0; test->options[i]; i++) { for (i = 0; test->options[i]; i++) {
char *optname; char *optname;
...@@ -546,7 +526,7 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f) ...@@ -546,7 +526,7 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
/* FAIL overrides anything else. */ /* FAIL overrides anything else. */
if (streq(optname, "FAIL")) { if (streq(optname, "FAIL")) {
ret = talloc_array(f, char *, 2); ret = tal_arr(f, char *, 2);
ret[0] = (char *)"FAIL"; ret[0] = (char *)"FAIL";
ret[1] = NULL; ret[1] = NULL;
return ret; return ret;
...@@ -555,8 +535,9 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f) ...@@ -555,8 +535,9 @@ char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
} }
ret[j] = NULL; ret[j] = NULL;
/* Shrink it to size so talloc_array_length() works as expected. */ /* Shrink it to size so tal_array_length() works as expected. */
return talloc_realloc(NULL, ret, char *, j + 1); tal_resize(&ret, j + 1);
return ret;
} }
static char *opt_set_const_charp(const char *arg, const char **p) static char *opt_set_const_charp(const char *arg, const char **p)
...@@ -568,7 +549,7 @@ static char *opt_set_target(const char *arg, struct dgraph_node *all) ...@@ -568,7 +549,7 @@ static char *opt_set_target(const char *arg, struct dgraph_node *all)
{ {
struct ccanlint *t = find_test(arg); struct ccanlint *t = find_test(arg);
if (!t) if (!t)
return talloc_asprintf(NULL, "unknown --target %s", arg); return tal_fmt(NULL, "unknown --target %s", arg);
targeting = true; targeting = true;
dgraph_add_edge(&t->node, all); dgraph_add_edge(&t->node, all);
...@@ -609,7 +590,7 @@ int main(int argc, char *argv[]) ...@@ -609,7 +590,7 @@ int main(int argc, char *argv[])
unsigned int i; unsigned int i;
struct manifest *m; struct manifest *m;
const char *prefix = ""; const char *prefix = "";
char *dir = talloc_getcwd(NULL), *base_dir = dir, *testlink; char *dir = tal_getcwd(NULL), *base_dir = dir, *testlink;
struct dgraph_node all; struct dgraph_node all;
/* Empty graph node to which we attach everything else. */ /* Empty graph node to which we attach everything else. */
...@@ -647,8 +628,8 @@ int main(int argc, char *argv[]) ...@@ -647,8 +628,8 @@ int main(int argc, char *argv[])
opt_early_parse(argc, argv, opt_log_stderr_exit); opt_early_parse(argc, argv, opt_log_stderr_exit);
/* We move into temporary directory, so gcov dumps its files there. */ /* We move into temporary directory, so gcov dumps its files there. */
if (chdir(temp_dir(talloc_autofree_context())) != 0) if (chdir(temp_dir()) != 0)
err(1, "Error changing to %s temporary dir", temp_dir(NULL)); err(1, "Error changing to %s temporary dir", temp_dir());
init_tests(); init_tests();
...@@ -665,7 +646,7 @@ int main(int argc, char *argv[]) ...@@ -665,7 +646,7 @@ int main(int argc, char *argv[])
strmap_iterate(&tests, add_to_all, &all); strmap_iterate(&tests, add_to_all, &all);
/* This links back to the module's test dir. */ /* This links back to the module's test dir. */
testlink = talloc_asprintf(NULL, "%s/test", temp_dir(NULL)); testlink = tal_fmt(NULL, "%s/test", temp_dir());
/* Defaults to pwd. */ /* Defaults to pwd. */
if (argc == 1) { if (argc == 1) {
...@@ -677,8 +658,7 @@ int main(int argc, char *argv[]) ...@@ -677,8 +658,7 @@ int main(int argc, char *argv[])
dir = argv[i]; dir = argv[i];
if (dir[0] != '/') if (dir[0] != '/')
dir = talloc_asprintf_append(NULL, "%s/%s", dir = tal_fmt(NULL, "%s/%s", base_dir, dir);
base_dir, dir);
while (strends(dir, "/")) while (strends(dir, "/"))
dir[strlen(dir)-1] = '\0'; dir[strlen(dir)-1] = '\0';
...@@ -695,16 +675,16 @@ int main(int argc, char *argv[]) ...@@ -695,16 +675,16 @@ int main(int argc, char *argv[])
} }
if (dir != base_dir) if (dir != base_dir)
prefix = talloc_append_string(talloc_basename(NULL,dir), prefix = tal_strcat(NULL, take(tal_basename(NULL,dir)),
": "); ": ");
m = get_manifest(talloc_autofree_context(), dir); m = get_manifest(autofree(), dir);
/* Create a symlink from temp dir back to src dir's /* Create a symlink from temp dir back to src dir's
* test directory. */ * test directory. */
unlink(testlink); unlink(testlink);
if (symlink(talloc_asprintf(m, "%s/test", dir), testlink) != 0) if (symlink(tal_fmt(m, "%s/test", dir), testlink) != 0)
err(1, "Creating test symlink in %s", temp_dir(NULL)); err(1, "Creating test symlink in %s", temp_dir());
if (!run_tests(&all, summary, m, prefix)) if (!run_tests(&all, summary, m, prefix))
pass = false; pass = false;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define CCAN_LINT_H #define CCAN_LINT_H
#include "config.h" #include "config.h"
#include <ccan/list/list.h> #include <ccan/list/list.h>
#include <ccan/tal/tal.h>
#include <ccan/dgraph/dgraph.h> #include <ccan/dgraph/dgraph.h>
#include <ccan/autodata/autodata.h> #include <ccan/autodata/autodata.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -55,7 +56,7 @@ struct ccanlint { ...@@ -55,7 +56,7 @@ struct ccanlint {
bool compulsory; bool compulsory;
/* If timeleft is set to 0, means it timed out. /* If timeleft is set to 0, means it timed out.
* score is the result, and a talloc context freed after all our * score is the result, and a tal context freed after all our
* depends are done. */ * depends are done. */
void (*check)(struct manifest *m, void (*check)(struct manifest *m,
unsigned int *timeleft, struct score *score); unsigned int *timeleft, struct score *score);
...@@ -137,7 +138,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond, ...@@ -137,7 +138,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
/* Get token if it's equal to token. */ /* Get token if it's equal to token. */
bool get_token(const char **line, const char *token); bool get_token(const char **line, const char *token);
/* Talloc copy of symbol token, or NULL. Increment line. */ /* Tal copy of symbol token, or NULL. Increment line. */
char *get_symbol_token(void *ctx, const char **line); char *get_symbol_token(void *ctx, const char **line);
/* Similarly for ->doc_sections */ /* Similarly for ->doc_sections */
......
#include "config.h" #include "config.h"
#include "ccanlint.h" #include "ccanlint.h"
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h> #include <ccan/take/take.h>
#include <ccan/talloc_link/talloc_link.h>
#include <ccan/hash/hash.h> #include <ccan/hash/hash.h>
#include <ccan/htable/htable_type.h> #include <ccan/htable/htable_type.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
...@@ -38,10 +36,11 @@ struct list_head *get_ccan_file_docs(struct ccan_file *f) ...@@ -38,10 +36,11 @@ struct list_head *get_ccan_file_docs(struct ccan_file *f)
* @in_comment: are we already within a comment (from prev line). * @in_comment: are we already within a comment (from prev line).
* @unterminated: are we still in a comment for next line. * @unterminated: are we still in a comment for next line.
*/ */
static char *remove_comments(const char *line, bool in_comment, static char *remove_comments(const tal_t *ctx,
const char *line, bool in_comment,
bool *unterminated) bool *unterminated)
{ {
char *p, *ret = talloc_array(line, char, strlen(line) + 1); char *p, *ret = tal_arr(ctx, char, strlen(line) + 1);
p = ret; p = ret;
for (;;) { for (;;) {
...@@ -121,7 +120,7 @@ static bool parse_hash_if(struct pp_conditions *cond, const char **line) ...@@ -121,7 +120,7 @@ static bool parse_hash_if(struct pp_conditions *cond, const char **line)
/* FIXME: We just chain them, ignoring operators. */ /* FIXME: We just chain them, ignoring operators. */
if (get_token(line, "||") || get_token(line, "&&")) { if (get_token(line, "||") || get_token(line, "&&")) {
struct pp_conditions *sub = talloc(cond, struct pp_conditions); struct pp_conditions *sub = tal(cond, struct pp_conditions);
sub->parent = cond->parent; sub->parent = cond->parent;
sub->type = PP_COND_IFDEF; sub->type = PP_COND_IFDEF;
...@@ -137,10 +136,10 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f, ...@@ -137,10 +136,10 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f,
const char *line, const char *line,
struct pp_conditions *parent) struct pp_conditions *parent)
{ {
struct pp_conditions *cond = talloc(f, struct pp_conditions); struct pp_conditions *cond = tal(f, struct pp_conditions);
bool unused; bool unused;
line = remove_comments(line, false, &unused); line = remove_comments(f, line, false, &unused);
cond->parent = parent; cond->parent = parent;
cond->type = PP_COND_IFDEF; cond->type = PP_COND_IFDEF;
...@@ -187,7 +186,7 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f, ...@@ -187,7 +186,7 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f,
cond->inverse = !cond->inverse; cond->inverse = !cond->inverse;
return cond; return cond;
} else if (get_token(&line, "endif")) { } else if (get_token(&line, "endif")) {
talloc_free(cond); tal_free(cond);
/* Malformed? */ /* Malformed? */
if (!parent) if (!parent)
return NULL; return NULL;
...@@ -195,7 +194,7 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f, ...@@ -195,7 +194,7 @@ static struct pp_conditions *analyze_directive(struct ccan_file *f,
return parent->parent; return parent->parent;
} else { } else {
/* Not a conditional. */ /* Not a conditional. */
talloc_free(cond); tal_free(cond);
return parent; return parent;
} }
...@@ -219,7 +218,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f) ...@@ -219,7 +218,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f)
return f->line_info; return f->line_info;
get_ccan_file_lines(f); get_ccan_file_lines(f);
f->line_info = talloc_array(f->lines, struct line_info, f->num_lines); f->line_info = tal_arr(f->lines, struct line_info, f->num_lines);
for (i = 0; i < f->num_lines; continued = continues(f->lines[i++])) { for (i = 0; i < f->num_lines; continued = continues(f->lines[i++])) {
char *p; char *p;
...@@ -233,7 +232,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f) ...@@ -233,7 +232,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f)
/* Same as last line. */ /* Same as last line. */
f->line_info[i].type = f->line_info[i-1].type; f->line_info[i].type = f->line_info[i-1].type;
/* Update in_comment. */ /* Update in_comment. */
remove_comments(f->lines[i], in_comment, &in_comment); remove_comments(f, f->lines[i], in_comment, &in_comment);
continue; continue;
} }
...@@ -248,7 +247,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f) ...@@ -248,7 +247,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f)
still_doc_line = (in_comment still_doc_line = (in_comment
&& f->line_info[i-1].type == DOC_LINE); && f->line_info[i-1].type == DOC_LINE);
p = remove_comments(f->lines[i], in_comment, &in_comment); p = remove_comments(f, f->lines[i], in_comment, &in_comment);
if (is_empty(p)) { if (is_empty(p)) {
if (strstarts(f->lines[i], "/**") || still_doc_line) if (strstarts(f->lines[i], "/**") || still_doc_line)
f->line_info[i].type = DOC_LINE; f->line_info[i].type = DOC_LINE;
...@@ -256,7 +255,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f) ...@@ -256,7 +255,7 @@ struct line_info *get_ccan_line_info(struct ccan_file *f)
f->line_info[i].type = COMMENT_LINE; f->line_info[i].type = COMMENT_LINE;
} else } else
f->line_info[i].type = CODE_LINE; f->line_info[i].type = CODE_LINE;
talloc_free(p); tal_free(p);
} }
return f->line_info; return f->line_info;
} }
...@@ -330,7 +329,7 @@ static enum line_compiled get_pp(struct pp_conditions *cond, ...@@ -330,7 +329,7 @@ static enum line_compiled get_pp(struct pp_conditions *cond,
static void add_symbol(struct list_head *head, static void add_symbol(struct list_head *head,
const char *symbol, const unsigned int *value) const char *symbol, const unsigned int *value)
{ {
struct symbol *sym = talloc(head, struct symbol); struct symbol *sym = tal(head, struct symbol);
sym->name = symbol; sym->name = symbol;
sym->value = value; sym->value = value;
list_add(head, &sym->list); list_add(head, &sym->list);
...@@ -345,7 +344,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond, ...@@ -345,7 +344,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
struct list_head *head; struct list_head *head;
va_list ap; va_list ap;
head = talloc(NULL, struct list_head); head = tal(NULL, struct list_head);
list_head_init(head); list_head_init(head);
va_start(ap, value); va_start(ap, value);
...@@ -356,7 +355,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond, ...@@ -356,7 +355,7 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
add_symbol(head, symbol, value); add_symbol(head, symbol, value);
} }
ret = get_pp(cond, head); ret = get_pp(cond, head);
talloc_free(head); tal_free(head);
return ret; return ret;
} }
...@@ -365,33 +364,34 @@ void score_file_error(struct score *score, struct ccan_file *f, unsigned line, ...@@ -365,33 +364,34 @@ void score_file_error(struct score *score, struct ccan_file *f, unsigned line,
{ {
va_list ap; va_list ap;
struct file_error *fe = talloc(score, struct file_error); struct file_error *fe = tal(score, struct file_error);
fe->file = f; fe->file = f;
fe->line = line; fe->line = line;
list_add_tail(&score->per_file_errors, &fe->list); list_add_tail(&score->per_file_errors, &fe->list);
if (!score->error) if (!score->error)
score->error = talloc_strdup(score, ""); score->error = tal_strdup(score, "");
if (verbose < 2 && strcount(score->error, "\n") > 5) if (verbose < 2 && strcount(score->error, "\n") > 5) {
if (!strends(score->error,
"... more (use -vv to see them all)\n")) {
score->error = tal_strcat(score,
take(score->error),
"... more (use -vv to see"
" them all)\n");
}
return; return;
}
if (line) if (line)
score->error = talloc_asprintf_append(score->error, tal_append_fmt(&score->error, "%s:%u:", f->fullname, line);
"%s:%u:",
f->fullname, line);
else else
score->error = talloc_asprintf_append(score->error, tal_append_fmt(&score->error, "%s:", f->fullname);
"%s:", f->fullname);
va_start(ap, errorfmt); va_start(ap, errorfmt);
score->error = talloc_vasprintf_append(score->error, errorfmt, ap); tal_append_vfmt(&score->error, errorfmt, ap);
va_end(ap); va_end(ap);
score->error = talloc_append_string(score->error, "\n"); score->error = tal_strcat(score, take(score->error),"\n");
if (verbose < 2 && strcount(score->error, "\n") > 5)
score->error = talloc_append_string(score->error,
"... more (use -vv to see them all)\n");
} }
char *get_or_compile_info(const void *ctx, const char *dir) char *get_or_compile_info(const void *ctx, const char *dir)
......
#include "licenses.h" #include "licenses.h"
#include "ccanlint.h" #include "ccanlint.h"
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h> #include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
const struct license_info licenses[] = { const struct license_info licenses[] = {
{ "LGPLv2+", "LGPL", { "LGPLv2+", "LGPL",
...@@ -155,9 +155,10 @@ enum license which_license(struct doc_section *d) ...@@ -155,9 +155,10 @@ enum license which_license(struct doc_section *d)
return LICENSE_BSD; return LICENSE_BSD;
if (streq(d->lines[0], "CC0")) if (streq(d->lines[0], "CC0"))
return LICENSE_CC0; return LICENSE_CC0;
if (strreg(NULL, d->lines[0], "CC0 \\([Pp]ublic [Dd]omain\\)", NULL)) if (tal_strreg(NULL, d->lines[0], "CC0 \\([Pp]ublic [Dd]omain\\)",
NULL))
return LICENSE_CC0; return LICENSE_CC0;
if (strreg(NULL, d->lines[0], "[Pp]ublic [Dd]omain")) if (tal_strreg(NULL, d->lines[0], "[Pp]ublic [Dd]omain"))
return LICENSE_PUBLIC_DOMAIN; return LICENSE_PUBLIC_DOMAIN;
return LICENSE_UNKNOWN; return LICENSE_UNKNOWN;
...@@ -169,7 +170,7 @@ const char *get_ccan_simplified(struct ccan_file *f) ...@@ -169,7 +170,7 @@ const char *get_ccan_simplified(struct ccan_file *f)
unsigned int i, j; unsigned int i, j;
/* Simplify for easy matching: only alnum and single spaces. */ /* Simplify for easy matching: only alnum and single spaces. */
f->simplified = talloc_strdup(f, get_ccan_file_contents(f)); f->simplified = tal_strdup(f, get_ccan_file_contents(f));
for (i = 0, j = 0; f->simplified[i]; i++) { for (i = 0, j = 0; f->simplified[i]; i++) {
if (cisupper(f->simplified[i])) if (cisupper(f->simplified[i]))
f->simplified[j++] = tolower(f->simplified[i]); f->simplified[j++] = tolower(f->simplified[i]);
......
...@@ -98,15 +98,15 @@ int main(int argc, char *argv[]) ...@@ -98,15 +98,15 @@ int main(int argc, char *argv[])
{ {
unsigned int i; unsigned int i;
struct line_info *line_info; struct line_info *line_info;
struct ccan_file *f = talloc(NULL, struct ccan_file); struct ccan_file *f = tal(NULL, struct ccan_file);
plan_tests(NUM_LINES * 2 + 2 + 86); plan_tests(NUM_LINES * 2 + 2 + 86);
f->num_lines = NUM_LINES; f->num_lines = NUM_LINES;
f->line_info = NULL; f->line_info = NULL;
f->lines = talloc_array(f, char *, f->num_lines); f->lines = tal_array(f, char *, f->num_lines);
for (i = 0; i < f->num_lines; i++) for (i = 0; i < f->num_lines; i++)
f->lines[i] = talloc_strdup(f->lines, testfile[i].line); f->lines[i] = tal_strdup(f->lines, testfile[i].line);
line_info = get_ccan_line_info(f); line_info = get_ccan_line_info(f);
ok1(line_info == f->line_info); ok1(line_info == f->line_info);
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -51,7 +50,7 @@ static void check_headers_no_cpp(struct manifest *m, ...@@ -51,7 +50,7 @@ static void check_headers_no_cpp(struct manifest *m,
if (fd < 0) if (fd < 0)
err(1, "Creating temporary file %s", tmpsrc); err(1, "Creating temporary file %s", tmpsrc);
contents = talloc_asprintf(tmpsrc, contents = tal_fmt(tmpsrc,
"#define alignas #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n" "#define alignas #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
"#define class #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n" "#define class #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
"#define constexpr #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n" "#define constexpr #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
...@@ -93,7 +92,7 @@ static void check_headers_no_cpp(struct manifest *m, ...@@ -93,7 +92,7 @@ static void check_headers_no_cpp(struct manifest *m,
tmpobj, &cmdout)) { tmpobj, &cmdout)) {
score->score = score->total; score->score = score->total;
} else { } else {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Main header file with C++ names:\n%s", "Main header file with C++ names:\n%s",
cmdout); cmdout);
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h> #include <ccan/take/take.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -46,9 +45,9 @@ static bool check_dep_includes(struct manifest *m, ...@@ -46,9 +45,9 @@ static bool check_dep_includes(struct manifest *m,
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
char *mod; char *mod;
if (!strreg(f, lines[i], if (!tal_strreg(f, lines[i],
"^[ \t]*#[ \t]*include[ \t]*[<\"]" "^[ \t]*#[ \t]*include[ \t]*[<\"]"
"(ccan/+.+)/+[^/]+\\.h", &mod)) "(ccan/+.+)/+[^/]+\\.h", &mod))
continue; continue;
if (has_dep(m, deps, used, mod)) if (has_dep(m, deps, used, mod))
...@@ -86,10 +85,10 @@ static void check_depends_accurate(struct manifest *m, ...@@ -86,10 +85,10 @@ static void check_depends_accurate(struct manifest *m,
get_or_compile_info); get_or_compile_info);
} }
core_deps = talloc_array_length(deps) - 1; core_deps = tal_count(deps) - 1;
test_deps = talloc_array_length(tdeps) - 1; test_deps = tal_count(tdeps) - 1;
used = talloc_zero_array(m, bool, core_deps + test_deps + 1); used = tal_arrz(m, bool, core_deps + test_deps + 1);
foreach_ptr(list, &m->c_files, &m->h_files) { foreach_ptr(list, &m->c_files, &m->h_files) {
struct ccan_file *f; struct ccan_file *f;
...@@ -105,10 +104,9 @@ static void check_depends_accurate(struct manifest *m, ...@@ -105,10 +104,9 @@ static void check_depends_accurate(struct manifest *m,
deps[i]); deps[i]);
} }
/* Now append test dependencies to deps. */ /* Now remove NUL and append test dependencies to deps. */
deps = talloc_realloc(NULL, deps, char *, deps = tal_dup(m, char *, take(deps), core_deps, test_deps + 2);
(core_deps + test_deps + 1) * sizeof(char *)); memcpy(deps + core_deps, tdeps, sizeof(tdeps[0]) * test_deps);
memcpy(&deps[core_deps], tdeps, test_deps * sizeof(char *));
/* ccan/tap is given a free pass. */ /* ccan/tap is given a free pass. */
deps[core_deps + test_deps] = (char *)"ccan/tap"; deps[core_deps + test_deps] = (char *)"ccan/tap";
deps[core_deps + test_deps + 1] = NULL; deps[core_deps + test_deps + 1] = NULL;
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -36,18 +35,17 @@ static char *build_subdir_objs(struct manifest *m, ...@@ -36,18 +35,17 @@ static char *build_subdir_objs(struct manifest *m,
struct ccan_file *i; struct ccan_file *i;
list_for_each(&m->c_files, i, list) { list_for_each(&m->c_files, i, list) {
char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name); char *fullfile = tal_fmt(m, "%s/%s", m->dir, i->name);
char *output; char *output;
i->compiled[ctype] = temp_file(m, "", fullfile); i->compiled[ctype] = temp_file(m, "", fullfile);
if (!compile_object(m, fullfile, ccan_dir, compiler, flags, if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
i->compiled[ctype], &output)) { i->compiled[ctype], &output)) {
talloc_free(i->compiled[ctype]); tal_free(i->compiled[ctype]);
i->compiled[ctype] = NULL; i->compiled[ctype] = NULL;
return talloc_asprintf(m, return tal_fmt(m,
"Dependency %s" "Dependency %s did not build:\n%s",
" did not build:\n%s", m->modname, output);
m->modname, output);
} }
} }
return NULL; return NULL;
...@@ -90,12 +88,12 @@ static void check_depends_built(struct manifest *m, ...@@ -90,12 +88,12 @@ static void check_depends_built(struct manifest *m,
errstr = build_submodule(i, cflags, COMPILE_NORMAL); errstr = build_submodule(i, cflags, COMPILE_NORMAL);
if (errstr) { if (errstr) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Dependency %s" "Dependency %s"
" did not" " did not"
" build:\n%s", " build:\n%s",
i->modname, i->modname,
errstr); errstr);
return; return;
} }
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -32,8 +31,7 @@ static void check_depends_built_without_features(struct manifest *m, ...@@ -32,8 +31,7 @@ static void check_depends_built_without_features(struct manifest *m,
struct manifest *i; struct manifest *i;
char *flags; char *flags;
flags = talloc_asprintf(score, "%s %s", cflags, flags = tal_fmt(score, "%s %s", cflags, REDUCE_FEATURES_FLAGS);
REDUCE_FEATURES_FLAGS);
foreach_ptr(list, &m->deps, &m->test_deps) { foreach_ptr(list, &m->deps, &m->test_deps) {
list_for_each(list, i, list) { list_for_each(list, i, list) {
...@@ -41,12 +39,11 @@ static void check_depends_built_without_features(struct manifest *m, ...@@ -41,12 +39,11 @@ static void check_depends_built_without_features(struct manifest *m,
COMPILE_NOFEAT); COMPILE_NOFEAT);
if (errstr) { if (errstr) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Dependency %s" "Dependency %s"
" did not" " did not build:\n%s",
" build:\n%s", i->modname,
i->modname, errstr);
errstr);
return; return;
} }
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -31,14 +30,12 @@ static bool add_dep(struct manifest *m, ...@@ -31,14 +30,12 @@ static bool add_dep(struct manifest *m,
{ {
struct stat st; struct stat st;
struct manifest *subm; struct manifest *subm;
char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep); char *dir = tal_fmt(m, "%s/%s", ccan_dir, dep);
/* FIXME: get_manifest has a tendency to exit. */ /* FIXME: get_manifest has a tendency to exit. */
if (stat(dir, &st) != 0) { if (stat(dir, &st) != 0) {
score->error score->error = tal_fmt(m, "Could not stat dependency %s: %s",
= talloc_asprintf(m, dir, strerror(errno));
"Could not stat dependency %s: %s",
dir, strerror(errno));
return false; return false;
} }
subm = get_manifest(m, dir); subm = get_manifest(m, dir);
......
This diff is collapsed.
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -24,28 +23,27 @@ static char *add_example(struct manifest *m, struct ccan_file *source, ...@@ -24,28 +23,27 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
int fd; int fd;
struct ccan_file *f; struct ccan_file *f;
name = talloc_asprintf(m, "%s/example-%s-%s.c", name = tal_fmt(m, "%s/example-%s-%s.c",
talloc_dirname(m, tal_dirname(m, source->fullname),
source->fullname), source->name,
source->name, example->function);
example->function);
/* example->function == 'struct foo' */ /* example->function == 'struct foo' */
while (strchr(name, ' ')) while (strchr(name, ' '))
*strchr(name, ' ') = '_'; *strchr(name, ' ') = '_';
name = temp_file(m, ".c", name); name = temp_file(m, ".c", name);
f = new_ccan_file(m, talloc_dirname(m, name), talloc_basename(m, name)); f = new_ccan_file(m, tal_dirname(m, name), tal_basename(m, name));
talloc_steal(f, name); tal_steal(f, name);
list_add_tail(&m->examples, &f->list); list_add_tail(&m->examples, &f->list);
fd = open(f->fullname, O_WRONLY | O_CREAT | O_EXCL, 0600); fd = open(f->fullname, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fd < 0) if (fd < 0)
return talloc_asprintf(m, "Creating temporary file %s: %s", return tal_fmt(m, "Creating temporary file %s: %s",
f->fullname, strerror(errno)); f->fullname, strerror(errno));
/* Add #line to demark where we are from, so errors are correct! */ /* Add #line to demark where we are from, so errors are correct! */
linemarker = talloc_asprintf(f, "#line %i \"%s\"\n", linemarker = tal_fmt(f, "#line %i \"%s\"\n",
example->srcline+2, source->fullname); example->srcline+2, source->fullname);
write(fd, linemarker, strlen(linemarker)); write(fd, linemarker, strlen(linemarker));
for (i = 0; i < example->num_lines; i++) { for (i = 0; i < example->num_lines; i++) {
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
...@@ -60,7 +59,7 @@ static bool scan_forv(const void *ctx, ...@@ -60,7 +59,7 @@ static bool scan_forv(const void *ctx,
for (len = 1; input[len-1]; len++) { for (len = 1; input[len-1]; len++) {
ret = scan_forv(ctx, input + len, fmt+2, &ap); ret = scan_forv(ctx, input + len, fmt+2, &ap);
if (ret) { if (ret) {
*p = talloc_strndup(ctx, input, len); *p = tal_strndup(ctx, input, len);
ret = true; ret = true;
break; break;
} }
...@@ -208,12 +207,12 @@ static char *unexpected(struct ccan_file *i, const char *input, ...@@ -208,12 +207,12 @@ static char *unexpected(struct ccan_file *i, const char *input,
bool ok; bool ok;
unsigned int default_time = default_timeout_ms; unsigned int default_time = default_timeout_ms;
cmd = talloc_asprintf(i, "echo '%s' | %s %s", cmd = tal_fmt(i, "echo '%s' | %s %s",
input, i->compiled[COMPILE_NORMAL], input); input, i->compiled[COMPILE_NORMAL], input);
output = run_with_timeout(i, cmd, &ok, &default_time); output = run_with_timeout(i, cmd, &ok, &default_time);
if (!ok) if (!ok)
return talloc_asprintf(i, "Exited with non-zero status\n"); return tal_fmt(i, "Exited with non-zero status\n");
if (exact) { if (exact) {
if (streq(output, expect) || streq(trim(output), expect)) if (streq(output, expect) || streq(trim(output), expect))
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -46,13 +45,13 @@ static void handle_idem(struct manifest *m, struct score *score) ...@@ -46,13 +45,13 @@ static void handle_idem(struct manifest *m, struct score *score)
/* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */ /* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */
if (strstarts(e->file->name, m->basename) if (strstarts(e->file->name, m->basename)
|| strlen(e->file->name) == strlen(m->basename) + 2) || strlen(e->file->name) == strlen(m->basename) + 2)
name = talloc_asprintf(score, "CCAN_%s_H", m->modname); name = tal_fmt(score, "CCAN_%s_H", m->modname);
else else
name = talloc_asprintf(score, "CCAN_%s_%s", name = tal_fmt(score, "CCAN_%s_%s",
m->modname, e->file->name); m->modname, e->file->name);
fix_name(name); fix_name(name);
q = talloc_asprintf(score, q = tal_fmt(score,
"Should I wrap %s in #ifndef/#define %s for you?", "Should I wrap %s in #ifndef/#define %s for you?",
e->file->name, name); e->file->name, name);
if (!ask(q)) if (!ask(q))
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/talloc/talloc.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
static void check_info_documentation_exists(struct manifest *m, static void check_info_documentation_exists(struct manifest *m,
...@@ -51,7 +50,7 @@ static void create_info_template_doc(struct manifest *m, struct score *score) ...@@ -51,7 +50,7 @@ static void create_info_template_doc(struct manifest *m, struct score *score)
err(1, "Writing to _info.new to insert documentation"); err(1, "Writing to _info.new to insert documentation");
} }
oldcontents = talloc_grab_file(m, m->info_file->fullname, NULL); oldcontents = tal_grab_file(m, m->info_file->fullname, NULL);
if (!oldcontents) { if (!oldcontents) {
unlink_noerr("_info.new"); unlink_noerr("_info.new");
err(1, "Reading %s", m->info_file->fullname); err(1, "Reading %s", m->info_file->fullname);
...@@ -93,13 +92,13 @@ static void check_info_documentation_exists(struct manifest *m, ...@@ -93,13 +92,13 @@ static void check_info_documentation_exists(struct manifest *m,
if (summary && description) { if (summary && description) {
score->score = score->total; score->score = score->total;
} else if (!summary) { } else if (!summary) {
score->error = talloc_strdup(score, score->error = tal_strdup(score,
"_info file has no module documentation.\n\n" "_info file has no module documentation.\n\n"
"CCAN modules use /**-style comments for documentation: the\n" "CCAN modules use /**-style comments for documentation: the\n"
"overall documentation belongs in the _info metafile.\n"); "overall documentation belongs in the _info metafile.\n");
info_documentation_exists.handle = create_info_template_doc; info_documentation_exists.handle = create_info_template_doc;
} else if (!description) { } else if (!description) {
score->error = talloc_strdup(score, score->error = tal_strdup(score,
"_info file has no module description.\n\n" "_info file has no module description.\n\n"
"The lines after the first summary line in the _info file\n" "The lines after the first summary line in the _info file\n"
"documentation should describe the purpose and use of the\n" "documentation should describe the purpose and use of the\n"
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -10,7 +12,6 @@ ...@@ -10,7 +12,6 @@
#include <err.h> #include <err.h>
#include <string.h> #include <string.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
#include <ccan/talloc/talloc.h>
static void check_has_info(struct manifest *m, static void check_has_info(struct manifest *m,
unsigned int *timeleft, unsigned int *timeleft,
...@@ -21,7 +22,7 @@ static void check_has_info(struct manifest *m, ...@@ -21,7 +22,7 @@ static void check_has_info(struct manifest *m,
score->score = score->total; score->score = score->total;
add_info_options(m->info_file); add_info_options(m->info_file);
} else { } else {
score->error = talloc_strdup(score, score->error = tal_strdup(score,
"You have no _info file.\n\n" "You have no _info file.\n\n"
"The file _info contains the metadata for a ccan package: things\n" "The file _info contains the metadata for a ccan package: things\n"
"like the dependencies, the documentation for the package as a whole\n" "like the dependencies, the documentation for the package as a whole\n"
...@@ -63,7 +64,7 @@ static void create_info_template(struct manifest *m, struct score *score) ...@@ -63,7 +64,7 @@ static void create_info_template(struct manifest *m, struct score *score)
if (!ask("Should I create a template _info file for you?")) if (!ask("Should I create a template _info file for you?"))
return; return;
filename = talloc_asprintf(m, "%s/%s", m->dir, "_info"); filename = tal_fmt(m, "%s/%s", m->dir, "_info");
info = fopen(filename, "w"); info = fopen(filename, "w");
if (!info) if (!info)
err(1, "Trying to create a template _info in %s", filename); err(1, "Trying to create a template _info in %s", filename);
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <stdio.h> #include <stdio.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
static void check_info_summary_single_line(struct manifest *m, static void check_info_summary_single_line(struct manifest *m,
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
static void check_license_comment(struct manifest *m, static void check_license_comment(struct manifest *m,
unsigned int *timeleft, struct score *score) unsigned int *timeleft, struct score *score)
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
static void check_license_depends_compat(struct manifest *m, static void check_license_depends_compat(struct manifest *m,
unsigned int *timeleft, unsigned int *timeleft,
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -8,22 +10,23 @@ ...@@ -8,22 +10,23 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/take/take.h>
/* We might need more ../ for nested modules. */ /* We might need more ../ for nested modules. */
static const char *link_prefix(struct manifest *m) static const char *link_prefix(struct manifest *m)
{ {
char *prefix = talloc_strdup(m, "../../"); char *prefix = tal_strdup(m, "../../");
unsigned int i; unsigned int i;
for (i = 0; i < strcount(m->modname, "/"); i++) for (i = 0; i < strcount(m->modname, "/"); i++)
prefix = talloc_append_string(prefix, "../"); prefix = tal_strcat(m, take(prefix), "../");
return talloc_append_string(prefix, "licenses/"); return tal_strcat(m, take(prefix), "licenses/");
} }
static const char *expected_link(const char *prefix, enum license license) static const char *expected_link(const tal_t *ctx,
const char *prefix, enum license license)
{ {
const char *shortname; const char *shortname;
...@@ -63,15 +66,15 @@ static const char *expected_link(const char *prefix, enum license license) ...@@ -63,15 +66,15 @@ static const char *expected_link(const char *prefix, enum license license)
return NULL; return NULL;
} }
return talloc_append_string(talloc_strdup(prefix, prefix), shortname); return tal_strcat(ctx, prefix, shortname);
} }
static void handle_license_link(struct manifest *m, struct score *score) static void handle_license_link(struct manifest *m, struct score *score)
{ {
struct doc_section *d = find_license_tag(m); struct doc_section *d = find_license_tag(m);
const char *prefix = link_prefix(m); const char *prefix = link_prefix(m);
const char *link = talloc_asprintf(m, "%s/LICENSE", m->dir); const char *link = tal_fmt(m, "%s/LICENSE", m->dir);
const char *ldest = expected_link(prefix, m->license); const char *ldest = expected_link(score, prefix, m->license);
char *q; char *q;
printf( printf(
...@@ -79,8 +82,8 @@ static void handle_license_link(struct manifest *m, struct score *score) ...@@ -79,8 +82,8 @@ static void handle_license_link(struct manifest *m, struct score *score)
"LICENSE symlink into %s to avoid too many copies.\n", prefix); "LICENSE symlink into %s to avoid too many copies.\n", prefix);
/* FIXME: make ask printf-like */ /* FIXME: make ask printf-like */
q = talloc_asprintf(m, "Set up link to %s (license is %s)?", q = tal_fmt(m, "Set up link to %s (license is %s)?",
ldest, d->lines[0]); ldest, d->lines[0]);
if (ask(q)) { if (ask(q)) {
if (symlink(ldest, link) != 0) if (symlink(ldest, link) != 0)
err(1, "Creating symlink %s -> %s", link, ldest); err(1, "Creating symlink %s -> %s", link, ldest);
...@@ -94,14 +97,14 @@ static void check_has_license(struct manifest *m, ...@@ -94,14 +97,14 @@ static void check_has_license(struct manifest *m,
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
ssize_t len; ssize_t len;
char *license = talloc_asprintf(m, "%s/LICENSE", m->dir); char *license = tal_fmt(m, "%s/LICENSE", m->dir);
const char *expected; const char *expected;
struct doc_section *d; struct doc_section *d;
const char *prefix = link_prefix(m); const char *prefix = link_prefix(m);
d = find_license_tag(m); d = find_license_tag(m);
if (!d) { if (!d) {
score->error = talloc_strdup(score, "No License: tag in _info"); score->error = tal_strdup(score, "No License: tag in _info");
return; return;
} }
...@@ -118,7 +121,7 @@ static void check_has_license(struct manifest *m, ...@@ -118,7 +121,7 @@ static void check_has_license(struct manifest *m,
/* If they have a license tag at all, we pass. */ /* If they have a license tag at all, we pass. */
score->pass = true; score->pass = true;
expected = expected_link(prefix, m->license); expected = expected_link(m, prefix, m->license);
len = readlink(license, buf, sizeof(buf)); len = readlink(license, buf, sizeof(buf));
if (len < 0) { if (len < 0) {
...@@ -129,7 +132,7 @@ static void check_has_license(struct manifest *m, ...@@ -129,7 +132,7 @@ static void check_has_license(struct manifest *m,
return; return;
} }
score->error score->error
= talloc_asprintf(score, = tal_fmt(score,
"License in _info is '%s'," "License in _info is '%s',"
" expect LICENSE symlink '%s'", " expect LICENSE symlink '%s'",
d->lines[0], expected); d->lines[0], expected);
...@@ -141,7 +144,7 @@ static void check_has_license(struct manifest *m, ...@@ -141,7 +144,7 @@ static void check_has_license(struct manifest *m,
score->score = score->total; score->score = score->total;
return; return;
} }
score->error = talloc_strdup(score, score->error = tal_strdup(score,
"LICENSE does not exist"); "LICENSE does not exist");
if (expected) if (expected)
license_exists.handle = handle_license_link; license_exists.handle = handle_license_link;
...@@ -155,22 +158,22 @@ static void check_has_license(struct manifest *m, ...@@ -155,22 +158,22 @@ static void check_has_license(struct manifest *m,
buf[len] = '\0'; buf[len] = '\0';
if (!strstarts(buf, prefix)) { if (!strstarts(buf, prefix)) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Expected symlink into" "Expected symlink into %s not %s",
" %s not %s", prefix, buf); prefix, buf);
return; return;
} }
if (!expected) { if (!expected) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"License in _info is unknown '%s'," "License in _info is unknown '%s',"
" but LICENSE symlink is '%s'", " but LICENSE symlink is '%s'",
d->lines[0], buf); d->lines[0], buf);
return; return;
} }
if (!streq(buf, expected)) { if (!streq(buf, expected)) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Expected symlink to %s not %s", "Expected symlink to %s not %s",
expected, buf); expected, buf);
return; return;
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
static void check_license_file_compat(struct manifest *m, static void check_license_file_compat(struct manifest *m,
unsigned int *timeleft, unsigned int *timeleft,
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -49,8 +48,8 @@ static void check_includes_build(struct manifest *m, ...@@ -49,8 +48,8 @@ static void check_includes_build(struct manifest *m,
if (fd < 0) if (fd < 0)
err(1, "Creating temporary file %s", tmpsrc); err(1, "Creating temporary file %s", tmpsrc);
contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n", contents = tal_fmt(tmpsrc, "#include <ccan/%s/%s.h>\n",
m->modname, m->basename); m->modname, m->basename);
if (write(fd, contents, strlen(contents)) != strlen(contents)) if (write(fd, contents, strlen(contents)) != strlen(contents))
err(1, "writing to temporary file %s", tmpsrc); err(1, "writing to temporary file %s", tmpsrc);
close(fd); close(fd);
...@@ -60,7 +59,7 @@ static void check_includes_build(struct manifest *m, ...@@ -60,7 +59,7 @@ static void check_includes_build(struct manifest *m,
score->pass = true; score->pass = true;
score->score = score->total; score->score = score->total;
} else { } else {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"#include of the main header file:\n%s", "#include of the main header file:\n%s",
cmdout); cmdout);
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -9,7 +11,6 @@ ...@@ -9,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/talloc/talloc.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
static void check_has_main_header(struct manifest *m, static void check_has_main_header(struct manifest *m,
...@@ -25,7 +26,7 @@ static void check_has_main_header(struct manifest *m, ...@@ -25,7 +26,7 @@ static void check_has_main_header(struct manifest *m,
return; return;
} }
} }
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"You have no %s/%s.h header file.\n\n" "You have no %s/%s.h header file.\n\n"
"CCAN modules have a name, the same as the directory name. They're\n" "CCAN modules have a name, the same as the directory name. They're\n"
"expected to have an interface in the header of the same name.\n", "expected to have an interface in the header of the same name.\n",
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/take/take.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -24,14 +24,14 @@ static const char *can_build(struct manifest *m) ...@@ -24,14 +24,14 @@ static const char *can_build(struct manifest *m)
static char *obj_list(const struct manifest *m, enum compile_type ctype) static char *obj_list(const struct manifest *m, enum compile_type ctype)
{ {
char *list = talloc_strdup(m, ""); char *list = tal_strdup(m, "");
struct ccan_file *i; struct ccan_file *i;
/* Objects from all the C files. */ /* Objects from all the C files. */
list_for_each(&m->c_files, i, list) list_for_each(&m->c_files, i, list) {
list = talloc_asprintf_append(list, "%s ", list = tal_strcat(m, take(list), i->compiled[ctype]);
i->compiled[ctype]); list = tal_strcat(m, take(list), " ");
}
return list; return list;
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/take/take.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -27,16 +27,16 @@ static char *obj_list(const struct manifest *m) ...@@ -27,16 +27,16 @@ static char *obj_list(const struct manifest *m)
struct manifest *i; struct manifest *i;
if (m->compiled[COMPILE_NORMAL]) if (m->compiled[COMPILE_NORMAL])
list = talloc_strdup(m, m->compiled[COMPILE_NORMAL]); list = tal_strdup(m, m->compiled[COMPILE_NORMAL]);
else else
list = talloc_strdup(m, ""); list = tal_strdup(m, "");
/* Other CCAN deps. */ /* Other CCAN deps. */
list_for_each(&m->deps, i, list) { list_for_each(&m->deps, i, list) {
if (i->compiled[COMPILE_NORMAL]) if (!i->compiled[COMPILE_NORMAL])
list = talloc_asprintf_append(list, " %s", continue;
i->compiled list = tal_strcat(m, take(list), " ");
[COMPILE_NORMAL]); list = tal_strcat(m, take(list), i->compiled[COMPILE_NORMAL]);
} }
return list; return list;
} }
...@@ -45,11 +45,11 @@ static char *lib_list(const struct manifest *m) ...@@ -45,11 +45,11 @@ static char *lib_list(const struct manifest *m)
{ {
unsigned int i; unsigned int i;
char **libs; char **libs;
char *ret = talloc_strdup(m, ""); char *ret = tal_strdup(m, "");
libs = get_libs(m, m->dir, "depends", get_or_compile_info); libs = get_libs(m, m->dir, "depends", get_or_compile_info);
for (i = 0; libs[i]; i++) for (i = 0; libs[i]; i++)
ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); tal_append_fmt(&ret, "-l%s ", libs[i]);
return ret; return ret;
} }
...@@ -66,13 +66,13 @@ static void check_use_build(struct manifest *m, ...@@ -66,13 +66,13 @@ static void check_use_build(struct manifest *m,
if (fd < 0) if (fd < 0)
err(1, "Creating temporary file %s", tmpfile); err(1, "Creating temporary file %s", tmpfile);
contents = talloc_asprintf(tmpfile, contents = tal_fmt(tmpfile,
"#include <ccan/%s/%s.h>\n" "#include <ccan/%s/%s.h>\n"
"int main(void)\n" "int main(void)\n"
"{\n" "{\n"
" return 0;\n" " return 0;\n"
"}\n", "}\n",
m->modname, m->basename); m->modname, m->basename);
if (write(fd, contents, strlen(contents)) != strlen(contents)) if (write(fd, contents, strlen(contents)) != strlen(contents))
err(1, "Failure writing to temporary file %s", tmpfile); err(1, "Failure writing to temporary file %s", tmpfile);
close(fd); close(fd);
......
/* Trailing whitespace test. Almost embarrassing, but trivial. */ /* Trailing whitespace test. Almost embarrassing, but trivial. */
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/talloc/talloc.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/tal/str/str.h>
/* FIXME: only print full analysis if verbose >= 2. */ /* FIXME: only print full analysis if verbose >= 2. */
static char *get_trailing_whitespace(const char *line) static char *get_trailing_whitespace(const tal_t *ctx, const char *line)
{ {
const char *e = strchr(line, 0); const char *e = strchr(line, 0);
while (e>line && (e[-1]==' ' || e[-1]=='\t')) while (e>line && (e[-1]==' ' || e[-1]=='\t'))
...@@ -16,9 +16,8 @@ static char *get_trailing_whitespace(const char *line) ...@@ -16,9 +16,8 @@ static char *get_trailing_whitespace(const char *line)
return NULL; //the line only consists of spaces return NULL; //the line only consists of spaces
if (strlen(line) > 20) if (strlen(line) > 20)
return talloc_asprintf(line, "...'%s'", return tal_fmt(ctx, "...'%s'", line + strlen(line) - 20);
line + strlen(line) - 20); return tal_fmt(ctx, "'%s'", line);
return talloc_asprintf(line, "'%s'", line);
} }
static void check_trailing_whitespace(struct manifest *m, static void check_trailing_whitespace(struct manifest *m,
...@@ -36,7 +35,8 @@ static void check_trailing_whitespace(struct manifest *m, ...@@ -36,7 +35,8 @@ static void check_trailing_whitespace(struct manifest *m,
list_for_each(list, f, list) { list_for_each(list, f, list) {
char **lines = get_ccan_file_lines(f); char **lines = get_ccan_file_lines(f);
for (i = 0; i < f->num_lines; i++) { for (i = 0; i < f->num_lines; i++) {
char *err = get_trailing_whitespace(lines[i]); char *err = get_trailing_whitespace(score,
lines[i]);
if (err) if (err)
score_file_error(score, f, i+1, score_file_error(score, f, i+1,
"%s", err); "%s", err);
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -36,12 +35,12 @@ void build_objects(struct manifest *m, ...@@ -36,12 +35,12 @@ void build_objects(struct manifest *m,
list_for_each(&m->c_files, i, list) { list_for_each(&m->c_files, i, list) {
char *output; char *output;
char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name); char *fullfile = tal_fmt(m, "%s/%s", m->dir, i->name);
i->compiled[ctype] = temp_file(m, "", fullfile); i->compiled[ctype] = temp_file(m, "", fullfile);
if (!compile_object(score, fullfile, ccan_dir, compiler, flags, if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
i->compiled[ctype], &output)) { i->compiled[ctype], &output)) {
talloc_free(i->compiled[ctype]); tal_free(i->compiled[ctype]);
score_file_error(score, i, 0, score_file_error(score, i, 0,
"Compiling object files:\n%s", "Compiling object files:\n%s",
output); output);
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -26,7 +24,7 @@ static const char *uses_stringfuncs(struct manifest *m) ...@@ -26,7 +24,7 @@ static const char *uses_stringfuncs(struct manifest *m)
char *match; char *match;
list_for_each(list, i, list) { list_for_each(list, i, list) {
if (strreg(m, get_ccan_file_contents(i), if (tal_strreg(m, get_ccan_file_contents(i),
"(isalnum|isalpha|isascii|isblank|iscntrl" "(isalnum|isalpha|isascii|isblank|iscntrl"
"|isdigit|isgraph|islower|isprint|ispunct" "|isdigit|isgraph|islower|isprint|ispunct"
"|isspace|isupper|isxdigit" "|isspace|isupper|isxdigit"
...@@ -103,7 +101,7 @@ static void build_objects_with_stringchecks(struct manifest *m, ...@@ -103,7 +101,7 @@ static void build_objects_with_stringchecks(struct manifest *m,
int tmpfd; int tmpfd;
/* FIXME:: We need -I so local #includes work outside normal dir. */ /* FIXME:: We need -I so local #includes work outside normal dir. */
flags = talloc_asprintf(score, "-I%s %s", m->dir, cflags); flags = tal_fmt(score, "-I%s %s", m->dir, cflags);
/* Won't work into macros, but will get inline functions. */ /* Won't work into macros, but will get inline functions. */
if (list_empty(&m->c_files)) { if (list_empty(&m->c_files)) {
...@@ -111,8 +109,8 @@ static void build_objects_with_stringchecks(struct manifest *m, ...@@ -111,8 +109,8 @@ static void build_objects_with_stringchecks(struct manifest *m,
i = get_main_header(m); i = get_main_header(m);
tmp = temp_file(score, ".c", i->fullname); tmp = temp_file(score, ".c", i->fullname);
tmpfd = start_file(tmp); tmpfd = start_file(tmp);
line = talloc_asprintf(score, "#include <ccan/%s/%s.h>\n", line = tal_fmt(score, "#include <ccan/%s/%s.h>\n",
m->modname, m->basename); m->modname, m->basename);
write_str(tmpfd, line); write_str(tmpfd, line);
close(tmpfd); close(tmpfd);
test_compile(score, i, tmp, flags, &errors, &warnings); test_compile(score, i, tmp, flags, &errors, &warnings);
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/talloc/talloc.h> #include <ccan/tal/str/str.h>
#include "reduce_features.h" #include "reduce_features.h"
#include "build.h" #include "build.h"
...@@ -7,8 +7,8 @@ static void check_objs_build_without_features(struct manifest *m, ...@@ -7,8 +7,8 @@ static void check_objs_build_without_features(struct manifest *m,
unsigned int *timeleft, unsigned int *timeleft,
struct score *score) struct score *score)
{ {
const char *flags = talloc_asprintf(score, "%s %s", const char *flags = tal_fmt(score, "%s %s",
REDUCE_FEATURES_FLAGS, cflags); REDUCE_FEATURES_FLAGS, cflags);
build_objects(m, score, flags, COMPILE_NOFEAT); build_objects(m, score, flags, COMPILE_NOFEAT);
} }
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/htable/htable_type.h> #include <ccan/htable/htable_type.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/hash/hash.h> #include <ccan/hash/hash.h>
#include <ccan/read_write_all/read_write_all.h> #include <ccan/read_write_all/read_write_all.h>
#include <errno.h> #include <errno.h>
...@@ -20,7 +18,7 @@ bool features_were_reduced; ...@@ -20,7 +18,7 @@ bool features_were_reduced;
static const char *can_run(struct manifest *m) static const char *can_run(struct manifest *m)
{ {
if (!config_header) if (!config_header)
return talloc_strdup(m, "Could not read config.h"); return tal_strdup(m, "Could not read config.h");
return NULL; return NULL;
} }
...@@ -103,11 +101,12 @@ static struct htable_option *get_used_options(struct manifest *m) ...@@ -103,11 +101,12 @@ static struct htable_option *get_used_options(struct manifest *m)
static struct htable_option *get_config_options(struct manifest *m) static struct htable_option *get_config_options(struct manifest *m)
{ {
const char **lines = (const char **)strsplit(m, config_header, "\n"); const char **lines = (const char **)tal_strsplit(m, config_header, "\n",
STR_EMPTY_OK);
unsigned int i; unsigned int i;
struct htable_option *opts = htable_option_new(); struct htable_option *opts = htable_option_new();
for (i = 0; i < talloc_array_length(lines) - 1; i++) { for (i = 0; i < tal_count(lines) - 1; i++) {
char *sym; char *sym;
if (!get_token(&lines[i], "#")) if (!get_token(&lines[i], "#"))
...@@ -166,13 +165,12 @@ static void do_reduce_features(struct manifest *m, ...@@ -166,13 +165,12 @@ static void do_reduce_features(struct manifest *m,
return; return;
/* Now make our own config.h variant, with our own options. */ /* Now make our own config.h variant, with our own options. */
hdr = talloc_strdup(m, "/* Modified by reduce_features */\n"); hdr = tal_strcat(m, "/* Modified by reduce_features */\n",
hdr = talloc_append_string(hdr, config_header); config_header);
for (sym = htable_option_first(options, &i); for (sym = htable_option_first(options, &i);
sym; sym;
sym = htable_option_next(options, &i)) { sym = htable_option_next(options, &i)) {
hdr = talloc_asprintf_append tal_append_fmt(&hdr, "#undef %s\n#define %s 0\n", sym, sym);
(hdr, "#undef %s\n#define %s 0\n", sym, sym);
} }
if (mkdir("reduced-features", 0700) != 0 && errno != EEXIST) if (mkdir("reduced-features", 0700) != 0 && errno != EEXIST)
err(1, "Creating reduced-features directory"); err(1, "Creating reduced-features directory");
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -27,33 +26,29 @@ static const char *can_build(struct manifest *m) ...@@ -27,33 +26,29 @@ static const char *can_build(struct manifest *m)
char *test_obj_list(const struct manifest *m, bool link_with_module, char *test_obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype, enum compile_type own_ctype) enum compile_type ctype, enum compile_type own_ctype)
{ {
char *list = talloc_strdup(m, ""); char *list = tal_strdup(m, "");
struct ccan_file *i; struct ccan_file *i;
struct manifest *subm; struct manifest *subm;
/* Objects from any other C files. */ /* Objects from any other C files. */
list_for_each(&m->other_test_c_files, i, list) list_for_each(&m->other_test_c_files, i, list)
list = talloc_asprintf_append(list, " %s", tal_append_fmt(&list, " %s", i->compiled[ctype]);
i->compiled[ctype]);
/* Our own object files. */ /* Our own object files. */
if (link_with_module) if (link_with_module)
list_for_each(&m->c_files, i, list) list_for_each(&m->c_files, i, list)
list = talloc_asprintf_append(list, " %s", tal_append_fmt(&list, " %s", i->compiled[own_ctype]);
i->compiled[own_ctype]);
/* Other ccan modules (normal depends). */ /* Other ccan modules (normal depends). */
list_for_each(&m->deps, subm, list) { list_for_each(&m->deps, subm, list) {
if (subm->compiled[ctype]) if (subm->compiled[ctype])
list = talloc_asprintf_append(list, " %s", tal_append_fmt(&list, " %s", subm->compiled[ctype]);
subm->compiled[ctype]);
} }
/* Other ccan modules (test depends). */ /* Other ccan modules (test depends). */
list_for_each(&m->test_deps, subm, list) { list_for_each(&m->test_deps, subm, list) {
if (subm->compiled[ctype]) if (subm->compiled[ctype])
list = talloc_asprintf_append(list, " %s", tal_append_fmt(&list, " %s", subm->compiled[ctype]);
subm->compiled[ctype]);
} }
return list; return list;
...@@ -63,11 +58,11 @@ char *test_lib_list(const struct manifest *m, enum compile_type ctype) ...@@ -63,11 +58,11 @@ char *test_lib_list(const struct manifest *m, enum compile_type ctype)
{ {
unsigned int i; unsigned int i;
char **libs; char **libs;
char *ret = talloc_strdup(m, ""); char *ret = tal_strdup(m, "");
libs = get_libs(m, m->dir, "testdepends", get_or_compile_info); libs = get_libs(m, m->dir, "testdepends", get_or_compile_info);
for (i = 0; libs[i]; i++) for (i = 0; libs[i]; i++)
ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); tal_append_fmt(&ret, "-l%s ", libs[i]);
return ret; return ret;
} }
...@@ -81,11 +76,11 @@ static bool compile(const void *ctx, ...@@ -81,11 +76,11 @@ static bool compile(const void *ctx,
{ {
char *fname, *flags; char *fname, *flags;
flags = talloc_asprintf(ctx, "%s%s%s", flags = tal_fmt(ctx, "%s%s%s",
fail ? "-DFAIL " : "", fail ? "-DFAIL " : "",
cflags, cflags,
ctype == COMPILE_NOFEAT ctype == COMPILE_NOFEAT
? " "REDUCE_FEATURES_FLAGS : ""); ? " "REDUCE_FEATURES_FLAGS : "");
fname = temp_file(ctx, "", file->fullname); fname = temp_file(ctx, "", file->fullname);
if (!compile_and_link(ctx, file->fullname, ccan_dir, if (!compile_and_link(ctx, file->fullname, ccan_dir,
...@@ -93,7 +88,7 @@ static bool compile(const void *ctx, ...@@ -93,7 +88,7 @@ static bool compile(const void *ctx,
ctype, ctype), ctype, ctype),
compiler, flags, test_lib_list(m, ctype), fname, compiler, flags, test_lib_list(m, ctype), fname,
output)) { output)) {
talloc_free(fname); tal_free(fname);
return false; return false;
} }
...@@ -111,10 +106,10 @@ static void compile_async(const void *ctx, ...@@ -111,10 +106,10 @@ static void compile_async(const void *ctx,
char *flags; char *flags;
file->compiled[ctype] = temp_file(ctx, "", file->fullname); file->compiled[ctype] = temp_file(ctx, "", file->fullname);
flags = talloc_asprintf(ctx, "%s%s", flags = tal_fmt(ctx, "%s%s",
cflags, cflags,
ctype == COMPILE_NOFEAT ctype == COMPILE_NOFEAT
? " "REDUCE_FEATURES_FLAGS : ""); ? " "REDUCE_FEATURES_FLAGS : "");
compile_and_link_async(file, time_ms, file->fullname, ccan_dir, compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
test_obj_list(m, link_with_module, ctype, ctype), test_obj_list(m, link_with_module, ctype, ctype),
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -25,7 +24,7 @@ static const char *can_run_coverage(struct manifest *m) ...@@ -25,7 +24,7 @@ static const char *can_run_coverage(struct manifest *m)
char *output; char *output;
if (!run_command(m, &timeleft, &output, "gcov -h")) if (!run_command(m, &timeleft, &output, "gcov -h"))
return talloc_asprintf(m, "No gcov support: %s", output); return tal_fmt(m, "No gcov support: %s", output);
return NULL; return NULL;
#else #else
return "No coverage support for this compiler"; return "No coverage support for this compiler";
...@@ -38,7 +37,7 @@ static void cov_compile(const void *ctx, ...@@ -38,7 +37,7 @@ static void cov_compile(const void *ctx,
struct ccan_file *file, struct ccan_file *file,
bool link_with_module) bool link_with_module)
{ {
char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS); char *flags = tal_fmt(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname); file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
compile_and_link_async(file, time_ms, file->fullname, ccan_dir, compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
...@@ -59,13 +58,13 @@ static void do_compile_coverage_tests(struct manifest *m, ...@@ -59,13 +58,13 @@ static void do_compile_coverage_tests(struct manifest *m,
struct ccan_file *i; struct ccan_file *i;
struct list_head *h; struct list_head *h;
bool ok; bool ok;
char *f = talloc_asprintf(score, "%s %s", cflags, COVERAGE_CFLAGS); char *f = tal_fmt(score, "%s %s", cflags, COVERAGE_CFLAGS);
/* For API tests, we need coverage version of module. */ /* For API tests, we need coverage version of module. */
if (!list_empty(&m->api_tests)) { if (!list_empty(&m->api_tests)) {
build_objects(m, score, f, COMPILE_COVERAGE); build_objects(m, score, f, COMPILE_COVERAGE);
if (!score->pass) { if (!score->pass) {
score->error = talloc_strdup(score, score->error = tal_strdup(score,
"Failed to compile module objects with coverage"); "Failed to compile module objects with coverage");
return; return;
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -53,7 +51,7 @@ static unsigned int score_coverage(float covered, unsigned total) ...@@ -53,7 +51,7 @@ static unsigned int score_coverage(float covered, unsigned total)
static void analyze_coverage(struct manifest *m, bool full_gcov, static void analyze_coverage(struct manifest *m, bool full_gcov,
const char *output, struct score *score) const char *output, struct score *score)
{ {
char **lines = strsplit(score, output, "\n"); char **lines = tal_strsplit(score, output, "\n", STR_EMPTY_OK);
float covered_lines = 0.0; float covered_lines = 0.0;
unsigned int i, total_lines = 0; unsigned int i, total_lines = 0;
bool lines_matter = false; bool lines_matter = false;
...@@ -100,11 +98,11 @@ static void analyze_coverage(struct manifest *m, bool full_gcov, ...@@ -100,11 +98,11 @@ static void analyze_coverage(struct manifest *m, bool full_gcov,
apostrophe = strchr(filename, '\''); apostrophe = strchr(filename, '\'');
*apostrophe = '\0'; *apostrophe = '\0';
if (lines_matter) { if (lines_matter) {
file = talloc_grab_file(score, filename, NULL); file = tal_grab_file(score, filename, NULL);
if (!file) { if (!file) {
score->error = talloc_asprintf(score, score->error = tal_fmt(score,
"Reading %s", "Reading %s",
filename); filename);
return; return;
} }
printf("%s", file); printf("%s", file);
...@@ -144,19 +142,18 @@ static void do_run_coverage_tests(struct manifest *m, ...@@ -144,19 +142,18 @@ static void do_run_coverage_tests(struct manifest *m,
bool ran_some = false; bool ran_some = false;
/* This tells gcov where we put those .gcno files. */ /* This tells gcov where we put those .gcno files. */
outdir = talloc_dirname(score, outdir = tal_dirname(score,
m->info_file->compiled[COMPILE_NORMAL]); m->info_file->compiled[COMPILE_NORMAL]);
covcmd = talloc_asprintf(m, "gcov %s -o %s", covcmd = tal_fmt(m, "gcov %s -o %s",
full_gcov ? "" : "-n", full_gcov ? "" : "-n",
outdir); outdir);
/* Run them all. */ /* Run them all. */
foreach_ptr(list, &m->run_tests, &m->api_tests) { foreach_ptr(list, &m->run_tests, &m->api_tests) {
list_for_each(list, i, list) { list_for_each(list, i, list) {
if (run_command(score, timeleft, &cmdout, if (run_command(score, timeleft, &cmdout,
"%s", i->compiled[COMPILE_COVERAGE])) { "%s", i->compiled[COMPILE_COVERAGE])) {
covcmd = talloc_asprintf_append(covcmd, " %s", tal_append_fmt(&covcmd, " %s", i->fullname);
i->fullname);
} else { } else {
score_file_error(score, i, 0, score_file_error(score, i, 0,
"Running test with coverage" "Running test with coverage"
...@@ -176,8 +173,7 @@ static void do_run_coverage_tests(struct manifest *m, ...@@ -176,8 +173,7 @@ static void do_run_coverage_tests(struct manifest *m,
/* Now run gcov: we want output even if it succeeds. */ /* Now run gcov: we want output even if it succeeds. */
if (!run_command(score, timeleft, &cmdout, "%s", covcmd)) { if (!run_command(score, timeleft, &cmdout, "%s", covcmd)) {
score->error = talloc_asprintf(score, "Running gcov: %s", score->error = tal_fmt(score, "Running gcov: %s", cmdout);
cmdout);
return; return;
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <ccan/tal/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -8,7 +9,6 @@ ...@@ -8,7 +9,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/talloc/talloc.h>
static void check_tests_exist(struct manifest *m, static void check_tests_exist(struct manifest *m,
unsigned int *timeleft, struct score *score); unsigned int *timeleft, struct score *score);
...@@ -25,7 +25,7 @@ static void handle_no_tests(struct manifest *m, struct score *score) ...@@ -25,7 +25,7 @@ static void handle_no_tests(struct manifest *m, struct score *score)
{ {
FILE *run; FILE *run;
struct ccan_file *i; struct ccan_file *i;
char *test_dir = talloc_asprintf(m, "%s/test", m->dir), *run_file; char *test_dir = tal_fmt(m, "%s/test", m->dir), *run_file;
printf( printf(
"CCAN modules have a directory called test/ which contains tests.\n" "CCAN modules have a directory called test/ which contains tests.\n"
...@@ -64,7 +64,7 @@ static void handle_no_tests(struct manifest *m, struct score *score) ...@@ -64,7 +64,7 @@ static void handle_no_tests(struct manifest *m, struct score *score)
err(1, "Creating test/ directory"); err(1, "Creating test/ directory");
} }
run_file = talloc_asprintf(test_dir, "%s/run.c", test_dir); run_file = tal_fmt(test_dir, "%s/run.c", test_dir);
run = fopen(run_file, "w"); run = fopen(run_file, "w");
if (!run) if (!run)
err(1, "Trying to create a test/run.c"); err(1, "Trying to create a test/run.c");
...@@ -106,10 +106,10 @@ static void check_tests_exist(struct manifest *m, ...@@ -106,10 +106,10 @@ static void check_tests_exist(struct manifest *m,
unsigned int *timeleft, struct score *score) unsigned int *timeleft, struct score *score)
{ {
struct stat st; struct stat st;
char *test_dir = talloc_asprintf(m, "%s/test", m->dir); char *test_dir = tal_fmt(m, "%s/test", m->dir);
if (lstat(test_dir, &st) != 0) { if (lstat(test_dir, &st) != 0) {
score->error = talloc_strdup(score, "No test directory"); score->error = tal_strdup(score, "No test directory");
if (errno != ENOENT) if (errno != ENOENT)
err(1, "statting %s", test_dir); err(1, "statting %s", test_dir);
tests_exist.handle = handle_no_tests; tests_exist.handle = handle_no_tests;
...@@ -119,7 +119,7 @@ static void check_tests_exist(struct manifest *m, ...@@ -119,7 +119,7 @@ static void check_tests_exist(struct manifest *m,
} }
if (!S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode)) {
score->error = talloc_strdup(score, "test is not a directory"); score->error = tal_strdup(score, "test is not a directory");
return; return;
} }
...@@ -127,8 +127,7 @@ static void check_tests_exist(struct manifest *m, ...@@ -127,8 +127,7 @@ static void check_tests_exist(struct manifest *m,
&& list_empty(&m->run_tests) && list_empty(&m->run_tests)
&& list_empty(&m->compile_ok_tests) && list_empty(&m->compile_ok_tests)
&& list_empty(&m->compile_fail_tests)) { && list_empty(&m->compile_fail_tests)) {
score->error = talloc_strdup(score, score->error = tal_strdup(score, "No tests in test directory");
"No tests in test directory");
tests_exist.handle = handle_no_tests; tests_exist.handle = handle_no_tests;
return; return;
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -97,8 +96,7 @@ static void do_compile_test_helpers_without_features(struct manifest *m, ...@@ -97,8 +96,7 @@ static void do_compile_test_helpers_without_features(struct manifest *m,
{ {
char *flags; char *flags;
flags = talloc_asprintf(score, "%s %s", cflags, flags = tal_fmt(score, "%s %s", cflags, REDUCE_FEATURES_FLAGS);
REDUCE_FEATURES_FLAGS);
compile_test_helpers(m, timeleft, score, flags, COMPILE_NOFEAT); compile_test_helpers(m, timeleft, score, flags, COMPILE_NOFEAT);
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h> #include <ccan/take/take.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -36,12 +36,12 @@ static const char *can_run(struct manifest *m) ...@@ -36,12 +36,12 @@ static const char *can_run(struct manifest *m)
static const char *concat(struct score *score, char *bits[]) static const char *concat(struct score *score, char *bits[])
{ {
unsigned int i; unsigned int i;
char *ret = talloc_strdup(score, ""); char *ret = tal_strdup(score, "");
for (i = 0; bits[i]; i++) { for (i = 0; bits[i]; i++) {
if (i) if (i)
ret = talloc_append_string(ret, " "); ret = tal_strcat(score, take(ret), " ");
ret = talloc_append_string(ret, bits[i]); ret = tal_strcat(score, take(ret), bits[i]);
} }
return ret; return ret;
} }
...@@ -60,7 +60,7 @@ static void run_test(void *ctx, ...@@ -60,7 +60,7 @@ static void run_test(void *ctx,
/* FIXME: Valgrind's output sucks. XML is /* FIXME: Valgrind's output sucks. XML is
* unreadable by humans *and* doesn't support * unreadable by humans *and* doesn't support
* children reporting. */ * children reporting. */
i->valgrind_log = talloc_asprintf(m, i->valgrind_log = tal_fmt(m,
"%s.valgrind-log", "%s.valgrind-log",
i->compiled[COMPILE_NORMAL]); i->compiled[COMPILE_NORMAL]);
...@@ -126,8 +126,8 @@ static void run_under_debugger(struct manifest *m, struct score *score) ...@@ -126,8 +126,8 @@ static void run_under_debugger(struct manifest *m, struct score *score)
if (!ask("Should I run the first failing test under the debugger?")) if (!ask("Should I run the first failing test under the debugger?"))
return; return;
command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s", command = tal_fmt(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
first->file->compiled[COMPILE_NORMAL]); first->file->compiled[COMPILE_NORMAL]);
if (system(command)) if (system(command))
doesnt_matter(); doesnt_matter();
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/take/take.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <ccan/str_talloc/str_talloc.h>
#include "tests_pass.h" #include "tests_pass.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -21,7 +20,7 @@ ...@@ -21,7 +20,7 @@
static const char *can_run_vg(struct manifest *m) static const char *can_run_vg(struct manifest *m)
{ {
if (!do_valgrind) if (!do_valgrind)
return talloc_asprintf(m, "No valgrind support"); return tal_fmt(m, "No valgrind support");
return NULL; return NULL;
} }
...@@ -61,35 +60,34 @@ static bool blank_line(const char *line) ...@@ -61,35 +60,34 @@ static bool blank_line(const char *line)
static char **extract_matching(const char *prefix, char *lines[]) static char **extract_matching(const char *prefix, char *lines[])
{ {
unsigned int i, num_ret = 0; unsigned int i, num_ret = 0;
char **ret = talloc_array(lines, char *, talloc_array_length(lines)); char **ret = tal_arr(lines, char *, tal_count(lines));
for (i = 0; i < talloc_array_length(lines) - 1; i++) { for (i = 0; i < tal_count(lines) - 1; i++) {
if (strstarts(lines[i], prefix)) { if (strstarts(lines[i], prefix)) {
ret[num_ret++] = talloc_steal(ret, lines[i]); ret[num_ret++] = tal_strdup(ret, lines[i]);
lines[i] = (char *)""; lines[i] = (char *)"";
} }
} }
ret[num_ret++] = NULL; ret[num_ret++] = NULL;
/* Make sure length is correct! */ /* Make sure tal_count is correct! */
return talloc_realloc(NULL, ret, char *, num_ret); tal_resize(&ret, num_ret);
return ret;
} }
static char *get_leaks(char *lines[], char **errs) static char *get_leaks(char *lines[], char **errs)
{ {
char *leaks = talloc_strdup(lines, ""); char *leaks = tal_strdup(lines, "");
unsigned int i; unsigned int i;
for (i = 0; i < talloc_array_length(lines) - 1; i++) { for (i = 0; i < tal_count(lines) - 1; i++) {
if (strstr(lines[i], " lost ")) { if (strstr(lines[i], " lost ")) {
/* A leak... */ /* A leak... */
if (strstr(lines[i], " definitely lost ")) { if (strstr(lines[i], " definitely lost ")) {
/* Definite leak, report. */ /* Definite leak, report. */
while (lines[i] && !blank_line(lines[i])) { while (lines[i] && !blank_line(lines[i])) {
leaks = talloc_append_string(leaks, tal_append_fmt(&leaks, "%s\n",
lines[i]); lines[i]);
leaks = talloc_append_string(leaks,
"\n");
i++; i++;
} }
} else } else
...@@ -99,8 +97,10 @@ static char *get_leaks(char *lines[], char **errs) ...@@ -99,8 +97,10 @@ static char *get_leaks(char *lines[], char **errs)
} else { } else {
/* A real error. */ /* A real error. */
while (lines[i] && !blank_line(lines[i])) { while (lines[i] && !blank_line(lines[i])) {
*errs = talloc_append_string(*errs, lines[i]); if (!*errs)
*errs = talloc_append_string(*errs, "\n"); *errs = tal_fmt(NULL, "%s\n", lines[i]);
else
tal_append_fmt(errs, "%s\n", lines[i]);
i++; i++;
} }
} }
...@@ -111,12 +111,12 @@ static char *get_leaks(char *lines[], char **errs) ...@@ -111,12 +111,12 @@ static char *get_leaks(char *lines[], char **errs)
/* Returns leaks, and sets errs[] */ /* Returns leaks, and sets errs[] */
static char *analyze_output(const char *output, char **errs) static char *analyze_output(const char *output, char **errs)
{ {
char *leaks = talloc_strdup(output, ""); char *leaks = tal_strdup(output, "");
unsigned int i; unsigned int i;
char **lines = strsplit(output, output, "\n"); char **lines = tal_strsplit(output, output, "\n", STR_EMPTY_OK);
*errs = talloc_strdup(output, ""); *errs = tal_strdup(output, "");
for (i = 0; i < talloc_array_length(lines) - 1; i++) { for (i = 0; i < tal_count(lines) - 1; i++) {
unsigned int preflen = strspn(lines[i], "=0123456789"); unsigned int preflen = strspn(lines[i], "=0123456789");
char *prefix, **sublines; char *prefix, **sublines;
...@@ -124,18 +124,19 @@ static char *analyze_output(const char *output, char **errs) ...@@ -124,18 +124,19 @@ static char *analyze_output(const char *output, char **errs)
if (preflen == 0) if (preflen == 0)
continue; continue;
prefix = talloc_strndup(output, lines[i], preflen); prefix = tal_strndup(output, lines[i], preflen);
sublines = extract_matching(prefix, lines); sublines = extract_matching(prefix, lines);
leaks = talloc_append_string(leaks, get_leaks(sublines, errs)); leaks = tal_strcat(output, take(leaks),
take(get_leaks(sublines, errs)));
} }
if (!leaks[0]) { if (!leaks[0]) {
talloc_free(leaks); tal_free(leaks);
leaks = NULL; leaks = NULL;
} }
if (!(*errs)[0]) { if (!(*errs)[0]) {
talloc_free(*errs); tal_free(*errs);
*errs = NULL; *errs = NULL;
} }
return leaks; return leaks;
...@@ -144,12 +145,12 @@ static char *analyze_output(const char *output, char **errs) ...@@ -144,12 +145,12 @@ static char *analyze_output(const char *output, char **errs)
static const char *concat(struct score *score, char *bits[]) static const char *concat(struct score *score, char *bits[])
{ {
unsigned int i; unsigned int i;
char *ret = talloc_strdup(score, ""); char *ret = tal_strdup(score, "");
for (i = 0; bits[i]; i++) { for (i = 0; bits[i]; i++) {
if (i) if (i)
ret = talloc_append_string(ret, " "); ret = tal_strcat(score, take(ret), " ");
ret = talloc_append_string(ret, bits[i]); ret = tal_strcat(score, take(ret), bits[i]);
} }
return ret; return ret;
} }
...@@ -179,7 +180,7 @@ static void do_run_tests_vg(struct manifest *m, ...@@ -179,7 +180,7 @@ static void do_run_tests_vg(struct manifest *m,
continue; continue;
} }
output = talloc_grab_file(i, i->valgrind_log, NULL); output = tal_grab_file(i, i->valgrind_log, NULL);
/* No valgrind errors? */ /* No valgrind errors? */
if (!output || output[0] == '\0') { if (!output || output[0] == '\0') {
err = NULL; err = NULL;
...@@ -249,11 +250,10 @@ static void run_under_debugger_vg(struct manifest *m, struct score *score) ...@@ -249,11 +250,10 @@ static void run_under_debugger_vg(struct manifest *m, struct score *score)
return; return;
first = list_top(&score->per_file_errors, struct file_error, list); first = list_top(&score->per_file_errors, struct file_error, list);
command = talloc_asprintf(m, "valgrind --leak-check=full --db-attach=yes%s %s", command = tal_fmt(m, "valgrind --leak-check=full --db-attach=yes%s %s",
concat(score, concat(score, per_file_options(&tests_pass_valgrind,
per_file_options(&tests_pass_valgrind, first->file)),
first->file)), first->file->compiled[COMPILE_NORMAL]);
first->file->compiled[COMPILE_NORMAL]);
if (system(command)) if (system(command))
doesnt_matter(); doesnt_matter();
} }
......
#include <tools/ccanlint/ccanlint.h> #include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h> #include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/foreach/foreach.h> #include <ccan/foreach/foreach.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -55,9 +54,8 @@ static void run_under_debugger(struct manifest *m, struct score *score) ...@@ -55,9 +54,8 @@ static void run_under_debugger(struct manifest *m, struct score *score)
if (!ask("Should I run the first failing test under the debugger?")) if (!ask("Should I run the first failing test under the debugger?"))
return; return;
command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s", command = tal_fmt(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
first->file->compiled first->file->compiled[COMPILE_NOFEAT]);
[COMPILE_NOFEAT]);
if (system(command)) if (system(command))
doesnt_matter(); doesnt_matter();
} }
......
#include "tools.h" #include "tools.h"
#include <ccan/talloc/talloc.h>
#include <stdlib.h> #include <stdlib.h>
bool compile_verbose = false; bool compile_verbose = false;
...@@ -16,7 +15,7 @@ char *link_objects(const void *ctx, const char *basename, ...@@ -16,7 +15,7 @@ char *link_objects(const void *ctx, const char *basename,
if (run_command(ctx, NULL, errmsg, "ld -r -o %s %s", file, objs)) if (run_command(ctx, NULL, errmsg, "ld -r -o %s %s", file, objs))
return file; return file;
talloc_free(file); tal_free(file);
return NULL; return NULL;
} }
......
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/read_write_all/read_write_all.h> #include <ccan/read_write_all/read_write_all.h>
#include <ccan/rbuf/rbuf.h> #include <ccan/rbuf/rbuf.h>
#include <ccan/compiler/compiler.h> #include <ccan/compiler/compiler.h>
...@@ -22,7 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...) ...@@ -22,7 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
struct rbuf in; struct rbuf in;
va_start(ap, format); va_start(ap, format);
cmd = talloc_vasprintf(ctx, format, ap); cmd = tal_vfmt(ctx, format, ap);
va_end(ap); va_end(ap);
p = popen(cmd, "r"); p = popen(cmd, "r");
...@@ -30,12 +28,12 @@ lines_from_cmd(const void *ctx, const char *format, ...) ...@@ -30,12 +28,12 @@ lines_from_cmd(const void *ctx, const char *format, ...)
err(1, "Executing '%s'", cmd); err(1, "Executing '%s'", cmd);
/* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */ /* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */
rbuf_init(&in, fileno(p), talloc_array(ctx, char, 4096), 4096); rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0);
if (!rbuf_read_str(&in, 0, do_talloc_realloc) && errno) if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
err(1, "Reading from '%s'", cmd); err(1, "Reading from '%s'", cmd);
pclose(p); pclose(p);
return strsplit(ctx, in.buf, "\n"); return tal_strsplit(ctx, in.buf, "\n", STR_EMPTY_OK);
} }
/* Be careful about trying to compile over running programs (parallel make). /* Be careful about trying to compile over running programs (parallel make).
...@@ -47,8 +45,7 @@ char *compile_info(const void *ctx, const char *dir) ...@@ -47,8 +45,7 @@ char *compile_info(const void *ctx, const char *dir)
int fd; int fd;
/* Copy it to a file with proper .c suffix. */ /* Copy it to a file with proper .c suffix. */
info = talloc_grab_file(ctx, talloc_asprintf(ctx, "%s/_info", dir), info = tal_grab_file(ctx, tal_fmt(ctx, "%s/_info", dir), &len);
&len);
if (!info) if (!info)
return NULL; return NULL;
...@@ -79,13 +76,13 @@ static char **get_one_deps(const void *ctx, const char *dir, const char *style, ...@@ -79,13 +76,13 @@ static char **get_one_deps(const void *ctx, const char *dir, const char *style,
if (!infofile) if (!infofile)
return NULL; return NULL;
cmd = talloc_asprintf(ctx, "%s %s", infofile, style); cmd = tal_fmt(ctx, "%s %s", infofile, style);
deps = lines_from_cmd(cmd, "%s", cmd); deps = lines_from_cmd(cmd, "%s", cmd);
if (!deps) { if (!deps) {
/* You must understand depends, maybe not testdepends. */ /* You must understand depends, maybe not testdepends. */
if (streq(style, "depends")) if (streq(style, "depends"))
err(1, "Could not run '%s'", cmd); err(1, "Could not run '%s'", cmd);
deps = talloc(ctx, char *); deps = tal(ctx, char *);
deps[0] = NULL; deps[0] = NULL;
} }
return deps; return deps;
...@@ -95,7 +92,7 @@ static char **get_one_deps(const void *ctx, const char *dir, const char *style, ...@@ -95,7 +92,7 @@ static char **get_one_deps(const void *ctx, const char *dir, const char *style,
static char *replace(const void *ctx, const char *src, static char *replace(const void *ctx, const char *src,
const char *from, const char *to) const char *from, const char *to)
{ {
char *ret = talloc_strdup(ctx, ""); char *ret = tal_strdup(ctx, "");
unsigned int rlen, len, add; unsigned int rlen, len, add;
rlen = len = 0; rlen = len = 0;
...@@ -106,7 +103,7 @@ static char *replace(const void *ctx, const char *src, ...@@ -106,7 +103,7 @@ static char *replace(const void *ctx, const char *src,
else else
add = next - (src+len); add = next - (src+len);
ret = talloc_realloc(ctx, ret, char, rlen + add + strlen(to)+1); tal_resize(&ret, rlen + add + strlen(to)+1);
memcpy(ret+rlen, src+len, add); memcpy(ret+rlen, src+len, add);
if (!next) if (!next)
return ret; return ret;
...@@ -128,15 +125,16 @@ static char **get_one_safe_deps(const void *ctx, ...@@ -128,15 +125,16 @@ static char **get_one_safe_deps(const void *ctx,
unsigned int i, n; unsigned int i, n;
bool correct_style = false; bool correct_style = false;
fname = talloc_asprintf(ctx, "%s/_info", dir); fname = tal_fmt(ctx, "%s/_info", dir);
raw = talloc_grab_file(fname, fname, NULL); raw = tal_grab_file(fname, fname, NULL);
if (!raw) if (!raw)
errx(1, "Could not open %s", fname); errx(1, "Could not open %s", fname);
/* Replace \n by actual line breaks, and split it. */ /* Replace \n by actual line breaks, and split it. */
lines = strsplit(raw, replace(raw, raw, "\\n", "\n"), "\n"); lines = tal_strsplit(raw, replace(raw, raw, "\\n", "\n"), "\n",
STR_EMPTY_OK);
deps = talloc_array(ctx, char *, talloc_array_length(lines)); deps = tal_arr(ctx, char *, tal_count(lines));
for (n = i = 0; lines[i]; i++) { for (n = i = 0; lines[i]; i++) {
char *str; char *str;
...@@ -167,13 +165,14 @@ static char **get_one_safe_deps(const void *ctx, ...@@ -167,13 +165,14 @@ static char **get_one_safe_deps(const void *ctx,
len = strspn(str, "/abcdefghijklmnopqrstuvxwyz12345678980_"); len = strspn(str, "/abcdefghijklmnopqrstuvxwyz12345678980_");
if (len == 5) if (len == 5)
continue; continue;
deps[n++] = talloc_strndup(deps, str, len); deps[n++] = tal_strndup(deps, str, len);
} }
deps[n] = NULL; deps[n] = NULL;
talloc_free(fname); tal_free(fname);
/* Make sure talloc_array_length() works */ /* Make sure tal_array_length() works */
return talloc_realloc(NULL, deps, char *, n + 1); tal_resize(&deps, n + 1);
return deps;
} }
static bool have_dep(char **deps, const char *dep) static bool have_dep(char **deps, const char *dep)
...@@ -199,7 +198,7 @@ get_all_deps(const void *ctx, const char *dir, const char *style, ...@@ -199,7 +198,7 @@ get_all_deps(const void *ctx, const char *dir, const char *style,
unsigned int i; unsigned int i;
deps = get_one(ctx, dir, style, get_info); deps = get_one(ctx, dir, style, get_info);
for (i = 0; i < talloc_array_length(deps)-1; i++) { for (i = 0; i < tal_count(deps)-1; i++) {
char **newdeps; char **newdeps;
unsigned int j; unsigned int j;
char *subdir; char *subdir;
...@@ -207,19 +206,18 @@ get_all_deps(const void *ctx, const char *dir, const char *style, ...@@ -207,19 +206,18 @@ get_all_deps(const void *ctx, const char *dir, const char *style,
if (!strstarts(deps[i], "ccan/")) if (!strstarts(deps[i], "ccan/"))
continue; continue;
subdir = talloc_asprintf(ctx, "%s/%s", subdir = tal_fmt(ctx, "%s/%s", find_ccan_dir(dir), deps[i]);
find_ccan_dir(dir), deps[i]);
newdeps = get_one(ctx, subdir, "depends", get_info); newdeps = get_one(ctx, subdir, "depends", get_info);
/* Should be short, so brute-force out dups. */ /* Should be short, so brute-force out dups. */
for (j = 0; j < talloc_array_length(newdeps)-1; j++) { for (j = 0; j < tal_count(newdeps)-1; j++) {
unsigned int num; unsigned int num;
if (have_dep(deps, newdeps[j])) if (have_dep(deps, newdeps[j]))
continue; continue;
num = talloc_array_length(deps)-1; num = tal_count(deps)-1;
deps = talloc_realloc(NULL, deps, char *, num + 2); tal_resize(&deps, num + 2);
deps[num] = newdeps[j]; deps[num] = newdeps[j];
deps[num+1] = NULL; deps[num+1] = NULL;
} }
...@@ -233,12 +231,11 @@ static char **get_one_libs(const void *ctx, const char *dir, ...@@ -233,12 +231,11 @@ static char **get_one_libs(const void *ctx, const char *dir,
{ {
char *cmd, **lines; char *cmd, **lines;
cmd = talloc_asprintf(ctx, "%s libs", get_info(ctx, dir)); cmd = tal_fmt(ctx, "%s libs", get_info(ctx, dir));
lines = lines_from_cmd(cmd, "%s", cmd); lines = lines_from_cmd(cmd, "%s", cmd);
/* Strip final NULL. */ /* Strip final NULL. */
if (lines) if (lines)
lines = talloc_realloc(NULL, lines, char *, tal_resize(&lines, tal_count(lines)-1);
talloc_array_length(lines)-1);
return lines; return lines;
} }
...@@ -247,13 +244,13 @@ static char **add_deps(char **deps1, char **deps2) ...@@ -247,13 +244,13 @@ static char **add_deps(char **deps1, char **deps2)
{ {
unsigned int i, len; unsigned int i, len;
len = talloc_array_length(deps1); len = tal_count(deps1);
for (i = 0; deps2[i]; i++) { for (i = 0; deps2[i]; i++) {
if (have_dep(deps1, deps2[i])) if (have_dep(deps1, deps2[i]))
continue; continue;
deps1 = talloc_realloc(NULL, deps1, char *, len + 1); tal_resize(&deps1, len + 1);
deps1[len-1] = talloc_steal(deps1, deps2[i]); deps1[len-1] = tal_strdup(deps1, deps2[i]);
deps1[len++] = NULL; deps1[len++] = NULL;
} }
return deps1; return deps1;
...@@ -266,7 +263,7 @@ char **get_libs(const void *ctx, const char *dir, const char *style, ...@@ -266,7 +263,7 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
unsigned int i, len; unsigned int i, len;
libs = get_one_libs(ctx, dir, get_info); libs = get_one_libs(ctx, dir, get_info);
len = talloc_array_length(libs); len = tal_count(libs);
if (style) { if (style) {
deps = get_deps(ctx, dir, style, true, get_info); deps = get_deps(ctx, dir, style, true, get_info);
...@@ -282,12 +279,12 @@ char **get_libs(const void *ctx, const char *dir, const char *style, ...@@ -282,12 +279,12 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
if (!strstarts(deps[i], "ccan/")) if (!strstarts(deps[i], "ccan/"))
continue; continue;
subdir = talloc_asprintf(ctx, "%s/%s", subdir = tal_fmt(ctx, "%s/%s",
find_ccan_dir(dir), deps[i]); find_ccan_dir(dir), deps[i]);
newlibs = get_one_libs(ctx, subdir, get_info); newlibs = get_one_libs(ctx, subdir, get_info);
newlen = talloc_array_length(newlibs); newlen = tal_count(newlibs);
libs = talloc_realloc(ctx, libs, char *, len + newlen); tal_resize(&libs, len + newlen);
memcpy(&libs[len], newlibs, memcpy(&libs[len], newlibs,
sizeof(newlibs[0])*newlen); sizeof(newlibs[0])*newlen);
len += newlen; len += newlen;
...@@ -295,7 +292,7 @@ char **get_libs(const void *ctx, const char *dir, const char *style, ...@@ -295,7 +292,7 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
} }
/* Append NULL entry. */ /* Append NULL entry. */
libs = talloc_realloc(ctx, libs, char *, len + 1); tal_resize(&libs, len + 1);
libs[len] = NULL; libs[len] = NULL;
return libs; return libs;
} }
...@@ -308,7 +305,7 @@ static char **uniquify_deps(char **deps) ...@@ -308,7 +305,7 @@ static char **uniquify_deps(char **deps)
if (!deps) if (!deps)
return NULL; return NULL;
num = talloc_array_length(deps) - 1; num = tal_count(deps) - 1;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
for (j = i + 1; j < num; j++) { for (j = i + 1; j < num; j++) {
if (streq(deps[i], deps[j])) { if (streq(deps[i], deps[j])) {
...@@ -319,8 +316,9 @@ static char **uniquify_deps(char **deps) ...@@ -319,8 +316,9 @@ static char **uniquify_deps(char **deps)
} }
} }
deps[num] = NULL; deps[num] = NULL;
/* Make sure talloc_array_length() works */ /* Make sure tal_count() works */
return talloc_realloc(NULL, deps, char *, num + 1); tal_resize(&deps, num + 1);
return deps;
} }
char **get_deps(const void *ctx, const char *dir, const char *style, char **get_deps(const void *ctx, const char *dir, const char *style,
......
/* This merely extracts, doesn't do XML or anything. */ /* This merely extracts, doesn't do XML or anything. */
#include <ccan/talloc/talloc.h> #include <ccan/take/take.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -22,24 +21,24 @@ static char **grab_doc(char **lines, unsigned int **linemap, ...@@ -22,24 +21,24 @@ static char **grab_doc(char **lines, unsigned int **linemap,
unsigned int i, num; unsigned int i, num;
bool printing = false; bool printing = false;
ret = talloc_array(NULL, char *, talloc_array_length(lines)); ret = tal_arr(NULL, char *, tal_count(lines));
*linemap = talloc_array(ret, unsigned int, talloc_array_length(lines)); *linemap = tal_arr(ret, unsigned int, tal_count(lines));
num = 0; num = 0;
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
if (streq(lines[i], "/**")) { if (streq(lines[i], "/**")) {
printing = true; printing = true;
if (num != 0) { if (num != 0) {
ret[num-1] = talloc_append_string(ret[num-1], ret[num-1] = tal_strcat(NULL,
"\n"); take(ret[num-1]), "\n");
} }
} else if (streq(lines[i], " */")) } else if (streq(lines[i], " */"))
printing = false; printing = false;
else if (printing) { else if (printing) {
if (strstarts(lines[i], " * ")) if (strstarts(lines[i], " * "))
ret[num++] = talloc_strdup(ret, lines[i]+3); ret[num++] = tal_strdup(ret, lines[i]+3);
else if (strstarts(lines[i], " *")) else if (strstarts(lines[i], " *"))
ret[num++] = talloc_strdup(ret, lines[i]+2); ret[num++] = tal_strdup(ret, lines[i]+2);
else { else {
/* Weird, malformed? */ /* Weird, malformed? */
static bool warned; static bool warned;
...@@ -49,7 +48,7 @@ static char **grab_doc(char **lines, unsigned int **linemap, ...@@ -49,7 +48,7 @@ static char **grab_doc(char **lines, unsigned int **linemap,
file, i+1); file, i+1);
warned++; warned++;
} }
ret[num++] = talloc_strdup(ret, lines[i]); ret[num++] = tal_strdup(ret, lines[i]);
if (strstr(lines[i], "*/")) if (strstr(lines[i], "*/"))
printing = false; printing = false;
} }
...@@ -70,7 +69,7 @@ static char *is_section(const void *ctx, const char *line, char **value) ...@@ -70,7 +69,7 @@ static char *is_section(const void *ctx, const char *line, char **value)
char *secname; char *secname;
/* Any number of upper case words separated by spaces, ending in : */ /* Any number of upper case words separated by spaces, ending in : */
if (!strreg(ctx, line, if (!tal_strreg(ctx, line,
"^([A-Z][a-zA-Z0-9_]*( [A-Z][a-zA-Z0-9_]*)*):[ \t\n]*(.*)", "^([A-Z][a-zA-Z0-9_]*( [A-Z][a-zA-Z0-9_]*)*):[ \t\n]*(.*)",
&secname, NULL, value)) &secname, NULL, value))
return NULL; return NULL;
...@@ -117,17 +116,17 @@ static struct doc_section *new_section(struct list_head *list, ...@@ -117,17 +116,17 @@ static struct doc_section *new_section(struct list_head *list,
d = list_tail(list, struct doc_section, list); d = list_tail(list, struct doc_section, list);
if (d && empty_section(d)) { if (d && empty_section(d)) {
list_del(&d->list); list_del(&d->list);
talloc_free(d); tal_free(d);
} }
d = talloc(list, struct doc_section); d = tal(list, struct doc_section);
d->function = function; d->function = function;
lowertype = talloc_size(d, strlen(type) + 1); lowertype = tal_arr(d, char, strlen(type) + 1);
/* Canonicalize type to lower case. */ /* Canonicalize type to lower case. */
for (i = 0; i < strlen(type)+1; i++) for (i = 0; i < strlen(type)+1; i++)
lowertype[i] = tolower(type[i]); lowertype[i] = tolower(type[i]);
d->type = lowertype; d->type = lowertype;
d->lines = NULL; d->lines = tal_arr(d, char *, 0);
d->num_lines = 0; d->num_lines = 0;
d->srcline = srcline; d->srcline = srcline;
...@@ -137,9 +136,9 @@ static struct doc_section *new_section(struct list_head *list, ...@@ -137,9 +136,9 @@ static struct doc_section *new_section(struct list_head *list,
static void add_line(struct doc_section *curr, const char *line) static void add_line(struct doc_section *curr, const char *line)
{ {
curr->lines = talloc_realloc(curr, curr->lines, char *, char *myline = tal_strdup(curr->lines, line);
curr->num_lines+1); tal_expand(&curr->lines, &myline, 1);
curr->lines[curr->num_lines++] = talloc_strdup(curr->lines, line); curr->num_lines++;
} }
/* We convert tabs to spaces here. */ /* We convert tabs to spaces here. */
...@@ -149,8 +148,8 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline) ...@@ -149,8 +148,8 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline)
char *line; char *line;
/* Worst-case alloc: 8 spaces per tab. */ /* Worst-case alloc: 8 spaces per tab. */
line = talloc_array(curr, char, strlen(rawline) + line = tal_arr(curr, char, strlen(rawline) +
strcount(rawline, "\t") * 7 + 1); strcount(rawline, "\t") * 7 + 1);
len = 0; len = 0;
/* We keep track of the *effective* offset of i. */ /* We keep track of the *effective* offset of i. */
...@@ -170,7 +169,7 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline) ...@@ -170,7 +169,7 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline)
line[len] = '\0'; line[len] = '\0';
add_line(curr, line + off); add_line(curr, line + off);
talloc_free(line); tal_free(line);
} }
/* Not very efficient: we could track prefix length while doing /* Not very efficient: we could track prefix length while doing
...@@ -216,7 +215,7 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file) ...@@ -216,7 +215,7 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file)
unsigned int i; unsigned int i;
struct list_head *list; struct list_head *list;
list = talloc(NULL, struct list_head); list = tal(NULL, struct list_head);
list_head_init(list); list_head_init(list);
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
...@@ -225,7 +224,7 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file) ...@@ -225,7 +224,7 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file)
funclen = is_summary_line(lines[i]); funclen = is_summary_line(lines[i]);
if (funclen) { if (funclen) {
function = talloc_strndup(list, lines[i], funclen); function = tal_strndup(list, lines[i], funclen);
curr = new_section(list, function, "summary", curr = new_section(list, function, "summary",
linemap[i]); linemap[i]);
add_line(curr, lines[i] + funclen + 3); add_line(curr, lines[i] + funclen + 3);
...@@ -246,6 +245,6 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file) ...@@ -246,6 +245,6 @@ struct list_head *extract_doc_sections(char **rawlines, const char *file)
list_for_each(list, curr, list) list_for_each(list, curr, list)
trim_lines(curr); trim_lines(curr);
talloc_free(lines); tal_free(lines);
return list; return list;
} }
/* This merely extracts, doesn't do XML or anything. */ /* This merely extracts, doesn't do XML or anything. */
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/talloc/talloc.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include "tools.h" #include "tools.h"
#include <string.h> #include <string.h>
...@@ -47,15 +45,15 @@ int main(int argc, char *argv[]) ...@@ -47,15 +45,15 @@ int main(int argc, char *argv[])
struct list_head *list; struct list_head *list;
struct doc_section *d; struct doc_section *d;
file = talloc_grab_file(NULL, argv[i], NULL); file = tal_grab_file(NULL, argv[i], NULL);
if (!file) if (!file)
err(1, "Reading file %s", argv[i]); err(1, "Reading file %s", argv[i]);
lines = strsplit(file, file, "\n"); lines = tal_strsplit(file, file, "\n", STR_EMPTY_OK);
list = extract_doc_sections(lines, argv[i]); list = extract_doc_sections(lines, argv[i]);
if (list_empty(list)) if (list_empty(list))
errx(1, "No documentation in file %s", argv[i]); errx(1, "No documentation in file %s", argv[i]);
talloc_free(file); tal_free(file);
if (streq(type, "functions")) { if (streq(type, "functions")) {
const char *last = NULL; const char *last = NULL;
...@@ -84,7 +82,7 @@ int main(int argc, char *argv[]) ...@@ -84,7 +82,7 @@ int main(int argc, char *argv[])
printf("%s\n", d->lines[j]); printf("%s\n", d->lines[j]);
} }
} }
talloc_free(list); tal_free(list);
} }
return 0; return 0;
} }
#include "config.h" #include "config.h"
#include "manifest.h" #include "manifest.h"
#include "tools.h" #include "tools.h"
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h> #include <ccan/tal/link/link.h>
#include <ccan/talloc_link/talloc_link.h>
#include <ccan/hash/hash.h> #include <ccan/hash/hash.h>
#include <ccan/htable/htable_type.h> #include <ccan/htable/htable_type.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
...@@ -44,7 +42,7 @@ static struct htable_manifest *manifests; ...@@ -44,7 +42,7 @@ static struct htable_manifest *manifests;
const char *get_ccan_file_contents(struct ccan_file *f) const char *get_ccan_file_contents(struct ccan_file *f)
{ {
if (!f->contents) { if (!f->contents) {
f->contents = talloc_grab_file(f, f->fullname, f->contents = tal_grab_file(f, f->fullname,
&f->contents_size); &f->contents_size);
if (!f->contents) if (!f->contents)
err(1, "Reading file %s", f->fullname); err(1, "Reading file %s", f->fullname);
...@@ -55,10 +53,11 @@ const char *get_ccan_file_contents(struct ccan_file *f) ...@@ -55,10 +53,11 @@ const char *get_ccan_file_contents(struct ccan_file *f)
char **get_ccan_file_lines(struct ccan_file *f) char **get_ccan_file_lines(struct ccan_file *f)
{ {
if (!f->lines) if (!f->lines)
f->lines = strsplit(f, get_ccan_file_contents(f), "\n"); f->lines = tal_strsplit(f, get_ccan_file_contents(f), "\n",
STR_EMPTY_OK);
/* FIXME: is f->num_lines necessary? */ /* FIXME: is f->num_lines necessary? */
f->num_lines = talloc_array_length(f->lines) - 1; f->num_lines = tal_count(f->lines) - 1;
return f->lines; return f->lines;
} }
...@@ -69,14 +68,14 @@ struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name) ...@@ -69,14 +68,14 @@ struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name)
assert(dir[0] == '/'); assert(dir[0] == '/');
f = talloc(ctx, struct ccan_file); f = tal(ctx, struct ccan_file);
f->lines = NULL; f->lines = NULL;
f->line_info = NULL; f->line_info = NULL;
f->doc_sections = NULL; f->doc_sections = NULL;
for (i = 0; i < ARRAY_SIZE(f->compiled); i++) for (i = 0; i < ARRAY_SIZE(f->compiled); i++)
f->compiled[i] = NULL; f->compiled[i] = NULL;
f->name = talloc_steal(f, name); f->name = tal_steal(f, name);
f->fullname = talloc_asprintf(f, "%s/%s", dir, f->name); f->fullname = tal_fmt(f, "%s/%s", dir, f->name);
f->contents = NULL; f->contents = NULL;
f->simplified = NULL; f->simplified = NULL;
return f; return f;
...@@ -86,7 +85,7 @@ static void add_files(struct manifest *m, const char *dir) ...@@ -86,7 +85,7 @@ static void add_files(struct manifest *m, const char *dir)
{ {
DIR *d; DIR *d;
struct dirent *ent; struct dirent *ent;
char **subs = NULL; char **subs = tal_arr(m, char *, 0);
if (dir[0]) if (dir[0])
d = opendir(dir); d = opendir(dir);
...@@ -105,19 +104,18 @@ static void add_files(struct manifest *m, const char *dir) ...@@ -105,19 +104,18 @@ static void add_files(struct manifest *m, const char *dir)
continue; continue;
f = new_ccan_file(m, m->dir, f = new_ccan_file(m, m->dir,
talloc_asprintf(m, "%s%s", tal_fmt(m, "%s%s", dir, ent->d_name));
dir, ent->d_name));
if (lstat(f->name, &st) != 0) if (lstat(f->name, &st) != 0)
err(1, "lstat %s", f->name); err(1, "lstat %s", f->name);
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
size_t len = talloc_array_length(subs); size_t len = tal_count(subs);
subs = talloc_realloc(m, subs, char *, len+1); tal_resize(&subs, len+1);
subs[len] = talloc_append_string(f->name, "/"); subs[len] = tal_strcat(subs, f->name, "/");
continue; continue;
} }
if (!S_ISREG(st.st_mode)) { if (!S_ISREG(st.st_mode)) {
talloc_free(f); tal_free(f);
continue; continue;
} }
...@@ -164,10 +162,10 @@ static void add_files(struct manifest *m, const char *dir) ...@@ -164,10 +162,10 @@ static void add_files(struct manifest *m, const char *dir)
&& list_empty(&m->h_files)) && list_empty(&m->h_files))
errx(1, "No _info, C or H files found here!"); errx(1, "No _info, C or H files found here!");
for (i = 0; i < talloc_array_length(subs); i++) for (i = 0; i < tal_count(subs); i++)
add_files(m, subs[i]); add_files(m, subs[i]);
} }
talloc_free(subs); tal_free(subs);
} }
static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b, static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b,
...@@ -178,20 +176,18 @@ static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b, ...@@ -178,20 +176,18 @@ static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b,
static void sort_files(struct list_head *list) static void sort_files(struct list_head *list)
{ {
struct ccan_file **files = NULL, *f; struct ccan_file **files = tal_arr(NULL, struct ccan_file *, 0), *f;
unsigned int i, num; unsigned int i;
num = 0;
while ((f = list_top(list, struct ccan_file, list)) != NULL) { while ((f = list_top(list, struct ccan_file, list)) != NULL) {
files = talloc_realloc(NULL, files, struct ccan_file *, num+1); tal_expand(&files, &f, 1);
files[num++] = f;
list_del(&f->list); list_del(&f->list);
} }
asort(files, num, cmp_names, NULL); asort(files, tal_count(files), cmp_names, NULL);
for (i = 0; i < num; i++) for (i = 0; i < tal_count(files); i++)
list_add_tail(list, &files[i]->list); list_add_tail(list, &files[i]->list);
talloc_free(files); tal_free(files);
} }
struct manifest *get_manifest(const void *ctx, const char *dir) struct manifest *get_manifest(const void *ctx, const char *dir)
...@@ -202,29 +198,28 @@ struct manifest *get_manifest(const void *ctx, const char *dir) ...@@ -202,29 +198,28 @@ struct manifest *get_manifest(const void *ctx, const char *dir)
struct list_head *list; struct list_head *list;
if (!manifests) { if (!manifests) {
manifests = talloc(NULL, struct htable_manifest); manifests = tal(NULL, struct htable_manifest);
htable_manifest_init(manifests); htable_manifest_init(manifests);
} }
olddir = talloc_getcwd(NULL); olddir = tal_getcwd(NULL);
if (!olddir) if (!olddir)
err(1, "Getting current directory"); err(1, "Getting current directory");
if (chdir(dir) != 0) if (chdir(dir) != 0)
err(1, "Failed to chdir to %s", dir); err(1, "Failed to chdir to %s", dir);
canon_dir = talloc_getcwd(olddir); canon_dir = tal_getcwd(olddir);
if (!canon_dir) if (!canon_dir)
err(1, "Getting current directory"); err(1, "Getting current directory");
m = htable_manifest_get(manifests, canon_dir); m = htable_manifest_get(manifests, canon_dir);
if (m) if (m)
goto done; goto done;
m = tal_linkable(tal(NULL, struct manifest));
m = talloc_linked(ctx, talloc(NULL, struct manifest));
m->info_file = NULL; m->info_file = NULL;
m->compiled[COMPILE_NORMAL] = m->compiled[COMPILE_NOFEAT] = NULL; m->compiled[COMPILE_NORMAL] = m->compiled[COMPILE_NOFEAT] = NULL;
m->dir = talloc_steal(m, canon_dir); m->dir = tal_steal(m, canon_dir);
list_head_init(&m->c_files); list_head_init(&m->c_files);
list_head_init(&m->h_files); list_head_init(&m->h_files);
list_head_init(&m->api_tests); list_head_init(&m->api_tests);
...@@ -259,12 +254,12 @@ struct manifest *get_manifest(const void *ctx, const char *dir) ...@@ -259,12 +254,12 @@ struct manifest *get_manifest(const void *ctx, const char *dir)
&m->compile_fail_tests) &m->compile_fail_tests)
sort_files(list); sort_files(list);
htable_manifest_add(manifests, m); htable_manifest_add(manifests, tal_link(manifests, m));
done: done:
if (chdir(olddir) != 0) if (chdir(olddir) != 0)
err(1, "Returning to original directory '%s'", olddir); err(1, "Returning to original directory '%s'", olddir);
talloc_free(olddir); tal_free(olddir);
return m; return m;
} }
...@@ -83,7 +83,7 @@ struct ccan_file { ...@@ -83,7 +83,7 @@ struct ccan_file {
char *simplified; char *simplified;
}; };
/* A new ccan_file, with the given name (talloc_steal onto returned value). */ /* A new ccan_file, with the given name (tal_steal onto returned value). */
struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name); struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
/* Use this rather than accessing f->contents directly: loads on demand. */ /* Use this rather than accessing f->contents directly: loads on demand. */
......
...@@ -10,9 +10,8 @@ ...@@ -10,9 +10,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "ccan/str/str.h" #include "ccan/str/str.h"
#include "ccan/str_talloc/str_talloc.h" #include "ccan/take/take.h"
#include "ccan/rbuf/rbuf.h" #include "ccan/rbuf/rbuf.h"
#include "ccan/talloc/talloc.h"
#include "ccan/err/err.h" #include "ccan/err/err.h"
#include "tools.h" #include "tools.h"
...@@ -41,20 +40,18 @@ static char **get_dir(const char *dir) ...@@ -41,20 +40,18 @@ static char **get_dir(const char *dir)
{ {
DIR *d; DIR *d;
struct dirent *ent; struct dirent *ent;
char **names = NULL; char **names = tal_arr(NULL, char *, 0), *n;
unsigned int size = 0;
d = opendir(dir); d = opendir(dir);
if (!d) if (!d)
return NULL; return NULL;
while ((ent = readdir(d)) != NULL) { while ((ent = readdir(d)) != NULL) {
names = talloc_realloc(dir, names, char *, size + 2); n = tal_fmt(names, "%s/%s", dir, ent->d_name);
names[size++] tal_expand(&names, &n, 1);
= talloc_asprintf(names, "%s/%s", dir, ent->d_name);
} }
/* FIXME: if the loop doesn't run at least once, we'll segfault here */ n = NULL;
names[size] = NULL; tal_expand(&names, &n, 1);
closedir(d); closedir(d);
return names; return names;
} }
...@@ -86,9 +83,9 @@ static void add_replace(struct replace **repl, const char *str) ...@@ -86,9 +83,9 @@ static void add_replace(struct replace **repl, const char *str)
if (streq(i->string, str)) if (streq(i->string, str))
return; return;
new = talloc(*repl, struct replace); new = tal(*repl, struct replace);
new->next = *repl; new->next = *repl;
new->string = talloc_strdup(new, str); new->string = tal_strdup(new, str);
*repl = new; *repl = new;
} }
...@@ -97,9 +94,9 @@ static void add_replace_tok(struct replace **repl, const char *s) ...@@ -97,9 +94,9 @@ static void add_replace_tok(struct replace **repl, const char *s)
struct replace *new; struct replace *new;
unsigned int len = strspn(s, IDENT_CHARS); unsigned int len = strspn(s, IDENT_CHARS);
new = talloc(*repl, struct replace); new = tal(*repl, struct replace);
new->next = *repl; new->next = *repl;
new->string = talloc_strndup(new, s, len); new->string = tal_strndup(new, s, len);
*repl = new; *repl = new;
} }
...@@ -124,7 +121,7 @@ static void look_for_macros(char *contents, struct replace **repl) ...@@ -124,7 +121,7 @@ static void look_for_macros(char *contents, struct replace **repl)
len = strspn(p, IDENT_CHARS); len = strspn(p, IDENT_CHARS);
if (len) { if (len) {
char *s; char *s;
s = talloc_strndup(contents, p, len); s = tal_strndup(contents, p, len);
/* Don't wrap idempotent wrappers */ /* Don't wrap idempotent wrappers */
if (!strstarts(s, "CCAN_")) { if (!strstarts(s, "CCAN_")) {
verbose("Found %s\n", s); verbose("Found %s\n", s);
...@@ -164,7 +161,7 @@ static char *get_statement(const void *ctx, char **p) ...@@ -164,7 +161,7 @@ static char *get_statement(const void *ctx, char **p)
{ {
unsigned brackets = 0; unsigned brackets = 0;
bool seen_brackets = false; bool seen_brackets = false;
char *answer = talloc_strdup(ctx, ""); char *answer = tal_strdup(ctx, "");
for (;;) { for (;;) {
if ((*p)[0] == '/' && (*p)[1] == '/') if ((*p)[0] == '/' && (*p)[1] == '/')
...@@ -190,10 +187,7 @@ static char *get_statement(const void *ctx, char **p) ...@@ -190,10 +187,7 @@ static char *get_statement(const void *ctx, char **p)
brackets--; brackets--;
if (answer[0] != '\0' || c != ' ') { if (answer[0] != '\0' || c != ' ') {
answer = talloc_realloc(NULL, answer, char, tal_append_fmt(&answer, "%c", c);
strlen(answer) + 2);
answer[strlen(answer)+1] = '\0';
answer[strlen(answer)] = c;
} }
if (c == '}' && seen_brackets && brackets == 0) { if (c == '}' && seen_brackets && brackets == 0) {
(*p)++; (*p)++;
...@@ -261,8 +255,8 @@ static void analyze_headers(const char *dir, struct replace **repl) ...@@ -261,8 +255,8 @@ static void analyze_headers(const char *dir, struct replace **repl)
char *hdr, *contents; char *hdr, *contents;
/* Get hold of header, assume that's it. */ /* Get hold of header, assume that's it. */
hdr = talloc_asprintf(dir, "%s/%s.h", dir, talloc_basename(dir, dir)); hdr = tal_fmt(dir, "%s/%s.h", dir, tal_basename(dir, dir));
contents = talloc_grab_file(dir, hdr, NULL); contents = tal_grab_file(dir, hdr, NULL);
if (!contents) if (!contents)
err(1, "Reading %s", hdr); err(1, "Reading %s", hdr);
...@@ -279,7 +273,7 @@ static void analyze_headers(const char *dir, struct replace **repl) ...@@ -279,7 +273,7 @@ static void analyze_headers(const char *dir, struct replace **repl)
static void write_replacement_file(const char *dir, struct replace **repl) static void write_replacement_file(const char *dir, struct replace **repl)
{ {
char *replname = talloc_asprintf(dir, "%s/.namespacize", dir); char *replname = tal_fmt(dir, "%s/.namespacize", dir);
int fd; int fd;
struct replace *r; struct replace *r;
...@@ -305,10 +299,9 @@ static void write_replacement_file(const char *dir, struct replace **repl) ...@@ -305,10 +299,9 @@ static void write_replacement_file(const char *dir, struct replace **repl)
close(fd); close(fd);
} }
static int unlink_destroy(char *name) static void unlink_destroy(char *name)
{ {
unlink(name); unlink(name);
return 0;
} }
static char *find_word(char *f, const char *str) static char *find_word(char *f, const char *str)
...@@ -338,7 +331,7 @@ static const char *rewrite_file(const char *filename, ...@@ -338,7 +331,7 @@ static const char *rewrite_file(const char *filename,
int fd; int fd;
verbose("Rewriting %s\n", filename); verbose("Rewriting %s\n", filename);
file = talloc_grab_file(filename, filename, NULL); file = tal_grab_file(filename, filename, NULL);
if (!file) if (!file)
err(1, "Reading file %s", filename); err(1, "Reading file %s", filename);
...@@ -347,7 +340,7 @@ static const char *rewrite_file(const char *filename, ...@@ -347,7 +340,7 @@ static const char *rewrite_file(const char *filename,
while ((p = find_word(file, repl->string)) != NULL) { while ((p = find_word(file, repl->string)) != NULL) {
unsigned int off; unsigned int off;
char *new = talloc_array(file, char, strlen(file)+6); char *new = tal_arr(file, char, strlen(file)+6);
off = p - file; off = p - file;
memcpy(new, file, off); memcpy(new, file, off);
...@@ -361,13 +354,12 @@ static const char *rewrite_file(const char *filename, ...@@ -361,13 +354,12 @@ static const char *rewrite_file(const char *filename,
} }
/* If we exit for some reason, we want this erased. */ /* If we exit for some reason, we want this erased. */
newname = talloc_asprintf(talloc_autofree_context(), "%s.tmp", newname = tal_fmt(autofree(), "%s.tmp", filename);
filename);
fd = open(newname, O_WRONLY|O_CREAT|O_EXCL, 0644); fd = open(newname, O_WRONLY|O_CREAT|O_EXCL, 0644);
if (fd < 0) if (fd < 0)
err(1, "Creating %s", newname); err(1, "Creating %s", newname);
talloc_set_destructor(newname, unlink_destroy); tal_add_destructor(newname, unlink_destroy);
if (write(fd, file, strlen(file)) != strlen(file)) { if (write(fd, file, strlen(file)) != strlen(file)) {
if (errno == 0) if (errno == 0)
errx(1, "Short write to %s: disk full?", newname); errx(1, "Short write to %s: disk full?", newname);
...@@ -394,7 +386,7 @@ static void setup_adjust_files(const char *dir, ...@@ -394,7 +386,7 @@ static void setup_adjust_files(const char *dir,
if (strends(*files, "/test")) if (strends(*files, "/test"))
setup_adjust_files(*files, repl, adj); setup_adjust_files(*files, repl, adj);
else if (strends(*files, ".c") || strends(*files, ".h")) { else if (strends(*files, ".c") || strends(*files, ".h")) {
struct adjusted *a = talloc(dir, struct adjusted); struct adjusted *a = tal(dir, struct adjusted);
a->next = *adj; a->next = *adj;
a->file = *files; a->file = *files;
a->tmpfile = rewrite_file(a->file, repl); a->tmpfile = rewrite_file(a->file, repl);
...@@ -421,7 +413,7 @@ static void convert_dir(const char *dir) ...@@ -421,7 +413,7 @@ static void convert_dir(const char *dir)
struct adjusted *adj = NULL; struct adjusted *adj = NULL;
/* Remove any ugly trailing slashes. */ /* Remove any ugly trailing slashes. */
name = talloc_strdup(NULL, dir); name = tal_strdup(NULL, dir);
while (strends(name, "/")) while (strends(name, "/"))
name[strlen(name)-1] = '\0'; name[strlen(name)-1] = '\0';
...@@ -429,31 +421,31 @@ static void convert_dir(const char *dir) ...@@ -429,31 +421,31 @@ static void convert_dir(const char *dir)
write_replacement_file(name, &replace); write_replacement_file(name, &replace);
setup_adjust_files(name, replace, &adj); setup_adjust_files(name, replace, &adj);
rename_files(adj); rename_files(adj);
talloc_free(name); tal_free(name);
talloc_free(replace); tal_free(replace);
} }
static struct replace *read_replacement_file(const char *depdir) static struct replace *read_replacement_file(const char *depdir)
{ {
struct replace *repl = NULL; struct replace *repl = NULL;
char *replname = talloc_asprintf(depdir, "%s/.namespacize", depdir); char *replname = tal_fmt(depdir, "%s/.namespacize", depdir);
char *file, **line; char *file, **line;
file = talloc_grab_file(replname, replname, NULL); file = tal_grab_file(replname, replname, NULL);
if (!file) { if (!file) {
if (errno != ENOENT) if (errno != ENOENT)
err(1, "Opening %s", replname); err(1, "Opening %s", replname);
return NULL; return NULL;
} }
for (line = strsplit(file, file, "\n"); *line; line++) for (line = tal_strsplit(file, file, "\n", STR_EMPTY_OK); *line; line++)
add_replace(&repl, *line); add_replace(&repl, *line);
return repl; return repl;
} }
static void adjust_dir(const char *dir) static void adjust_dir(const char *dir)
{ {
char *parent = talloc_dirname(talloc_autofree_context(), dir); char *parent = tal_dirname(autofree(), dir);
char **deps; char **deps;
verbose("Adjusting %s\n", dir); verbose("Adjusting %s\n", dir);
...@@ -465,7 +457,7 @@ static void adjust_dir(const char *dir) ...@@ -465,7 +457,7 @@ static void adjust_dir(const char *dir)
struct adjusted *adj = NULL; struct adjusted *adj = NULL;
struct replace *repl; struct replace *repl;
depdir = talloc_asprintf(parent, "%s/%s", parent, *deps); depdir = tal_fmt(parent, "%s/%s", parent, *deps);
repl = read_replacement_file(depdir); repl = read_replacement_file(depdir);
if (repl) { if (repl) {
verbose("%s has been namespacized\n", depdir); verbose("%s has been namespacized\n", depdir);
...@@ -473,16 +465,16 @@ static void adjust_dir(const char *dir) ...@@ -473,16 +465,16 @@ static void adjust_dir(const char *dir)
rename_files(adj); rename_files(adj);
} else } else
verbose("%s has not been namespacized\n", depdir); verbose("%s has not been namespacized\n", depdir);
talloc_free(depdir); tal_free(depdir);
} }
verbose_unindent(); verbose_unindent();
talloc_free(parent); tal_free(parent);
} }
static void adjust_dependents(const char *dir) static void adjust_dependents(const char *dir)
{ {
char *parent = talloc_dirname(NULL, dir); char *parent = tal_dirname(NULL, dir);
char *base = talloc_basename(parent, dir); char *base = tal_basename(parent, dir);
char **file; char **file;
verbose("Looking for dependents in %s\n", parent); verbose("Looking for dependents in %s\n", parent);
...@@ -491,10 +483,10 @@ static void adjust_dependents(const char *dir) ...@@ -491,10 +483,10 @@ static void adjust_dependents(const char *dir)
char *info, **deps; char *info, **deps;
bool isdep = false; bool isdep = false;
if (talloc_basename(*file, *file)[0] == '.') if (tal_basename(*file, *file)[0] == '.')
continue; continue;
info = talloc_asprintf(*file, "%s/_info", *file); info = tal_fmt(*file, "%s/_info", *file);
if (access(info, R_OK) != 0) if (access(info, R_OK) != 0)
continue; continue;
......
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/str_talloc/str_talloc.h>
#include <ccan/talloc/talloc.h>
#include "read_config_header.h" #include "read_config_header.h"
#include "tools.h" #include "tools.h"
#include <string.h> #include <string.h>
...@@ -16,7 +14,7 @@ char *get_symbol_token(void *ctx, const char **line) ...@@ -16,7 +14,7 @@ char *get_symbol_token(void *ctx, const char **line)
toklen = strspn(*line, IDENT_CHARS); toklen = strspn(*line, IDENT_CHARS);
if (!toklen) if (!toklen)
return NULL; return NULL;
ret = talloc_strndup(ctx, *line, toklen); ret = tal_strndup(ctx, *line, toklen);
*line += toklen; *line += toklen;
return ret; return ret;
} }
...@@ -92,19 +90,19 @@ char *read_config_header(const char *ccan_dir, ...@@ -92,19 +90,19 @@ char *read_config_header(const char *ccan_dir,
const char **compiler, const char **cflags, const char **compiler, const char **cflags,
bool verbose) bool verbose)
{ {
char *fname = talloc_asprintf(NULL, "%s/config.h", ccan_dir); char *fname = tal_fmt(NULL, "%s/config.h", ccan_dir);
char **lines; char **lines;
unsigned int i; unsigned int i;
char *config_header; char *config_header;
config_header = talloc_grab_file(NULL, fname, NULL); config_header = tal_grab_file(NULL, fname, NULL);
talloc_free(fname); tal_free(fname);
if (!config_header) if (!config_header)
goto out; goto out;
lines = strsplit(config_header, config_header, "\n"); lines = tal_strsplit(config_header, config_header, "\n", STR_EMPTY_OK);
for (i = 0; i < talloc_array_length(lines) - 1; i++) { for (i = 0; i < tal_count(lines) - 1; i++) {
char *sym; char *sym;
const char **line = (const char **)&lines[i]; const char **line = (const char **)&lines[i];
......
#include <ccan/talloc/talloc.h> #include <ccan/take/take.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/noerr/noerr.h> #include <ccan/noerr/noerr.h>
#include <ccan/rbuf/rbuf.h> #include <ccan/rbuf/rbuf.h>
...@@ -25,38 +25,38 @@ bool tools_verbose = false; ...@@ -25,38 +25,38 @@ bool tools_verbose = false;
/* Ten minutes. */ /* Ten minutes. */
const unsigned int default_timeout_ms = 10 * 60 * 1000; const unsigned int default_timeout_ms = 10 * 60 * 1000;
char *talloc_basename(const void *ctx, const char *dir) char *tal_basename(const void *ctx, const char *dir)
{ {
char *p = strrchr(dir, '/'); const char *p = strrchr(dir, '/');
if (!p) if (!p)
return talloc_strdup(ctx, dir); return tal_strdup(ctx, dir);
return talloc_strdup(ctx, p+1); return tal_strdup(ctx, p+1);
} }
char *talloc_dirname(const void *ctx, const char *dir) char *tal_dirname(const void *ctx, const char *dir)
{ {
char *p = strrchr(dir, '/'); const char *p = strrchr(dir, '/');
if (!p) if (!p)
return talloc_strdup(ctx, "."); return tal_strdup(ctx, ".");
return talloc_strndup(ctx, dir, p - dir); return tal_strndup(ctx, dir, p - dir);
} }
char *talloc_getcwd(const void *ctx) char *tal_getcwd(const void *ctx)
{ {
unsigned int len; unsigned int len;
char *cwd; char *cwd;
/* *This* is why people hate C. */ /* *This* is why people hate C. */
len = 32; len = 32;
cwd = talloc_array(ctx, char, len); cwd = tal_arr(ctx, char, len);
while (!getcwd(cwd, len)) { while (!getcwd(cwd, len)) {
if (errno != ERANGE) { if (errno != ERANGE) {
talloc_free(cwd); tal_free(cwd);
return NULL; return NULL;
} }
cwd = talloc_realloc(ctx, cwd, char, len *= 2); tal_resize(&cwd, len *= 2);
} }
return cwd; return cwd;
} }
...@@ -77,8 +77,8 @@ char *run_with_timeout(const void *ctx, const char *cmd, ...@@ -77,8 +77,8 @@ char *run_with_timeout(const void *ctx, const char *cmd,
*ok = false; *ok = false;
if (pipe(p) != 0) if (pipe(p) != 0)
return talloc_asprintf(ctx, "Failed to create pipe: %s", return tal_fmt(ctx, "Failed to create pipe: %s",
strerror(errno)); strerror(errno));
if (tools_verbose) if (tools_verbose)
printf("Running: %s\n", cmd); printf("Running: %s\n", cmd);
...@@ -90,8 +90,7 @@ char *run_with_timeout(const void *ctx, const char *cmd, ...@@ -90,8 +90,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
if (pid == -1) { if (pid == -1) {
close_noerr(p[0]); close_noerr(p[0]);
close_noerr(p[1]); close_noerr(p[1]);
return talloc_asprintf(ctx, "Failed to fork: %s", return tal_fmt(ctx, "Failed to fork: %s", strerror(errno));
strerror(errno));
} }
if (pid == 0) { if (pid == 0) {
...@@ -117,11 +116,9 @@ char *run_with_timeout(const void *ctx, const char *cmd, ...@@ -117,11 +116,9 @@ char *run_with_timeout(const void *ctx, const char *cmd,
} }
close(p[1]); close(p[1]);
rbuf_init(&in, p[0], talloc_array(ctx, char, 4096), 4096); rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096);
if (!rbuf_read_str(&in, 0, do_talloc_realloc) && errno) { if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
talloc_free(in.buf); in.buf = tal_free(in.buf);
in.buf = NULL;
}
/* This shouldn't fail... */ /* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid) if (waitpid(pid, &status, 0) != pid)
...@@ -144,7 +141,7 @@ char *run_with_timeout(const void *ctx, const char *cmd, ...@@ -144,7 +141,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
return in.buf; return in.buf;
} }
/* Tallocs *output off ctx; return false if command fails. */ /* Tals *output off ctx; return false if command fails. */
bool run_command(const void *ctx, unsigned int *time_ms, char **output, bool run_command(const void *ctx, unsigned int *time_ms, char **output,
const char *fmt, ...) const char *fmt, ...)
{ {
...@@ -156,12 +153,12 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output, ...@@ -156,12 +153,12 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output,
if (!time_ms) if (!time_ms)
time_ms = &default_time; time_ms = &default_time;
else if (*time_ms == 0) { else if (*time_ms == 0) {
*output = talloc_strdup(ctx, "\n== TIMED OUT ==\n"); *output = tal_strdup(ctx, "\n== TIMED OUT ==\n");
return false; return false;
} }
va_start(ap, fmt); va_start(ap, fmt);
cmd = talloc_vasprintf(ctx, fmt, ap); cmd = tal_vfmt(ctx, fmt, ap);
va_end(ap); va_end(ap);
*output = run_with_timeout(ctx, cmd, &ok, time_ms); *output = run_with_timeout(ctx, cmd, &ok, time_ms);
...@@ -170,12 +167,11 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output, ...@@ -170,12 +167,11 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output,
if (!*output) if (!*output)
err(1, "Problem running child"); err(1, "Problem running child");
if (*time_ms == 0) if (*time_ms == 0)
*output = talloc_asprintf_append(*output, *output = tal_strcat(ctx, take(*output), "\n== TIMED OUT ==\n");
"\n== TIMED OUT ==\n");
return false; return false;
} }
static int unlink_all(const char *dir) static void unlink_all(const char *dir)
{ {
char cmd[strlen(dir) + sizeof("rm -rf ")]; char cmd[strlen(dir) + sizeof("rm -rf ")];
sprintf(cmd, "rm -rf %s", dir); sprintf(cmd, "rm -rf %s", dir);
...@@ -183,66 +179,78 @@ static int unlink_all(const char *dir) ...@@ -183,66 +179,78 @@ static int unlink_all(const char *dir)
printf("Running: %s\n", cmd); printf("Running: %s\n", cmd);
if (system(cmd) != 0) if (system(cmd) != 0)
warn("Could not remove temporary work in %s", dir); warn("Could not remove temporary work in %s", dir);
return 0;
} }
const char *temp_dir(const void *ctx) static pid_t *afree;
static void free_autofree(void)
{
if (*afree == getpid())
tal_free(afree);
}
tal_t *autofree(void)
{
if (!afree) {
afree = tal(NULL, pid_t);
*afree = getpid();
atexit(free_autofree);
}
return afree;
}
const char *temp_dir(void)
{ {
/* For first call, create dir. */ /* For first call, create dir. */
while (!tmpdir) { while (!tmpdir) {
tmpdir = getenv("TMPDIR"); tmpdir = getenv("TMPDIR");
if (!tmpdir) if (!tmpdir)
tmpdir = "/tmp"; tmpdir = "/tmp";
tmpdir = talloc_asprintf(talloc_autofree_context(), tmpdir = tal_fmt(autofree(), "%s/ccanlint-%u.%lu",
"%s/ccanlint-%u.%lu", tmpdir, getpid(), random());
tmpdir, getpid(), random());
if (mkdir(tmpdir, 0700) != 0) { if (mkdir(tmpdir, 0700) != 0) {
if (errno == EEXIST) { if (errno == EEXIST) {
talloc_free(tmpdir); tal_free(tmpdir);
tmpdir = NULL; tmpdir = NULL;
continue; continue;
} }
err(1, "mkdir %s failed", tmpdir); err(1, "mkdir %s failed", tmpdir);
} }
talloc_set_destructor(tmpdir, unlink_all); tal_add_destructor(tmpdir, unlink_all);
if (tools_verbose) if (tools_verbose)
printf("Created temporary directory %s\n", tmpdir); printf("Created temporary directory %s\n", tmpdir);
} }
return tmpdir; return tmpdir;
} }
int unlink_file_destructor(char *filename) void keep_temp_dir(void)
{ {
unlink(filename); tal_del_destructor(temp_dir(), unlink_all);
return 0;
} }
char *temp_file(const void *ctx, const char *extension, const char *srcname) char *temp_file(const void *ctx, const char *extension, const char *srcname)
{ {
unsigned baselen; unsigned baselen;
char *f, *suffix = talloc_strdup(ctx, ""); char *f, *suffix = tal_strdup(ctx, "");
struct stat st; struct stat st;
unsigned int count = 0; unsigned int count = 0;
srcname = talloc_basename(ctx, srcname); srcname = tal_basename(ctx, srcname);
if (strrchr(srcname, '.')) if (strrchr(srcname, '.'))
baselen = strrchr(srcname, '.') - srcname; baselen = strrchr(srcname, '.') - srcname;
else else
baselen = strlen(srcname); baselen = strlen(srcname);
do { do {
f = talloc_asprintf(ctx, "%s/%.*s%s%s", f = tal_fmt(ctx, "%s/%.*s%s%s",
temp_dir(ctx), temp_dir(), baselen, srcname, suffix, extension);
baselen, srcname, tal_free(suffix);
suffix, extension); suffix = tal_fmt(ctx, "-%u", ++count);
talloc_free(suffix);
suffix = talloc_asprintf(ctx, "-%u", ++count);
} while (lstat(f, &st) == 0); } while (lstat(f, &st) == 0);
if (tools_verbose) if (tools_verbose)
printf("Creating file %s\n", f); printf("Creating file %s\n", f);
talloc_free(suffix); tal_free(suffix);
return f; return f;
} }
...@@ -264,7 +272,7 @@ bool move_file(const char *oldname, const char *newname) ...@@ -264,7 +272,7 @@ bool move_file(const char *oldname, const char *newname)
} }
/* Try copy and delete: not atomic! */ /* Try copy and delete: not atomic! */
contents = talloc_grab_file(NULL, oldname, &size); contents = tal_grab_file(NULL, oldname, &size);
if (!contents) { if (!contents) {
if (tools_verbose) if (tools_verbose)
printf("read failed: %s\n", strerror(errno)); printf("read failed: %s\n", strerror(errno));
...@@ -294,28 +302,27 @@ bool move_file(const char *oldname, const char *newname) ...@@ -294,28 +302,27 @@ bool move_file(const char *oldname, const char *newname)
} }
free: free:
talloc_free(contents); tal_free(contents);
return ret; return ret;
} }
void *do_talloc_realloc(void *p, size_t size) void *do_tal_realloc(void *p, size_t size)
{ {
return talloc_realloc(NULL, p, char, size); tal_resize((char **)&p, size);
return p;
} }
void *talloc_grab_file(const void *ctx, const char *filename, size_t *size) void *tal_grab_file(const void *ctx, const char *filename, size_t *size)
{ {
struct rbuf rbuf; struct rbuf rbuf;
char *buf = talloc_size(ctx, 4096); char *buf = tal_arr(ctx, char, 0);
if (!rbuf_open(&rbuf, filename, buf, 4096)) { if (!rbuf_open(&rbuf, filename, buf, 0))
talloc_free(buf); return tal_free(buf);
return NULL;
} if (!rbuf_fill_all(&rbuf, do_tal_realloc) && errno)
if (!rbuf_fill_all(&rbuf, do_talloc_realloc)) { rbuf.buf = tal_free(rbuf.buf);
talloc_free(rbuf.buf); else {
rbuf.buf = NULL;
} else {
rbuf.buf[rbuf.len] = '\0'; rbuf.buf[rbuf.len] = '\0';
if (size) if (size)
*size = rbuf.len; *size = rbuf.len;
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "config.h" #include "config.h"
#include <ccan/compiler/compiler.h> #include <ccan/compiler/compiler.h>
#include <ccan/rbuf/rbuf.h> #include <ccan/rbuf/rbuf.h>
#include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -44,20 +46,24 @@ char **get_libs(const void *ctx, const char *dir, const char *style, ...@@ -44,20 +46,24 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
/* From tools.c */ /* From tools.c */
/* If set, print all commands run, all output they give and exit status. */ /* If set, print all commands run, all output they give and exit status. */
extern bool tools_verbose; extern bool tools_verbose;
char *talloc_basename(const void *ctx, const char *dir); char *tal_basename(const void *ctx, const char *dir);
char *talloc_dirname(const void *ctx, const char *dir); char *tal_dirname(const void *ctx, const char *dir);
char *talloc_getcwd(const void *ctx); char *tal_getcwd(const void *ctx);
bool PRINTF_FMT(4,5) run_command(const void *ctx, bool PRINTF_FMT(4,5) run_command(const void *ctx,
unsigned int *time_ms, unsigned int *time_ms,
char **output, char **output,
const char *fmt, ...); const char *fmt, ...);
char *run_with_timeout(const void *ctx, const char *cmd, char *run_with_timeout(const void *ctx, const char *cmd,
bool *ok, unsigned *timeout_ms); bool *ok, unsigned *timeout_ms);
const char *temp_dir(const void *ctx); const char *temp_dir(void);
void keep_temp_dir(void);
bool move_file(const char *oldname, const char *newname); bool move_file(const char *oldname, const char *newname);
void *do_talloc_realloc(void *p, size_t size); void *do_tal_realloc(void *p, size_t size);
void *talloc_grab_file(const void *ctx, const char *filename, size_t *size); void *tal_grab_file(const void *ctx, const char *filename, size_t *size);
/* Freed on exit: a good parent for auto cleanup. */
tal_t *autofree(void);
/* From compile.c. /* From compile.c.
* *
...@@ -86,9 +92,6 @@ char *temp_file(const void *ctx, const char *extension, const char *srcname); ...@@ -86,9 +92,6 @@ char *temp_file(const void *ctx, const char *extension, const char *srcname);
/* Default wait for run_command. Should never time out. */ /* Default wait for run_command. Should never time out. */
extern const unsigned int default_timeout_ms; extern const unsigned int default_timeout_ms;
/* Talloc destructor which unlinks file. */
int unlink_file_destructor(char *filename);
/* Get ccan/ top dir, given a directory within it. */ /* Get ccan/ top dir, given a directory within it. */
const char *find_ccan_dir(const char *base); const char *find_ccan_dir(const char *base);
#endif /* CCAN_TOOLS_H */ #endif /* CCAN_TOOLS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment