[pacman-dev] [PATCH] Introduce _alpm_pkg_free_trans()

Dan McGee dpmcgee at gmail.com
Sun Jun 7 16:11:33 EDT 2009


On Sun, Jun 7, 2009 at 7:34 AM, Nagy Gabor<ngaba at bibl.u-szeged.hu> wrote:
> The main purpose of this function to make our code more readable.
> It frees transaction specific fields of pmpkg_t. (It is used when a package
> is removed from the target list.)
>
> Signed-off-by: Nagy Gabor <ngaba at bibl.u-szeged.hu>

Looks good to me.
> ---
>  lib/libalpm/package.c |   13 +++++++++++++
>  lib/libalpm/package.h |    1 +
>  lib/libalpm/sync.c    |   11 +++--------
>  lib/libalpm/trans.c   |    7 +------
>  4 files changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index b63b5ec..8e41456 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -857,6 +857,19 @@ void _alpm_pkg_free(pmpkg_t *pkg)
>        FREE(pkg);
>  }
>
> +/* Free transaction specific fields */
> +void _alpm_pkg_free_trans(pmpkg_t *pkg)
> +{
> +       ALPM_LOG_FUNC;
> +
> +       if(pkg == NULL) {
> +               return;
> +       }
> +
> +       alpm_list_free(pkg->removes);
> +       pkg->removes = NULL;
> +}
> +
>  /* Is spkg an upgrade for locapkg? */
>  int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
>  {
> diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
> index 87e8179..4e4a7b9 100644
> --- a/lib/libalpm/package.h
> +++ b/lib/libalpm/package.h
> @@ -79,6 +79,7 @@ struct __pmpkg_t {
>  pmpkg_t* _alpm_pkg_new(void);
>  pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
>  void _alpm_pkg_free(pmpkg_t *pkg);
> +void _alpm_pkg_free_trans(pmpkg_t *pkg);
>  int _alpm_pkg_cmp(const void *p1, const void *p2);
>  int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg);
>  pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle);
> diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
> index ccd6424..d4632d2 100644
> --- a/lib/libalpm/sync.c
> +++ b/lib/libalpm/sync.c
> @@ -391,12 +391,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
>                }
>
>                /* Unresolvable packages will be removed from the target list, so
> -                  we free the transaction specific field: pkg->removes */
> -               for(i = unresolvable; i; i = i->next) {
> -                       pmpkg_t *pkg = i->data;
> -                       alpm_list_free(pkg->removes);
> -                       pkg->removes = NULL;
> -               }
> +                  we free the transaction specific fields */
> +               alpm_list_free_inner(unresolvable, (alpm_list_fn_free)_alpm_pkg_free_trans);
>
>                /* Set DEPEND reason for pulled packages */
>                for(i = resolved; i; i = i->next) {
> @@ -470,8 +466,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
>                        _alpm_log(PM_LOG_WARNING,
>                                        _("removing '%s' from target list because it conflicts with '%s'\n"),
>                                        rsync->name, sync->name);
> -                       alpm_list_free(rsync->removes); /* rsync is not transaction target anymore */
> -                       rsync->removes = NULL;
> +                       _alpm_pkg_free_trans(rsync); /* rsync is not transaction target anymore */
>                        trans->packages = alpm_list_remove(trans->packages, rsync, _alpm_pkg_cmp, NULL);
>                        continue;
>                }
> diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
> index 6317b69..99ef9f7 100644
> --- a/lib/libalpm/trans.c
> +++ b/lib/libalpm/trans.c
> @@ -248,12 +248,7 @@ void _alpm_trans_free(pmtrans_t *trans)
>        }
>
>        if(trans->type == PM_TRANS_TYPE_SYNC) {
> -               alpm_list_t *i;
> -               for(i = trans->packages; i; i = i->next) {
> -                       pmpkg_t *pkg = i->data;
> -                       alpm_list_free(pkg->removes);
> -                       pkg->removes = NULL;
> -               }
> +               alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_pkg_free_trans);
>        } else {
>                alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_pkg_free);
>        }
> --
> 1.6.3.2
>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev at archlinux.org
> http://www.archlinux.org/mailman/listinfo/pacman-dev
>


More information about the pacman-dev mailing list