Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-01-12 01:27:02 -0600
committerDan McGee <dan@archlinux.org>2008-01-21 19:33:32 -0600
commit927af790ee3ff1495acd2c6b33378a7ab20e0c67 (patch)
tree200a2cfdcce855f478530e018d1604237b345446
parentf6785dcb89e380f0f3062b4b7aa485e1cd3c5830 (diff)
Convert deltas to dynamic allocation
Another elimination of a static length structure in libalpm. Should result in a little more memory saved during execution of packages with lots of deltas attached. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/be_files.c3
-rw-r--r--lib/libalpm/delta.c23
-rw-r--r--lib/libalpm/delta.h18
-rw-r--r--lib/libalpm/package.c3
4 files changed, 28 insertions, 19 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 443a55de..f95c87a4 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -487,7 +487,8 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* DELTAS */
if(inforeq & INFRQ_DELTAS) {
- snprintf(path, PATH_MAX, "%s/%s-%s/deltas", db->path, info->name, info->version);
+ snprintf(path, PATH_MAX, "%s/%s-%s/deltas", db->path,
+ info->name, info->version);
if((fp = fopen(path, "r"))) {
while(!feof(fp)) {
fgets(line, 255, fp);
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index 3d33c595..9eb6e82f 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -1,7 +1,7 @@
/*
* delta.c
*
- * Copyright (c) 2007 by Judd Vinet <jvinet@zeroflux.org>
+ * Copyright (c) 2007-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -99,7 +99,7 @@ unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
alpm_list_t *dlts = deltas;
while(dlts) {
- pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
+ pmdelta_t *d = alpm_list_getdata(dlts);
sum += d->size;
dlts = alpm_list_next(dlts);
@@ -121,7 +121,7 @@ unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
alpm_list_t *dlts = deltas;
while(dlts) {
- pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
+ pmdelta_t *d = alpm_list_getdata(dlts);
char *fname = _alpm_filecache_find(d->filename);
if(!fname) {
@@ -241,12 +241,12 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- strncpy(delta->from, tmp2, DLT_VERSION_LEN);
+ STRDUP(delta->from, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- strncpy(delta->to, tmp2, DLT_VERSION_LEN);
+ STRDUP(delta->to, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
@@ -256,11 +256,20 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- strncpy(delta->filename, tmp2, DLT_FILENAME_LEN);
+ STRDUP(delta->filename, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
- strncpy(delta->md5sum, tmp, DLT_MD5SUM_LEN);
+ STRDUP(delta->md5sum, tmp, RET_ERR(PM_ERR_MEMORY, NULL));
return(delta);
}
+void _alpm_delta_free(pmdelta_t *delta)
+{
+ FREE(delta->from);
+ FREE(delta->to);
+ FREE(delta->filename);
+ FREE(delta->md5sum);
+ FREE(delta);
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h
index 3065d4d1..007e5d45 100644
--- a/lib/libalpm/delta.h
+++ b/lib/libalpm/delta.h
@@ -1,7 +1,7 @@
/*
* delta.h
*
- * Copyright (c) 2007 by Judd Vinet <jvinet@zeroflux.org>
+ * Copyright (c) 2007-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,22 +21,20 @@
#include "alpm.h"
-#define DLT_FILENAME_LEN 512
-#define DLT_VERSION_LEN 64
-#define DLT_MD5SUM_LEN 33
-
struct __pmdelta_t {
- char from[DLT_VERSION_LEN];
- char to[DLT_VERSION_LEN];
+ char *from;
+ char *to;
unsigned long size;
- char filename[DLT_FILENAME_LEN];
- char md5sum[DLT_MD5SUM_LEN];
+ char *filename;
+ char *md5sum;
};
unsigned long _alpm_delta_path_size(alpm_list_t *deltas);
unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas);
pmdelta_t *_alpm_delta_parse(char *line);
-alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas, const char *from, const char *to);
+void _alpm_delta_free(pmdelta_t *delta);
+alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas,
+ const char *from, const char *to);
#endif /* _ALPM_DELTA_H */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index a6e7af34..40667038 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -845,7 +845,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREELIST(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);
- FREELIST(pkg->deltas);
+ alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
+ alpm_list_free(pkg->deltas);
if(pkg->origin == PKG_FROM_FILE) {
FREE(pkg->origin_data.file);