libxbps: ABI/API break due to xbps_pkg{,pattern}_name changes.
The funcs xbps_pkg_name() and xbps_pkgpattern_name() were using malloc(3) to return the result, until now. They now have been changed to not allocate the result via malloc, the caller is responsible to provide a buffer at least of XBPS_NAME_SIZE (64). If for whatever reason the pkgname can't be guessed, returns false. This should avoid lots of small allocs around libxbps. New functions have the following prototype: bool xbps_pkg_name(char *dst, size_t len, const char *pkg) bool xbps_pkgpattern_name(char *dst, size_t len, const char *pkg) as suggested by @duncaen.
This commit is contained in:
@ -36,7 +36,7 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
|
||||
{
|
||||
xbps_array_t replaces;
|
||||
const char *pkgver, *repo;
|
||||
char *pkgname, *self_replaced;
|
||||
char pkgname[XBPS_NAME_SIZE], *self_replaced;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo);
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
@ -54,10 +54,10 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
|
||||
if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL)
|
||||
replaces = xbps_array_create();
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
self_replaced = xbps_xasprintf("%s>=0", pkgname);
|
||||
free(pkgname);
|
||||
xbps_array_add_cstring(replaces, self_replaced);
|
||||
free(self_replaced);
|
||||
|
||||
|
Reference in New Issue
Block a user