Skip to content

Commit

Permalink
convert from khash to pkghash
Browse files Browse the repository at this point in the history
khash usage is driving llvm's scan-build crazy, and musage making
compiler output painful to read due to the macro nature of khash
  • Loading branch information
bapt committed Aug 20, 2021
1 parent 8ca695f commit 438bcc6
Show file tree
Hide file tree
Showing 27 changed files with 566 additions and 640 deletions.
11 changes: 5 additions & 6 deletions libpkg/backup_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ register_backup(struct pkgdb *db, int fd, const char *path)
time_t t;
char buf[BUFSIZ];
char *sum;
khint_t k;
struct pkg_file *f;
char *lpath;
struct stat st;
pkghash_entry *e;

sum = pkg_checksum_generate_fileat(fd, RELATIVE_PATH(path), PKG_HASH_TYPE_SHA256_HEX);

Expand All @@ -67,11 +67,10 @@ register_backup(struct pkgdb *db, int fd, const char *path)
free(pkg->version);
t = time(NULL);
strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", localtime(&t));
if (pkg->filehash != NULL && (k = kh_get_pkg_files(pkg->filehash, path)) != kh_end(pkg->filehash)) {
f = kh_val(pkg->filehash, k);
kh_del_pkg_files(pkg->filehash, k);
DL_DELETE(pkg->files, f);
pkg_file_free(f);
if ((e = pkghash_get(pkg->filehash, path)) != NULL) {
DL_DELETE(pkg->files, (struct pkg_file *)e->value);
pkg_file_free(e->value);
pkghash_del(pkg->filehash, path);
}
xasprintf(&lpath, "%s/%s", ctx.backup_library_path, path);
pkg_addfile(pkg, lpath, sum, false);
Expand Down
39 changes: 21 additions & 18 deletions libpkg/elfhints.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ struct shlib {
char path[];
};

KHASH_MAP_INIT_STR(shlib, struct shlib *);

static int shlib_list_add(kh_shlib_t **shlib_list,
static int shlib_list_add(pkghash **shlib_list,
const char *dir, const char *shlib_file);
static int scan_dirs_for_shlibs(kh_shlib_t **shlib_list,
static int scan_dirs_for_shlibs(pkghash **shlib_list,
int numdirs, const char **dirlist,
bool strictnames);
static void add_dir(const char *, const char *, int);
Expand All @@ -73,34 +71,34 @@ int insecure;

/* Known shlibs on the standard system search path. Persistent,
common to all applications */
static kh_shlib_t *shlibs = NULL;
static pkghash *shlibs = NULL;

/* Known shlibs on the specific RPATH or RUNPATH of one binary.
Evanescent. */
static kh_shlib_t *rpath = NULL;
static pkghash *rpath = NULL;

void
shlib_list_init(void)
{
assert(kh_count(shlibs) == 0);
assert(pkghash_count(shlibs) == 0);
}

void
rpath_list_init(void)
{
assert(kh_count(rpath) == 0);
assert(pkghash_count(rpath) == 0);
}

static int
shlib_list_add(kh_shlib_t **shlib_list, const char *dir,
shlib_list_add(pkghash **shlib_list, const char *dir,
const char *shlib_file)
{
struct shlib *sl;
size_t path_len, dir_len;

/* If shlib_file is already in the shlib_list table, don't try
* and add it again */
if (kh_contains(shlib, *shlib_list, shlib_file))
if (pkghash_get(*shlib_list, shlib_file) != NULL)
return (EPKG_OK);

path_len = strlen(dir) + strlen(shlib_file) + 2;
Expand All @@ -113,7 +111,7 @@ shlib_list_add(kh_shlib_t **shlib_list, const char *dir,

sl->name = sl->path + dir_len;

kh_add(shlib, *shlib_list, sl, sl->name, free);
pkghash_safe_add(*shlib_list, sl->name, sl, free);

return (EPKG_OK);
}
Expand All @@ -122,14 +120,19 @@ const char *
shlib_list_find_by_name(const char *shlib_file)
{
struct shlib *sl;
pkghash_entry *e;

kh_find(shlib, rpath, shlib_file, sl);
if (sl != NULL)
e = pkghash_get(rpath, shlib_file);
if (e != NULL) {
sl = (struct shlib *)e->value;
return (sl->path);
}

kh_find(shlib, shlibs, shlib_file, sl);
if (sl != NULL)
e = pkghash_get(shlibs, shlib_file);
if (e != NULL) {
sl = (struct shlib *)e->value;
return (sl->path);
}

return (NULL);
}
Expand All @@ -138,15 +141,15 @@ void
shlib_list_free(void)
{

kh_free(shlib, shlibs, struct shlib, free);
pkghash_destroy(shlibs);
shlibs = NULL;
}

void
rpath_list_free(void)
{

kh_free(shlib, rpath, struct shlib, free);
pkghash_destroy(rpath);
rpath = NULL;
}

Expand Down Expand Up @@ -185,7 +188,7 @@ add_dir(const char *hintsfile, const char *name, int trusted)
}

static int
scan_dirs_for_shlibs(kh_shlib_t **shlib_list, int numdirs,
scan_dirs_for_shlibs(pkghash **shlib_list, int numdirs,
const char **dirlist, bool strictnames)
{
int i;
Expand Down
Loading

0 comments on commit 438bcc6

Please sign in to comment.