diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-05-19 11:39:21 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-05-19 12:02:56 +0300 |
commit | d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4 (patch) | |
tree | 10dbc6d72c9cef13a26cb539df43e92e4bf78d74 /src/app_list.c | |
parent | 12fdf6fc219321d22825042ae08efd322acc0310 (diff) | |
download | apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.gz apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.bz2 apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.xz apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.zip |
make the atom functions not use global state
This greatly helps with memory management on applications that
may want to daemonize and open/close database several times.
Also the lifetime and "owner" of memory for all data is now
explicitly bound to owning struct apk_database, which might
be helpful when writing language bindings. As side effect, the
interned "atoms" are unique only within what apk_database, so
comparing packages from different apk_database may not work
as expected.
Fixes #10697
Diffstat (limited to 'src/app_list.c')
-rw-r--r-- | src/app_list.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/app_list.c b/src/app_list.c index ab5c846..24d1a88 100644 --- a/src/app_list.c +++ b/src/app_list.c @@ -67,33 +67,25 @@ static const struct apk_package *is_upgradable(struct apk_name *name, const stru { struct apk_provider *p; struct apk_package *ipkg; - apk_blob_t *latest = apk_blob_atomize(APK_BLOB_STR("")); + apk_blob_t no_version = APK_BLOB_STR(""); + apk_blob_t *latest = &no_version; + int r; - if (name == NULL) - return NULL; + if (!name) return NULL; ipkg = apk_pkg_get_installed(name); - if (ipkg == NULL) - return NULL; + if (!ipkg) return NULL; - if (pkg0 == NULL) - { - foreach_array_item(p, name->providers) - { + if (!pkg0) { + foreach_array_item(p, name->providers) { pkg0 = p->pkg; - int r; - - if (pkg0 == ipkg) - continue; - + if (pkg0 == ipkg) continue; r = apk_version_compare_blob(*pkg0->version, *latest); - if (r == APK_VERSION_GREATER) - latest = pkg0->version; + if (r == APK_VERSION_GREATER) latest = pkg0->version; } - } - else + } else { latest = pkg0->version; - + } return apk_version_compare_blob(*ipkg->version, *latest) == APK_VERSION_LESS ? ipkg : NULL; } |