Compare commits

...

4 Commits

Author SHA1 Message Date
Kai Pastor be1ea7888b Separate input world from output world
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-11-22 10:11:21 -08:00
Kai Pastor 45073b7460 Circular deps: track ancestors, not serial 2023-11-22 10:09:22 -08:00
Victor Westerhuis 948297b5b8 Search XDG Base Directories for personality files
Try $XDG_DATA_HOME/pkgconfig/personality.d and $XDG_DATA_DIRS/pkgconfig/personality.d.
2023-11-22 10:07:41 -08:00
Sam James d454f62c73 libpkgconf: fix -Walloc-size
GCC 14 introduces a new -Walloc-size included in -Wextra which gives:
```
libpkgconf/personality.c:260:11: warning: allocation of insufficient size '1' for type 'pkgconf_cross_personality_t' {aka 'struct pkgconf_cross_personality_'} with size '48' [-Walloc-size]
libpkgconf/queue.c:46:33: warning: allocation of insufficient size '1' for type 'pkgconf_queue_t' {aka'struct pkgconf_queue_'} with size '16' [-Walloc-size]
libpkgconf/client.c:164:33: warning: allocation of insufficient size '1' for type 'pkgconf_client_t' {aka 'struct pkgconf_client_'} with size '120' [-Walloc-size]
libpkgconf/path.c:105:14: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '24' [-Walloc-size]
libpkgconf/path.c:237:22: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '24' [-Walloc-size]
libpkgconf/tuple.c:239:34: warning: allocation of insufficient size '1' for type 'pkgconf_tuple_t' {aka 'struct pkgconf_tuple_'} with size '24' [-Walloc-size]
libpkgconf/dependency.c:133:13: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '44' [-Walloc-size]
libpkgconf/dependency.c:472:17: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '44' [-Walloc-size]
libpkgconf/fragment.c:146:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size]
libpkgconf/fragment.c:195:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size]
libpkgconf/fragment.c:356:14: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size]
libpkgconf/pkg.c:422:13: warning: allocation of insufficient size '1' for type 'pkgconf_pkg_t' {aka 'struct pkgconf_pkg_'} with size '188' [-Walloc-size]
libpkgconf/client.c:164:33: warning: allocation of insufficient size '1' for type 'pkgconf_client_t' {aka 'struct pkgconf_client_'} with size '224' [-Walloc-size]
libpkgconf/personality.c:260:11: warning: allocation of insufficient size '1' for type 'pkgconf_cross_personality_t' {aka 'struct pkgconf_cross_personality_'} with size '96' [-Walloc-size]
libpkgconf/dependency.c:133:13: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '80' [-Walloc-size]
libpkgconf/dependency.c:472:17: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '80' [-Walloc-size]
libpkgconf/path.c:105:14: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '48' [-Walloc-size]
libpkgconf/path.c:237:22: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '48' [-Walloc-size]
libpkgconf/queue.c:46:33: warning: allocation of insufficient size '1' for type 'pkgconf_queue_t' {aka 'struct pkgconf_queue_'} with size '32' [-Walloc-size]
libpkgconf/tuple.c:239:34: warning: allocation of insufficient size '1' for type 'pkgconf_tuple_t' {aka 'struct pkgconf_tuple_'} with size '48' [-Walloc-size]
libpkgconf/fragment.c:146:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size]
libpkgconf/fragment.c:195:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size]
libpkgconf/fragment.c:356:14: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size]
libpkgconf/pkg.c:422:13: warning: allocation of insufficient size '1' for type 'pkgconf_pkg_t' {aka 'struct pkgconf_pkg_'} with size '360' [-Walloc-size]
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
    ```

So, just swap the number of members and size arguments to match the prototype, as
we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
doing anything wrong.

The only exception there is for argv which I fixed while at it.

Signed-off-by: Sam James <sam@gentoo.org>
2023-11-22 10:06:14 -08:00
10 changed files with 68 additions and 25 deletions

View File

@ -72,7 +72,7 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv)
memset(buf, 0, strlen(src) + 1);
*argv = calloc(sizeof (void *), argv_size);
*argv = calloc(argv_size, sizeof (void *));
(*argv)[argc_count] = dst_iter;
while (*src_iter)

View File

