Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
vec: simplify vec_init() usage
Baptiste Daroussin committed 1 year ago
commit 6401b829d221c39d8a2f960cc935449698212e11
parent 7b88d72
27 files changed +43 -100
modified libpkg/fetch.c
@@ -228,16 +228,13 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, int dest, struct fetch_item *fi,
    bool silent)
{
	struct pkg_kv	*kv;
-
	kvlist_t	 envtorestore;
-
	c_charv_t		 envtounset;
+
	kvlist_t	 envtorestore = vec_init();
+
	c_charv_t		 envtounset = vec_init();
	char		*tmp;
	int		 retcode = EPKG_OK;
	struct pkg_repo	*fakerepo = NULL;
	size_t           nsz;

-
	vec_init(&envtorestore);
-
	vec_init(&envtounset);
-

	/* A URL of the form http://host.example.com/ where
	 * host.example.com does not resolve as a simple A record is
	 * not valid according to RFC 2616 Section 3.2.2.  Our usage
modified libpkg/pkg/vec.h
@@ -14,8 +14,8 @@
#define vec_t(Type) \
  struct { Type *d; size_t len, cap; }

-
#define vec_init(v) \
-
	memset((v), 0, sizeof(*(v)))
+
#define vec_init() \
+
	{ .d = NULL, .len = 0, .cap = 0 }

#define vec_foreach(list, __i) \
	for (size_t __i = 0; __i < (list).len; __i++)
modified libpkg/pkg_abi.c
@@ -530,11 +530,9 @@ pkg_analyse_files(struct pkgdb *db __unused, struct pkg *pkg, const char *stage)
	/* shlibs that are provided by files in the package but not matched by
	   SHLIB_PROVIDE_PATHS_* are still used to filter the shlibs
	   required by the package */
-
	charv_t internal_provided;
-
	vec_init(&internal_provided);
+
	charv_t internal_provided = vec_init();
	/* list of shlibs that are in the path to be evaluated for provided but are symlinks */
-
	charv_t maybe_provided;
-
	vec_init(&maybe_provided);
+
	charv_t maybe_provided = vec_init();

	while (pkg_files(pkg, &file) == EPKG_OK) {
		struct stat st;
modified libpkg/pkg_add.c
@@ -1455,15 +1455,13 @@ pkg_add_common(struct pkg_add_db *db, const char *path, unsigned flags,
	int			 retcode = EPKG_OK;
	int			 ret;
	int			 nfiles;
-
	tempdirs_t		 tempdirs;
+
	tempdirs_t		 tempdirs = vec_init();
	struct pkg_add_context	 context;

	memset(&context, 0, sizeof(context));

	assert(path != NULL);

-
	vec_init(&tempdirs);
-

	/*
	 * Open the package archive file, read all the meta files and set the
	 * current archive_entry to the first non-meta file.
@@ -1787,18 +1785,16 @@ pkg_add_fromdir(struct pkg *pkg, const char *src, struct pkgdb *db __unused)
	struct group *gr, grent;
	int err, fd, fromfd;
	int retcode;
-
	hardlinks_t hardlinks;
+
	hardlinks_t hardlinks = vec_init();
	const char *path;
	char buffer[1024];
	size_t link_len;
	bool install_as_user;
-
	tempdirs_t tempdirs;
+
	tempdirs_t tempdirs = vec_init();
	struct pkg_add_context context;

	memset(&context, 0, sizeof(context));

-
	vec_init(&hardlinks);
-
	vec_init(&tempdirs);
	install_as_user = (getenv("INSTALL_AS_USER") != NULL);

	fromfd = open(src, O_DIRECTORY);
modified libpkg/pkg_checksum.c
@@ -202,12 +202,11 @@ pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
	char *olduid;
	size_t blen;
	struct kv *entries = NULL;
-
	charv_t tofree;
+
	charv_t tofree = vec_init();
	struct pkg_option *option = NULL;
	struct pkg_dep *dep = NULL;
	struct pkg_file *f = NULL;
	bool is_group = false;
-
	vec_init(&tofree);

	if (pkg == NULL || type >= PKG_HASH_TYPE_UNKNOWN ||
					destlen < checksum_types[type].hlen)
modified libpkg/pkg_create.c
@@ -68,9 +68,8 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	const char	*relocation;
	char		*manifest;
	ucl_object_t	*obj;
-
	hardlinks_t	 hardlinks;
+
	hardlinks_t	 hardlinks = vec_init();

-
	vec_init(&hardlinks);
	if (pkg_is_valid(pkg) != EPKG_OK) {
		pkg_emit_error("the package is not valid");
		return (EPKG_FATAL);
modified libpkg/pkg_jobs.c
@@ -119,8 +119,7 @@ pkg_jobs_set_flags(struct pkg_jobs *j, pkg_flags flags)
int
pkg_jobs_set_repository(struct pkg_jobs *j, const char *ident)
{
-
	c_charv_t idents;
-
	vec_init(&idents);
+
	c_charv_t idents = vec_init();
	if (ident != NULL)
		vec_push(&idents, ident);
	return (pkg_jobs_set_repositories(j, &idents));
@@ -537,11 +536,9 @@ pkg_jobs_process_delete_request(struct pkg_jobs *j)
	struct pkg_dep *d = NULL;
	struct pkg *lp;
	int rc = EPKG_OK;
-
	pkgs_t to_process;
+
	pkgs_t to_process = vec_init();
	pkghash_it it;

-
	vec_init(&to_process);
-

	if (force)
		return (EPKG_OK);

modified libpkg/pkg_ports.c
@@ -1048,7 +1048,6 @@ plist_new(struct pkg *pkg, const char *stage)
	p->post_install_buf = xstring_new();
	p->pre_deinstall_buf = xstring_new();
	p->post_deinstall_buf = xstring_new();
-
	vec_init(&p->hardlinks);

	populate_keywords(p);

modified libpkg/pkgdb.c
@@ -992,10 +992,9 @@ pkgdb_nfs_corruption(sqlite3 *db)
int
pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
{
-
	c_charv_t r;
+
	c_charv_t r = vec_init();
	int ret;

-
	vec_init(&r);
	if (reponame != NULL)
		vec_push(&r, reponame);

@@ -2923,11 +2922,10 @@ pkgdb_begin_solver(struct pkgdb *db)
		"CREATE INDEX pkg_digest_id ON packages(name, manifestdigest);";
	struct pkgdb_it *it;
	struct pkg *p = NULL;
-
	pkgs_t pkglist;
+
	pkgs_t pkglist = vec_init();
	int rc = EPKG_OK;
	int64_t cnt = 0, cur = 0;

-
	vec_init(&pkglist);
	it = pkgdb_query_cond(db, " WHERE manifestdigest IS NULL OR manifestdigest==''",
		NULL, MATCH_ALL);
	if (it != NULL) {
modified libpkg/pkgdb_query.c
@@ -378,11 +378,9 @@ struct pkgdb_it *
pkgdb_repo_query_cond(struct pkgdb *db, const char *cond, const char *pattern, match_t match,
    const char *repo)
{
-
	c_charv_t r;
+
	c_charv_t r = vec_init();
	struct pkgdb_it *ret;

-
	vec_init(&r);
-

	if (repo != NULL)
		vec_push(&r, repo);

@@ -525,10 +523,9 @@ struct pkgdb_it *
pkgdb_repo_search(struct pkgdb *db, const char *pattern, match_t match,
    pkgdb_field field, pkgdb_field sort, const char *repo)
{
-
	c_charv_t r;
+
	c_charv_t r = vec_init();
	struct pkgdb_it *ret;

-
	vec_init(&r);
	if (repo != NULL)
		vec_push(&r, repo);

@@ -572,11 +569,9 @@ struct pkgdb_it *
pkgdb_all_search(struct pkgdb *db, const char *pattern, match_t match,
    pkgdb_field field, pkgdb_field sort, const char *repo)
{
-
	c_charv_t r;
+
	c_charv_t r = vec_init();
	struct pkgdb_it *ret;

-
	vec_init(&r);
-

	if (repo != NULL)
		vec_push(&r, repo);

modified src/check.c
@@ -244,7 +244,7 @@ exec_check(int argc, char **argv)
	int i, processed, total = 0;
	int verbose = 0;
	int nbactions;
-
	charv_t dh;
+
	charv_t dh = vec_init();

	struct option longopts[] = {
		{ "all",		no_argument,	NULL,	'a' },
@@ -263,8 +263,6 @@ exec_check(int argc, char **argv)
		{ NULL,			0,		NULL,	0   },
	};

-
	vec_init(&dh);
-

	processed = 0;

	while ((ch = getopt_long(argc, argv, "+aBCdginqrsvxy", longopts, NULL)) != -1) {
modified src/clean.c
@@ -29,7 +29,6 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
-
#include <tllist.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
@@ -262,7 +261,7 @@ exec_clean(int argc, char **argv)
{
	struct pkgdb	*db = NULL;
	pkghash		*sumlist = NULL;
-
	charv_t		 dl;
+
	charv_t		 dl = vec_init();
	const char	*cachedir;
	bool		 all = false;
	int		 retcode;
@@ -274,8 +273,6 @@ exec_clean(int argc, char **argv)
	cap_rights_t rights;
#endif

-
	vec_init(&dl);
-

	struct option longopts[] = {
		{ "all",	no_argument,	NULL,	'a' },
		{ "dry-run",	no_argument,	NULL,	'n' },
modified src/create.c
@@ -58,9 +58,7 @@ pkg_create_matches(int argc, char **argv, match_t match, struct pkg_create *pc)
	    PKG_LOAD_PROVIDES | PKG_LOAD_REQUIRES |
	    PKG_LOAD_SHLIBS_PROVIDED | PKG_LOAD_ANNOTATIONS | PKG_LOAD_LUA_SCRIPTS;
	bool foundone;
-
	vec_t(struct pkg *) pkglist;
-

-
	vec_init(&pkglist);
+
	vec_t(struct pkg *) pkglist = vec_init();

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
		pkgdb_close(db);
modified src/fetch.c
@@ -64,7 +64,7 @@ exec_fetch(int argc, char **argv)
	unsigned	 mode;
	match_t		 match = MATCH_EXACT;
	pkg_flags	 f = PKG_FLAG_NONE;
-
	c_charv_t	reponames;
+
	c_charv_t	reponames = vec_init();

	struct option longopts[] = {
		{ "all",		no_argument,		NULL,	'a' },
@@ -82,7 +82,6 @@ exec_fetch(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+aCdgiqr:Uuxyo:", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
modified src/install.c
@@ -69,7 +69,7 @@ exec_install(int argc, char **argv)
	bool		 local_only = false;
	match_t		 match = MATCH_EXACT;
	pkg_flags	 f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;
-
	c_charv_t	reponames;
+
	c_charv_t	reponames = vec_init();

	struct option longopts[] = {
		{ "automatic",		no_argument,		NULL,	'A' },
@@ -99,7 +99,6 @@ exec_install(int argc, char **argv)
		quiet = true;
	}

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+ACfFgiIlMnqr:RUxy", longopts, NULL)) != -1) {
		switch (ch) {
		case 'A':
modified src/lock.c
@@ -81,9 +81,7 @@ do_lock_unlock(struct pkgdb *db, int match, const char *pkgname,
	int		 retcode;
	int		 exitcode = EXIT_SUCCESS;
	bool		 gotone = false;
-
	vec_t(struct pkg *)pkgs;
-

-
	vec_init(&pkgs);
+
	vec_t(struct pkg *)pkgs = vec_init();

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) {
		pkgdb_close(db);
modified src/rquery.c
@@ -121,7 +121,7 @@ exec_rquery(int argc, char **argv)
	bool			 onematched = false;
	bool			 old_quiet;
	bool			 index_output = false;
-
	c_charv_t		reponames;
+
	c_charv_t		reponames = vec_init();

	struct option longopts[] = {
		{ "all",		no_argument,		NULL,	'a' },
@@ -138,7 +138,6 @@ exec_rquery(int argc, char **argv)

	portsdir = pkg_object_string(pkg_config_get("PORTSDIR"));

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+aCgiIxe:r:U", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
modified src/search.c
@@ -254,7 +254,7 @@ exec_search(int argc, char **argv)
	struct pkg	*pkg = NULL;
	bool		 atleastone = false;
	bool		 old_quiet;
-
	c_charv_t	reponames;
+
	c_charv_t	reponames = vec_init();

	struct option longopts[] = {
		{ "case-sensitive",	no_argument,		NULL,	'C' },
@@ -280,7 +280,6 @@ exec_search(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+CcDdefgiL:opqQ:r:RS:sUx", longopts, NULL)) != -1) {
		switch (ch) {
		case 'C':
modified src/update.c
@@ -149,7 +149,7 @@ exec_update(int argc, char **argv)
{
	int		 ret;
	int		 ch;
-
	c_charv_t 	reponames;
+
	c_charv_t 	reponames = vec_init();

	struct option longopts[] = {
		{ "force",	no_argument,		NULL,	'f' },
@@ -158,7 +158,6 @@ exec_update(int argc, char **argv)
		{ NULL,		0,			NULL,	0   },
	};

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+fqr:", longopts, NULL)) != -1) {
		switch (ch) {
		case 'f':
modified src/updating.c
@@ -103,9 +103,8 @@ matcher(const char *affects, const char *origin, bool ignorecase)
	size_t len;
	char *re, *buf, *p, **words;
	struct regex_cache *ent;
-
	vec_t(struct regex_cache *) cache;
+
	vec_t(struct regex_cache *) cache = vec_init();

-
	vec_init(&cache);
	len = strlen(affects);
	buf = strdup(affects);
	if (buf == NULL)
@@ -219,7 +218,7 @@ exec_updating(int argc, char **argv)
	char			*dateline = NULL;
	char			*updatingfile = NULL;
	bool			caseinsensitive = false;
-
	charv_t 		 origins;
+
	charv_t 		 origins = vec_init();
	int			 ch;
	char			*line = NULL;
	size_t			 linecap = 0;
@@ -235,8 +234,6 @@ exec_updating(int argc, char **argv)
	cap_rights_t rights;
#endif

-
	vec_init(&origins);
-

	struct option longopts[] = {
		{ "date",	required_argument,	NULL,	'd' },
		{ "file",	required_argument,	NULL,	'f' },
modified src/upgrade.c
@@ -250,7 +250,7 @@ exec_upgrade(int argc, char **argv)
	int		 scriptnoexec = 0;
	bool	rc = true;
	pkg_flags	 f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;
-
	c_charv_t	reponames;
+
	c_charv_t	reponames = vec_init();

	struct option longopts[] = {
		{ "case-sensitive",	no_argument,		NULL,	'C' },
@@ -270,8 +270,6 @@ exec_upgrade(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	vec_init(&reponames);
-

	while ((ch = getopt_long(argc, argv, "+CfFgiInqr:Uxyv", longopts, NULL)) != -1) {
		switch (ch) {
		case 'C':
modified src/version.c
@@ -807,7 +807,7 @@ exec_version(int argc, char **argv)
	match_t		 match = MATCH_ALL;
	char		*pattern = NULL;
	int		 ch;
-
	c_charv_t	reponames;
+
	c_charv_t	reponames = vec_init();

	struct option longopts[] = {
		{ "case-sensitive",	no_argument,		NULL,	'C' },
@@ -833,7 +833,6 @@ exec_version(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+Ce:g:hIiL:l:n:O:oPqRr:TtUvx:",
				 longopts, NULL)) != -1) {
		switch (ch) {
modified src/which.c
@@ -59,9 +59,7 @@ exec_which(int argc, char **argv)
	bool		 search = false;
	bool		 search_s = false;
	bool		 show_match = false;
-
	charv_t		 patterns;
-

-
	vec_init(&patterns);
+
	charv_t		 patterns = vec_init();

	struct option longopts[] = {
		{ "glob",		no_argument,	NULL,	'g' },
modified tests/lib/kv.c
@@ -12,9 +12,7 @@ ATF_TC_WITHOUT_HEAD(kv_search);

ATF_TC_BODY(kv_sort, tc)
{
-
	kvlist_t kvl;
-

-
	vec_init(&kvl);
+
	kvlist_t kvl = vec_init();

	ATF_REQUIRE_EQ_MSG(kvl.d, NULL, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(kvl.cap, 0, "vec_init failed");
@@ -44,9 +42,7 @@ ATF_TC_BODY(kv_sort, tc)

ATF_TC_BODY(kv_search, tc)
{
-
	kvlist_t kvl;
-

-
	vec_init(&kvl);
+
	kvlist_t kvl = vec_init();

	ATF_REQUIRE_EQ_MSG(kvl.d, NULL, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(kvl.cap, 0, "vec_init failed");
modified tests/lib/plist.c
@@ -275,8 +275,7 @@ ATF_TC_BODY(parse_plist, tc)
ATF_TC_BODY(expand_plist_variables, tc)
{
	char *plop;
-
	kvlist_t kv;
-
	vec_init(&kv);
+
	kvlist_t kv = vec_init();

	plop = expand_plist_variables("%%this%% is a line", &kv);
	ATF_REQUIRE_STREQ(plop, "%%this%% is a line");
modified tests/lib/shlibs.c
@@ -14,8 +14,7 @@ ATF_TC_WITHOUT_HEAD(cleanup_shlibs_required_consecutive_provided);
ATF_TC_BODY(cleanup_shlibs_required, tc)
{
	struct pkg *p;
-
	charv_t internal_provided;
-
	vec_init(&internal_provided);
+
	charv_t internal_provided = vec_init();

	ATF_REQUIRE_EQ(pkg_new(&p, PKG_FILE), EPKG_OK);
	ATF_REQUIRE(p != NULL);
@@ -36,8 +35,7 @@ ATF_TC_BODY(cleanup_shlibs_required, tc)
ATF_TC_BODY(cleanup_shlibs_required_multiple_provided, tc)
{
	struct pkg *p;
-
	charv_t internal_provided;
-
	vec_init(&internal_provided);
+
	charv_t internal_provided = vec_init();

	ATF_REQUIRE_EQ(pkg_new(&p, PKG_FILE), EPKG_OK);
	ATF_REQUIRE(p != NULL);
@@ -59,8 +57,7 @@ ATF_TC_BODY(cleanup_shlibs_required_multiple_provided, tc)
ATF_TC_BODY(cleanup_shlibs_required_consecutive_provided, tc)
{
	struct pkg *p;
-
	charv_t internal_provided;
-
	vec_init(&internal_provided);
+
	charv_t internal_provided = vec_init();

	ATF_REQUIRE_EQ(pkg_new(&p, PKG_FILE), EPKG_OK);
	ATF_REQUIRE(p != NULL);
modified tests/lib/vec.c
@@ -17,9 +17,8 @@ ATF_TC_WITHOUT_HEAD(charv_search);

ATF_TC_BODY(c_charv_t, tc)
{
-
	c_charv_t list;
+
	c_charv_t list = vec_init();

-
	vec_init(&list);
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");
@@ -55,9 +54,8 @@ ATF_TC_BODY(c_charv_t, tc)

ATF_TC_BODY(charv_t, tc)
{
-
	charv_t list;
+
	charv_t list = vec_init();

-
	vec_init(&list);
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");
@@ -93,9 +91,8 @@ ATF_TC_BODY(charv_t, tc)

ATF_TC_BODY(c_charv_contains, tc)
{
-
	c_charv_t list;
+
	c_charv_t list = vec_init();

-
	vec_init(&list);
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");
@@ -124,9 +121,8 @@ ATF_TC_BODY(c_charv_contains, tc)

ATF_TC_BODY(vec_remove_and_free, tc)
{
-
	charv_t list;
+
	charv_t list = vec_init();

-
	vec_init(&list);
	vec_push(&list, xstrdup("test1"));
	ATF_REQUIRE_EQ(list.len, 1);
	vec_remove_and_free(&list, 0, free);
@@ -147,8 +143,7 @@ ATF_TC_BODY(vec_remove_and_free, tc)

ATF_TC_BODY(charv_search, tc)
{
-
	charv_t list;
-
	vec_init(&list);
+
	charv_t list = vec_init();

	ATF_REQUIRE(charv_search(&list, "key") == NULL);
	vec_push(&list, xstrdup("bla"));