From: Michael Schroeder Date: Tue, 4 Mar 2008 17:52:55 +0000 (+0000) Subject: - clean up tmp space management X-Git-Tag: BASE-SuSE-Code-12_1-Branch~308^2~537 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b53291befd7bfbb2b7079d99932ad99213199de7;p=thirdparty%2Flibsolv.git - clean up tmp space management - return location in tmp space - move solvable2str into solvable.c --- diff --git a/src/pool.c b/src/pool.c index d5cac2be..9bebf4ac 100644 --- a/src/pool.c +++ b/src/pool.c @@ -158,8 +158,8 @@ pool_free(Pool *pool) sat_free(pool->ss.strings); sat_free(pool->rels); queue_free(&pool->vendormap); - for (i = 0; i < DEP2STRBUF; i++) - sat_free(pool->dep2strbuf[i]); + for (i = 0; i < POOL_TMPSPACEBUF; i++) + sat_free(pool->tmpspacebuf[i]); for (i = 0; i < pool->nlanguages; i++) free((char *)pool->languages[i]); sat_free(pool->languages); @@ -202,25 +202,6 @@ pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids) } -const char * -solvable2str(Pool *pool, Solvable *s) -{ - int l, nn = pool->dep2strn; - const char *n, *e, *a; - n = id2str(pool, s->name); - e = id2str(pool, s->evr); - a = id2str(pool, s->arch); - l = strlen(n) + strlen(e) + strlen(a) + 3; - if (l > pool->dep2strlen[nn]) - { - pool->dep2strbuf[nn] = sat_realloc(pool->dep2strbuf[nn], l + 32); - pool->dep2strlen[nn] = l + 32; - } - sprintf(pool->dep2strbuf[nn], "%s-%s.%s", n, e, a); - pool->dep2strn = (nn + 1) % DEP2STRBUF; - return pool->dep2strbuf[nn]; -} - static Pool *pool_shrink_whatprovides_sortcmp_data; static int @@ -933,4 +914,20 @@ pool_set_languages(Pool *pool, const char **languages, int nlanguages) pool->languages[i] = strdup(languages[i]); } +char * +pool_alloctmpspace(Pool *pool, int len) +{ + int n = pool->tmpspacen; + if (!len) + return 0; + if (len > pool->tmpspacelen[n]) + { + pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32); + pool->tmpspacelen[n] = len + 32; + } + pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF; + return pool->tmpspacebuf[n]; +} + + // EOF diff --git a/src/pool.h b/src/pool.h index ecc3915d..48e2ed2d 100644 --- a/src/pool.h +++ b/src/pool.h @@ -111,7 +111,7 @@ extern "C" { /* how many strings to maintain (round robin) */ -#define DEP2STRBUF 16 +#define POOL_TMPSPACEBUF 16 //----------------------------------------------- @@ -163,10 +163,10 @@ struct _Pool { Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr); void *nscallbackdata; - /* our dep2str string space */ - char *dep2strbuf[DEP2STRBUF]; - int dep2strlen[DEP2STRBUF]; - int dep2strn; + /* our tmp space string space */ + char *tmpspacebuf[POOL_TMPSPACEBUF]; + int tmpspacelen[POOL_TMPSPACEBUF]; + int tmpspacen; /* debug mask and callback */ int debugmask; @@ -226,6 +226,8 @@ extern void pool_free(Pool *pool); extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4))); +extern char *pool_alloctmpspace(Pool *pool, int len); + /** * Solvable management */ diff --git a/src/poolid.c b/src/poolid.c index a08c1833..d1e449e4 100644 --- a/src/poolid.c +++ b/src/poolid.c @@ -183,74 +183,57 @@ id2evr(Pool *pool, Id id) return ""; rd = GETRELDEP(pool, id); if (ISRELDEP(rd->evr)) - return "REL"; + return "(REL)"; return pool->ss.stringspace + pool->ss.strings[rd->evr]; } -const char * -dep2str(Pool *pool, Id id) +static int +dep2strlen(Pool *pool, Id id) { - Reldep *rd; - const char *sr; - char *s1, *s2; - int n, l, ls1, ls2, lsr; - - if (!ISRELDEP(id)) - return pool->ss.stringspace + pool->ss.strings[id]; - rd = GETRELDEP(pool, id); - n = pool->dep2strn; + int l = 0; - sr = id2rel(pool, id); - lsr = strlen(sr); - - s2 = (char *)dep2str(pool, rd->evr); - pool->dep2strn = n; - ls2 = strlen(s2); - - s1 = (char *)dep2str(pool, rd->name); - pool->dep2strn = n; - ls1 = strlen(s1); - - if (rd->flags == REL_NAMESPACE) + while (ISRELDEP(id)) { - sr = "("; - lsr = 1; - ls2++; + Reldep *rd = GETRELDEP(pool, id); + l += dep2strlen(pool, rd->name) + strlen(id2rel(pool, id)); + id = rd->evr; } + return l + strlen(pool->ss.stringspace + pool->ss.strings[id]); +} - l = ls1 + ls2 + lsr; - if (l + 1 > pool->dep2strlen[n]) +static void +dep2strcpy(Pool *pool, char *p, Id id) +{ + while (ISRELDEP(id)) { - if (s1 != pool->dep2strbuf[n]) - pool->dep2strbuf[n] = sat_realloc(pool->dep2strbuf[n], l + 32); - else + Reldep *rd = GETRELDEP(pool, id); + dep2strcpy(pool, p, rd->name); + p += strlen(p); + if (rd->flags == REL_NAMESPACE) { - pool->dep2strbuf[n] = sat_realloc(pool->dep2strbuf[n], l + 32); - s1 = pool->dep2strbuf[n]; + *p++ = '('; + dep2strcpy(pool, p, rd->evr); + strcat(p, ")"); + return; } - pool->dep2strlen[n] = l + 32; - } - if (s1 != pool->dep2strbuf[n]) - { - strcpy(pool->dep2strbuf[n], s1); - s1 = pool->dep2strbuf[n]; + strcpy(p, id2rel(pool, id)); + p += strlen(p); + id = rd->evr; } - strcpy(s1 + ls1, sr); - pool->dep2strbuf[n] = s1 + ls1 + lsr; - s2 = (char *)dep2str(pool, rd->evr); - if (s2 != pool->dep2strbuf[n]) - strcpy(pool->dep2strbuf[n], s2); - pool->dep2strbuf[n] = s1; - if (rd->flags == REL_NAMESPACE) - { - s1[ls1 + ls2 + lsr - 1] = ')'; - s1[ls1 + ls2 + lsr] = 0; - } - pool->dep2strn = (n + 1) % DEP2STRBUF; - return s1; + strcpy(p, pool->ss.stringspace + pool->ss.strings[id]); } - +const char * +dep2str(Pool *pool, Id id) +{ + char *p; + if (!ISRELDEP(id)) + return pool->ss.stringspace + pool->ss.strings[id]; + p = pool_alloctmpspace(pool, dep2strlen(pool, id)); + dep2strcpy(pool, p, id); + return p; +} + void pool_shrink_strings(Pool *pool) { diff --git a/src/repodata.c b/src/repodata.c index 90742be8..95b217ec 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -1458,6 +1458,8 @@ repodata_str2dir(Repodata *data, const char *dir, int create) parent = 0; while (*dir == '/' && dir[1] == '/') dir++; + if (*dir == '/' && !dir[1]) + return 1; while (*dir) { dire = strchrnul(dir, '/'); diff --git a/src/solvable.c b/src/solvable.c index 77fb4276..9217c9b7 100644 --- a/src/solvable.c +++ b/src/solvable.c @@ -21,6 +21,19 @@ #include "repo.h" #include "util.h" +const char * +solvable2str(Pool *pool, Solvable *s) +{ + const char *n, *e, *a; + char *p; + n = id2str(pool, s->name); + e = id2str(pool, s->evr); + a = id2str(pool, s->arch); + p = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3); + sprintf(p, "%s-%s.%s", n, e, a); + return p; +} + const char * solvable_lookup_str(Solvable *s, Id keyname) { @@ -210,7 +223,7 @@ solvable_get_location(Solvable *s, unsigned int *medianrp) evr = id2str(pool, s->evr); arch = id2str(pool, s->arch); /* name-evr.arch.rpm */ - loc = sat_malloc(l + strlen(name) + strlen(evr) + strlen(arch) + 7); + loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7); if (mediadir) sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch); else @@ -221,7 +234,7 @@ solvable_get_location(Solvable *s, unsigned int *medianrp) mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE); if (!mediafile) return 0; - loc = sat_malloc(l + strlen(mediafile) + 1); + loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1); if (mediadir) sprintf(loc, "%s/%s", mediadir, mediafile); else