@ -161,7 +161,7 @@ pkgconf_client_init(pkgconf_client_t *client, pkgconf_error_handler_func_t error
pkgconf_client_t *
pkgconf_client_new(pkgconf_error_handler_func_t error_handler, void *error_handler_data, const pkgconf_cross_personality_t *personality)
{
pkgconf_client_t *out = calloc(sizeof(pkgconf_client_t), 1);
pkgconf_client_t *out = calloc(1, sizeof(pkgconf_client_t));
pkgconf_client_init(out, error_handler, error_handler_data, personality);
return out;
}

View File

@ -130,7 +130,7 @@ pkgconf_dependency_addraw(pkgconf_client_t *client, pkgconf_list_t *list, const
{
pkgconf_dependency_t *dep;
dep = calloc(sizeof(pkgconf_dependency_t), 1);
dep = calloc(1, sizeof(pkgconf_dependency_t));
dep->package = pkgconf_strndup(package, package_sz);
if (version_sz != 0)
@ -469,7 +469,7 @@ pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *de
{
pkgconf_dependency_t *new_dep;
new_dep = calloc(sizeof(pkgconf_dependency_t), 1);
new_dep = calloc(1, sizeof(pkgconf_dependency_t));
new_dep->package = strdup(dep->package);
if (dep->version != NULL)

View File

@ -143,7 +143,7 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
if (strlen(string) > 1 && !pkgconf_fragment_is_special(string))
{
frag = calloc(sizeof(pkgconf_fragment_t), 1);
frag = calloc(1, sizeof(pkgconf_fragment_t));
frag->type = *(string + 1);
frag->data = pkgconf_fragment_copy_munged(client, string + 2, flags);
@ -192,7 +192,7 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
}
}
frag = calloc(sizeof(pkgconf_fragment_t), 1);
frag = calloc(1, sizeof(pkgconf_fragment_t));
frag->type = 0;
frag->data = strdup(string);
@ -353,7 +353,7 @@ pkgconf_fragment_copy(const pkgconf_client_t *client, pkgconf_list_t *list, cons
else if (!is_private && !pkgconf_fragment_can_merge_back(base, client->flags, is_private) && (pkgconf_fragment_lookup(list, base) != NULL))
return;
frag = calloc(sizeof(pkgconf_fragment_t), 1);
frag = calloc(1, sizeof(pkgconf_fragment_t));
frag->type = base->type;
frag->merged = base->merged;
@ -427,7 +427,7 @@ fragment_quote(const pkgconf_fragment_t *frag)
if (frag->data == NULL)
return NULL;
out = dst = calloc(outlen, 1);
out = dst = calloc(1, outlen);
for (; *src; src++)
{

View File

@ -278,6 +278,7 @@ PKGCONF_API void pkgconf_cross_personality_deinit(pkgconf_cross_personality_t *p
#define PKGCONF_PKG_PKGF_DONT_MERGE_SPECIAL_FRAGMENTS 0x4000
#define PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES 0x8000
#define PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES 0x10000
#define PKGCONF_PKG_PKGF_ANCESTOR 0x20000
#define PKGCONF_PKG_DEPF_INTERNAL 0x1
#define PKGCONF_PKG_DEPF_PRIVATE 0x2

View File

@ -90,7 +90,7 @@ prepare_path_node(const char *text, pkgconf_list_t *dirlist, bool filter)
return NULL;
#endif
node = calloc(sizeof(pkgconf_path_t), 1);
node = calloc(1, sizeof(pkgconf_path_t));
node->path = strdup(path);
#ifdef PKGCONF_CACHE_INODES
@ -266,7 +266,7 @@ pkgconf_path_copy_list(pkgconf_list_t *dst, const pkgconf_list_t *src)
{
pkgconf_path_t *srcpath = n->data, *path;
path = calloc(sizeof(pkgconf_path_t), 1);
path = calloc(1, sizeof(pkgconf_path_t));
path->path = strdup(srcpath->path);
#ifdef PKGCONF_CACHE_INODES

View File

@ -241,23 +241,25 @@ personality_warn_func(void *p, const char *fmt, ...)
}
static pkgconf_cross_personality_t *
load_personality_with_path(const char *path, const char *triplet)
load_personality_with_path(const char *path, const char *triplet, bool datadir)
{
char pathbuf[PKGCONF_ITEM_SIZE];
FILE *f;
pkgconf_cross_personality_t *p;
/* if triplet is null, assume that path is a direct path to the personality file */
if (triplet != NULL)
snprintf(pathbuf, sizeof pathbuf, "%s/%s.personality", path, triplet);
else
if (triplet == NULL)
pkgconf_strlcpy(pathbuf, path, sizeof pathbuf);
else if (datadir)
snprintf(pathbuf, sizeof pathbuf, "%s/pkgconfig/personality.d/%s.personality", path, triplet);
else
snprintf(pathbuf, sizeof pathbuf, "%s/%s.personality", path, triplet);
f = fopen(pathbuf, "r");
if (f == NULL)
return NULL;
p = calloc(sizeof(pkgconf_cross_personality_t), 1);
p = calloc(1, sizeof(pkgconf_cross_personality_t));
if (triplet != NULL)
p->name = strdup(triplet);
pkgconf_parser_parse(f, p, personality_parser_ops, personality_warn_func, pathbuf);
@ -281,21 +283,51 @@ pkgconf_cross_personality_find(const char *triplet)
pkgconf_list_t plist = PKGCONF_LIST_INITIALIZER;
pkgconf_node_t *n;
pkgconf_cross_personality_t *out = NULL;
#if ! defined(_WIN32) && ! defined(__HAIKU__)
char pathbuf[PKGCONF_ITEM_SIZE];
const char *envvar;
#endif
out = load_personality_with_path(triplet, NULL);
out = load_personality_with_path(triplet, NULL, false);
if (out != NULL)
return out;
if (!valid_triplet(triplet))
return NULL;
#if ! defined(_WIN32) && ! defined(__HAIKU__)
envvar = getenv("XDG_DATA_HOME");
if (envvar != NULL)
pkgconf_path_add(envvar, &plist, true);
else {
envvar = getenv("HOME");
if (envvar != NULL) {
pkgconf_strlcpy(pathbuf, envvar, sizeof pathbuf);
pkgconf_strlcat(pathbuf, "/.local/share", sizeof pathbuf);
pkgconf_path_add(pathbuf, &plist, true);
}
}
pkgconf_path_build_from_environ("XDG_DATA_DIRS", "/usr/local/share" PKG_CONFIG_PATH_SEP_S "/usr/share", &plist, true);
PKGCONF_FOREACH_LIST_ENTRY(plist.head, n)
{
pkgconf_path_t *pn = n->data;
out = load_personality_with_path(pn->path, triplet, true);
if (out != NULL)
goto finish;
}
pkgconf_path_free(&plist);
#endif
pkgconf_path_split(PERSONALITY_PATH, &plist, true);
PKGCONF_FOREACH_LIST_ENTRY(plist.head, n)
{
pkgconf_path_t *pn = n->data;
out = load_personality_with_path(pn->path, triplet);
out = load_personality_with_path(pn->path, triplet, false);
if (out != NULL)
goto finish;
}

View File

@ -250,7 +250,7 @@ determine_prefix(const pkgconf_pkg_t *pkg, char *buf, size_t buflen)
static char *
convert_path_to_value(const char *path)
{
char *buf = calloc((strlen(path) + 1) * 2, 1);
char *buf = calloc(1, (strlen(path) + 1) * 2);
char *bptr = buf;
const char *i;
@ -419,7 +419,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
pkgconf_pkg_t *pkg;
char *idptr;
pkg = calloc(sizeof(pkgconf_pkg_t), 1);
pkg = calloc(1, sizeof(pkgconf_pkg_t));
pkg->owner = client;
pkg->filename = strdup(filename);
pkg->pc_filedir = pkg_get_parent_dir(pkg);
@ -1487,6 +1487,8 @@ pkgconf_pkg_walk_list(pkgconf_client_t *client,
unsigned int eflags = PKGCONF_PKG_ERRF_OK;
pkgconf_node_t *node, *next;
parent->flags |= PKGCONF_PKG_PKGF_ANCESTOR;
PKGCONF_FOREACH_LIST_ENTRY_SAFE(deplist->head, next, node)
{
unsigned int eflags_local = PKGCONF_PKG_ERRF_OK;
@ -1507,7 +1509,7 @@ pkgconf_pkg_walk_list(pkgconf_client_t *client,
if (pkgdep == NULL)
continue;
if (pkgdep->serial == client->serial && !(parent->flags & PKGCONF_PKG_PROPF_VIRTUAL))
if((pkgdep->flags & PKGCONF_PKG_PKGF_ANCESTOR) != 0)
{
pkgdep->identifier = ++client->identifier;
@ -1545,6 +1547,8 @@ next:
pkgconf_pkg_unref(client, pkgdep);
}
parent->flags &= ~PKGCONF_PKG_PKGF_ANCESTOR;
return eflags;
}

View File

@ -43,7 +43,7 @@
void
pkgconf_queue_push(pkgconf_list_t *list, const char *package)
{
pkgconf_queue_t *pkgq = calloc(sizeof(pkgconf_queue_t), 1);
pkgconf_queue_t *pkgq = calloc(1, sizeof(pkgconf_queue_t));
pkgq->package = strdup(package);
pkgconf_node_insert_tail(&pkgq->iter, pkgq, list);
@ -228,11 +228,17 @@ pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_lis
{
unsigned int result;
if (!pkgconf_queue_compile(client, world, list))
pkgconf_pkg_t initial_world = {
.id = "virtual:world",
.realname = "virtual world package",
.flags = PKGCONF_PKG_PROPF_STATIC | PKGCONF_PKG_PROPF_VIRTUAL,
};
if (!pkgconf_queue_compile(client, &initial_world, list))
return PKGCONF_PKG_ERRF_DEPGRAPH_BREAK;
/* collect all the dependencies */
result = pkgconf_pkg_traverse(client, world, pkgconf_queue_collect_dependents, world, maxdepth, 0);
result = pkgconf_pkg_traverse(client, &initial_world, pkgconf_queue_collect_dependents, world, maxdepth, 0);
if (result != PKGCONF_PKG_ERRF_OK)
return result;

View File

@ -156,7 +156,7 @@ pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key)
static char *
dequote(const char *value)
{
char *buf = calloc((strlen(value) + 1) * 2, 1);
char *buf = calloc(1, (strlen(value) + 1) * 2);
char *bptr = buf;
const char *i;
char quote = 0;
@ -236,7 +236,7 @@ pkgconf_tuple_t *
pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse, unsigned int flags)
{
char *dequote_value;
pkgconf_tuple_t *tuple = calloc(sizeof(pkgconf_tuple_t), 1);
pkgconf_tuple_t *tuple = calloc(1, sizeof(pkgconf_tuple_t));
pkgconf_tuple_find_delete(list, key);