]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
- clean up tmp space management
authorMichael Schroeder <mls@suse.de>
Tue, 4 Mar 2008 17:52:55 +0000 (17:52 +0000)
committerMichael Schroeder <mls@suse.de>
Tue, 4 Mar 2008 17:52:55 +0000 (17:52 +0000)
- return location in tmp space
- move solvable2str into solvable.c

src/pool.c
src/pool.h
src/poolid.c
src/repodata.c
src/solvable.c

index d5cac2be89a3eea1aeeb09e0dd1a346ebc909ea4..9bebf4ac67db1854401e958832c08466cc783177 100644 (file)
@@ -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
index ecc3915d5a48d8bedc2d493c33fe05cf83609764..48e2ed2da22bf8c4d5a126b14b0369f504b7e5bf 100644 (file)
@@ -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
  */
index a08c1833f826f041d0c7271c5a3c2b6b68c8dea3..d1e449e48a92cb6fe630833c18ffe773e77776d8 100644 (file)
@@ -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)
 {
index 90742be8d4a522dd280fb7a86c95e8bbb04bb508..95b217ec26be3f5a4e9a20af3099095ee289eb5b 100644 (file)
@@ -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, '/');
index 77fb427665f5ad773c1c3b89f4e1cd1b903ba332..9217c9b771a0a926865d1a760ddfb704c7a5c757 100644 (file)
 #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