[pacman-dev] [PATCH] Copy pmdelta_t objects in _alpm_pkg_dup().
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t. Signed-off-by: Nathan Jones <nathanj@insightbb.com> --- lib/libalpm/package.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 4f6f5a9..7829d48 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -49,6 +49,7 @@ #include "provide.h" #include "handle.h" #include "alpm.h" +#include "delta.h" /** \addtogroup alpm_packages Package Functions * @brief Functions to manipulate libalpm packages @@ -689,6 +690,7 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version) pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) { pmpkg_t* newpkg; + alpm_list_t *deltas; ALPM_LOG_FUNC; @@ -708,6 +710,23 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) newpkg->groups = alpm_list_strdup(alpm_pkg_get_groups(pkg)); newpkg->provides = alpm_list_strdup(alpm_pkg_get_provides(pkg)); newpkg->replaces = alpm_list_strdup(alpm_pkg_get_replaces(pkg)); + + /* copy all the delta objects */ + newpkg->deltas = NULL; + deltas = alpm_pkg_get_deltas(pkg); + while(deltas) { + pmdelta_t *d = malloc(sizeof(pmdelta_t)); + + if(d == NULL) { + _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdelta_t)); + RET_ERR(PM_ERR_MEMORY, NULL); + } + + memcpy(d, alpm_list_getdata(deltas), sizeof(pmdelta_t)); + newpkg->deltas = alpm_list_add(newpkg->deltas, d); + deltas = alpm_list_next(deltas); + } + /* internal */ if(newpkg->origin == PKG_FROM_FILE) { newpkg->origin_data.file = strdup(pkg->origin_data.file); -- 1.5.3.4
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
How about this instead? diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 2301411..6487753 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -361,8 +361,6 @@ alpm_list_t SYMEXPORT *alpm_list_remove_dupes(const alpm_list_t *list) /** * @brief Copy a string list, including data. * - * This is gross, assumes string data members. - * * @param list the list to copy * * @return a copy of the original list @@ -397,6 +395,30 @@ alpm_list_t SYMEXPORT *alpm_list_copy(const alpm_list_t *list) } /** + * @brief Copy a list and copy the data. + * + * The data must be constant size! + * + * @param list the list to copy + * + * @return a copy of the original list, data copied as well + */ +alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list) +{ + const alpm_list_t *lp = list; + alpm_list_t *newlist = NULL; + while(lp) { + void *newdata = calloc(1, sizeof(lp->data)); + if(newdata) { + memcpy(newdata, lp->data, sizeof(lp->data)); + newlist = alpm_list_add(newlist, newdata); + lp = lp->next; + } + } + return(newlist); +} + +/** * @brief Create a new list in reverse order. * * @param list the list to copy diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h index 8fce280..addf950 100644 --- a/lib/libalpm/alpm_list.h +++ b/lib/libalpm/alpm_list.h @@ -61,6 +61,7 @@ alpm_list_t *alpm_list_remove_node(alpm_list_t *node); alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list); alpm_list_t *alpm_list_strdup(const alpm_list_t *list); alpm_list_t *alpm_list_copy(const alpm_list_t *list); +alpm_list_t *alpm_list_copy_data(const alpm_list_t *list); alpm_list_t *alpm_list_reverse(alpm_list_t *list); /* item accessors */ diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 9c166a5..5103a38 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -46,6 +46,7 @@ #include "error.h" #include "db.h" #include "cache.h" +#include "delta.h" #include "provide.h" #include "handle.h" #include "alpm.h" @@ -703,6 +704,7 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) newpkg->groups = alpm_list_strdup(alpm_pkg_get_groups(pkg)); newpkg->provides = alpm_list_strdup(alpm_pkg_get_provides(pkg)); newpkg->replaces = alpm_list_strdup(alpm_pkg_get_replaces(pkg)); + newpkg->deltas = alpm_list_copy_data(alpm_pkg_get_deltas(pkg)); /* internal */ if(newpkg->origin == PKG_FROM_FILE) { newpkg->origin_data.file = strdup(pkg->origin_data.file);
On 10/29/07, Dan McGee <dpmcgee@gmail.com> wrote:
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
How about this instead?
Probably a better idea there. I was meaning to look into why it was the only list structure that required so much code.
On 10/29/07, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On 10/29/07, Dan McGee <dpmcgee@gmail.com> wrote:
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
How about this instead?
Probably a better idea there. I was meaning to look into why it was the only list structure that required so much code.
It's the only non-string list...take that for what it's worth. Probably not a good thing. -Dan
On Mon, Oct 29, 2007 at 09:00:47PM -0500, Dan McGee wrote:
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
How about this instead?
Fine with me. I mainly wrote it that way to avoid breaking #6 in HACKING.
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
On Mon, Oct 29, 2007 at 09:00:47PM -0500, Dan McGee wrote:
On 10/29/07, Nathan Jones <nathanj@insightbb.com> wrote:
_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t struct. I missed this function when adding the delta list to pmpkg_t.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
How about this instead?
Fine with me. I mainly wrote it that way to avoid breaking #6 in HACKING.
For everyones reference (and boy am I glad someone actually read this!): 6. The sizeof() operator should accept a type, not a value. (TODO: in certain cases, it may be better- should this be a set guideline? Read "The Practice of Programming") sizeof(alpm_list_t); NOT sizeof(*mylist); This is the exception case. Not really another way to do it, and as long as you follow the warning that the size must be known beforehand (static), you are fine. People get in trouble when they start doing it on strings, etc. Nathan- keep up the great work. Glad to have you contributing! -Dan
participants (3)
-
Aaron Griffin
-
Dan McGee
-
Nathan Jones