libpkgconf: pkg: record which pkgconf_client_t owns each pkgconf_pkg_t object

feature/tap-sh
William Pitcock 2017-12-05 17:32:00 -06:00
parent 4c0cc29277
commit 44b4b126f3
3 changed files with 14 additions and 7 deletions

View File

@ -44,7 +44,7 @@
* :rtype: pkgconf_pkg_t * * :rtype: pkgconf_pkg_t *
*/ */
pkgconf_pkg_t * pkgconf_pkg_t *
pkgconf_cache_lookup(const pkgconf_client_t *client, const char *id) pkgconf_cache_lookup(pkgconf_client_t *client, const char *id)
{ {
pkgconf_node_t *node; pkgconf_node_t *node;

View File

@ -136,6 +136,8 @@ struct pkgconf_pkg_ {
pkgconf_list_t vars; pkgconf_list_t vars;
unsigned int flags; unsigned int flags;
pkgconf_client_t *owner;
}; };
typedef bool (*pkgconf_pkg_iteration_func_t)(const pkgconf_pkg_t *pkg, void *data); typedef bool (*pkgconf_pkg_iteration_func_t)(const pkgconf_pkg_t *pkg, void *data);
@ -242,7 +244,7 @@ PKGCONF_API bool pkgconf_default_error_handler(const char *msg, const pkgconf_cl
} while (0); } while (0);
#endif #endif
PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg);
PKGCONF_API void pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg);
PKGCONF_API void pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg);
PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name); PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name);
@ -306,7 +308,7 @@ PKGCONF_API bool pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *l
PKGCONF_API bool pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth); PKGCONF_API bool pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth);
/* cache.c */ /* cache.c */
PKGCONF_API pkgconf_pkg_t *pkgconf_cache_lookup(const pkgconf_client_t *client, const char *id); PKGCONF_API pkgconf_pkg_t *pkgconf_cache_lookup(pkgconf_client_t *client, const char *id);
PKGCONF_API void pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg);
PKGCONF_API void pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg);
PKGCONF_API void pkgconf_cache_free(pkgconf_client_t *client); PKGCONF_API void pkgconf_cache_free(pkgconf_client_t *client);

View File

@ -475,10 +475,12 @@ pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
* :rtype: pkgconf_pkg_t * * :rtype: pkgconf_pkg_t *
*/ */
pkgconf_pkg_t * pkgconf_pkg_t *
pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg) pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
{ {
(void) client; if (pkg->owner != NULL && pkg->owner != client)
PKGCONF_TRACE(client, "WTF: client %p refers to package %p owned by other client %p", client, pkg, pkg->owner);
pkg->owner = client;
pkg->refcount++; pkg->refcount++;
PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount); PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount);
@ -499,11 +501,14 @@ pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg)
void void
pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg) pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
{ {
if (pkg->owner != NULL && pkg->owner != client)
PKGCONF_TRACE(client, "WTF: client %p unrefs package %p owned by other client %p", client, pkg, pkg->owner);
pkg->refcount--; pkg->refcount--;
PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount); PKGCONF_TRACE(pkg->owner, "refcount@%p: %d", pkg, pkg->refcount);
if (pkg->refcount <= 0) if (pkg->refcount <= 0)
pkgconf_pkg_free(client, pkg); pkgconf_pkg_free(pkg->owner, pkg);
} }
static inline pkgconf_pkg_t * static inline pkgconf_pkg_t *