- get rid of static variables used by join2
authorMichael Schroeder <mls@suse.de>
Mon, 6 Feb 2012 13:28:10 +0000 (14:28 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 6 Feb 2012 13:28:10 +0000 (14:28 +0100)
ext/repo_comps.c
ext/repo_content.c
ext/repo_deltainfoxml.c
ext/repo_products.c
ext/repo_releasefile_products.c
ext/repo_rpmmd.c
ext/repo_susetags.c
ext/repo_updateinfoxml.c
ext/repo_zyppdb.c
ext/tools_util.h

index 536eb44..efdfa02 100644 (file)
@@ -94,6 +94,9 @@ static struct stateswitch stateswitches[] = {
 };
 
 struct parsedata {
+  Pool *pool;
+  Repo *repo;
+  Repodata *data;
   const char *filename;
   const char *basename;
   int depth;
@@ -103,12 +106,10 @@ struct parsedata {
   int lcontent;
   int acontent;
   int docontent;
-  Pool *pool;
-  Repo *repo;
-  Repodata *data;
 
   struct stateswitch *swtab[NUMSTATES];
   enum state sbtab[NUMSTATES];
+  struct joindata jd;
 
   const char *tmplang;
   Id reqtype;
@@ -263,7 +264,7 @@ endElement(void *userData, const char *name)
 
     case STATE_ID:
     case STATE_CID:
-      s->name = pool_str2id(pd->pool, join2("pattern", ":", pd->content), 1);
+      s->name = pool_str2id(pd->pool, join2(&pd->jd, "pattern", ":", pd->content), 1);
       break;
 
     case STATE_NAME:
@@ -286,7 +287,7 @@ endElement(void *userData, const char *name)
       break;
 
     case STATE_GROUPID:
-      id = pool_str2id(pd->pool, join2("pattern", ":", pd->content), 1);
+      id = pool_str2id(pd->pool, join2(&pd->jd, "pattern", ":", pd->content), 1);
       s->requires = repo_addid_dep(pd->repo, s->requires, id, 0);
       break;
 
@@ -389,7 +390,7 @@ repo_add_comps(Repo *repo, FILE *fp, int flags)
 
   solv_free((void *)pd.tmplang);
   solv_free(pd.content);
-  join_freemem();
+  join_freemem(&pd.jd);
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
index 44acc4d..fe9f055 100644 (file)
@@ -28,6 +28,7 @@
 #include "chksum.h"
 #include "repo_content.h"
 #define DISABLE_SPLIT
+#define DISABLE_JOIN2
 #include "tools_util.h"
 
 /* split off a word, return null terminated pointer to it.
@@ -542,7 +543,6 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
     solv_free(pd.tmp);
   solv_free(line);
   solv_free(otherarchs);
-  join_freemem();
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
   return 0;
index 5ca9382..c12395e 100644 (file)
@@ -21,9 +21,6 @@
 #include "chksum.h"
 #include "repo_updateinfoxml.h"
 
-#define DISABLE_SPLIT
-#include "tools_util.h"
-
 /* #define DUMPOUT 1 */
 
 /*
@@ -584,7 +581,6 @@ repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
   XML_ParserFree(parser);
   solv_free(pd.content);
   solv_free(pd.tempstr);
-  join_freemem();
 
   /* now commit all handles */
   for (i = 0; i < pd.nhandles; i++)
index 065c8a8..802dabe 100644 (file)
@@ -109,6 +109,7 @@ struct parsedata {
 
   struct stateswitch *swtab[NUMSTATES];
   enum state sbtab[NUMSTATES];
+  struct joindata jd;
 
   const char *tmplang;
 
@@ -264,7 +265,7 @@ endElement(void *userData, const char *name)
       if (pd->tmprel)
        {
          if (pd->tmpvers)
-           s->evr = makeevr(pd->pool, join2(pd->tmpvers, "-", pd->tmprel));
+           s->evr = makeevr(pd->pool, join2(&pd->jd, pd->tmpvers, "-", pd->tmprel));
          else
            {
              fprintf(stderr, "Seen <release> but no <version>\n");
@@ -286,7 +287,7 @@ endElement(void *userData, const char *name)
       s->vendor = pool_str2id(pd->pool, pd->content, 1);
       break;
     case STATE_NAME:
-      s->name = pool_str2id(pd->pool, join2("product", ":", pd->content), 1);
+      s->name = pool_str2id(pd->pool, join2(&pd->jd, "product", ":", pd->content), 1);
       break;
     case STATE_VERSION:
       pd->tmpvers = solv_strdup(pd->content);
@@ -449,7 +450,7 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
       char *fullpath;
 
       /* check for <productsdir>/baseproduct on code11 and remember its target inode */
-      if (stat(join2(dirpath, "/", "baseproduct"), &st) == 0) /* follow symlink */
+      if (stat(join2(&pd.jd, dirpath, "/", "baseproduct"), &st) == 0) /* follow symlink */
        pd.baseproduct = st.st_ino;
       else
        pd.baseproduct = 0;
@@ -460,7 +461,7 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
          FILE *fp;
          if (len <= 5 || strcmp(entry->d_name + len - 5, ".prod") != 0)
            continue;
-         fullpath = join2(dirpath, "/", entry->d_name);
+         fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
          fp = fopen(fullpath, "r");
          if (!fp)
            {
@@ -476,7 +477,7 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
     }
   solv_free((void *)pd.tmplang);
   solv_free(pd.content);
-  join_freemem();
+  join_freemem(&pd.jd);
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
@@ -500,44 +501,48 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
 void
 repo_add_products(Repo *repo, const char *proddir, const char *root, int flags)
 {
-  const char *fullpath;
+  char *fullpath;
   DIR *dir;
 
-  dir = opendir(proddir);
-  if (dir)
+  if (proddir)
     {
-      /* assume code11 stype products */
-      closedir(dir);
-      repo_add_code11_products(repo, proddir, flags);
-      return;
+      dir = opendir(proddir);
+      if (dir)
+       {
+         /* assume code11 stype products */
+         closedir(dir);
+         repo_add_code11_products(repo, proddir, flags);
+         return;
+       }
     }
 
-  /* code11 didn't work, try old zyppdb */
-  fullpath = root ? join2(root, "", "/var/lib/zypp/db/products") : "/var/lib/zypp/db/products";
+  /* code11 didn't work, try old code10 zyppdb */
+  fullpath = solv_dupjoin(root ? root : 0, "/var/lib/zypp/db/products", 0);
   dir = opendir(fullpath);
   if (dir)
     {
       closedir(dir);
       /* assume code10 style products */
       repo_add_zyppdb_products(repo, fullpath, flags);
-      join_freemem();
+      solv_free(fullpath);
       return;
     }
+  solv_free(fullpath);
 
-  /* code11 didn't work, try -release files parsing */
-  fullpath = root ? join2(root, "", "/etc") : "/etc";
+  /* code10/11 didn't work, try -release files parsing */
+  fullpath = solv_dupjoin(root ? root : 0, "/etc", 0);
   dir = opendir(fullpath);
   if (dir)
     {
       closedir(dir);
       repo_add_releasefile_products(repo, fullpath, flags);
-      join_freemem();
+      solv_free(fullpath);
       return;
     }
 
   /* no luck. print an error message in case the root argument is wrong */
   perror(fullpath);
-  join_freemem();
+  solv_free(fullpath);
 
   /* the least we can do... */
   if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
index 7a7c217..e7cbc49 100644 (file)
 
 #define BUFF_SIZE 8192
 
+struct parsedata {
+  Repo *repo;
+  struct joindata jd;
+};
+
 static void
-add_releasefile_product(Repo *repo, FILE *fp)
+add_releasefile_product(struct parsedata *pd, FILE *fp)
 {
+  Repo *repo = pd->repo;
   Pool *pool = repo->pool;
   char buf[BUFF_SIZE];
   Id name = 0;
@@ -66,7 +72,7 @@ add_releasefile_product(Repo *repo, FILE *fp)
                 && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.'))
            --ptr1;
          *(++ptr1) = 0;
-         name = pool_str2id(pool, join2("product", ":", buf), 1);
+         name = pool_str2id(pool, join2(&pd->jd, "product", ":", buf), 1);
 
          if (ptr)
            {
@@ -117,11 +123,14 @@ repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
   struct dirent *entry;
   FILE *fp;
   char *fullpath;
+  struct parsedata pd;
 
   dir = opendir(dirpath);
   if (!dir)
     return 0;
 
+  memset(&pd, 0, sizeof(pd));
+  pd.repo = repo;
   while ((entry = readdir(dir)))
     {
       int len = strlen(entry->d_name);
@@ -130,18 +139,18 @@ repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
          /* skip /etc/lsb-release, thats not a product per-se */
          if (strcmp(entry->d_name, "lsb-release") == 0)
            continue;
-         fullpath = join2(dirpath, "/", entry->d_name);
+         fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
          if ((fp = fopen(fullpath, "r")) == 0)
            {
              perror(fullpath);
              continue;
            }
-         add_releasefile_product(repo, fp);
+         add_releasefile_product(&pd, fp);
          fclose(fp);
        }
     }
   closedir(dir);
-  join_freemem();
+  join_freemem(&pd.jd);
 
   if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
     repodata_internalize(repo_last_repodata(repo));
index 2dafb81..9527a41 100644 (file)
@@ -247,6 +247,7 @@ struct parsedata {
   Offset freshens;
   struct stateswitch *swtab[NUMSTATES];
   enum state sbtab[NUMSTATES];
+  struct joindata jd;
   /* temporal to store attribute tag language */
   const char *tmplang;
   Id chksumtype;
@@ -798,14 +799,14 @@ startElement(void *userData, const char *name, const char **atts)
       {
        const char *tmp = find_attr("pattern", atts);
        if (tmp)
-         repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_INCLUDES, join2("pattern", ":", tmp));
+         repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", tmp));
       }
       break;
     case STATE_EXTENDSENTRY:
       {
        const char *tmp = find_attr("pattern", atts);
        if (tmp)
-         repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_EXTENDS, join2("pattern", ":", tmp));
+         repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", tmp));
       }
       break;
     case STATE_LOCATION:
@@ -940,7 +941,7 @@ endElement(void *userData, const char *name)
     {
     case STATE_SOLVABLE:
       if (pd->kind && !s->name) /* add namespace in case of NULL name */
-        s->name = pool_str2id(pool, join2(pd->kind, ":", ""), 1);
+        s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
       if (!s->arch)
         s->arch = ARCH_NOARCH;
       if (!s->evr)
@@ -954,7 +955,7 @@ endElement(void *userData, const char *name)
       break;
     case STATE_NAME:
       if (pd->kind)
-        s->name = pool_str2id(pool, join2(pd->kind, ":", pd->content), 1);
+        s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", pd->content), 1);
       else
         s->name = pool_str2id(pool, pd->content, 1);
       break;
@@ -1222,7 +1223,7 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
   XML_ParserFree(parser);
   solv_free(pd.content);
   solv_free(pd.lastdirstr);
-  join_freemem();
+  join_freemem(&pd.jd);
   stringpool_free(&pd.cspool);
   solv_free(pd.cscache);
 
index 52b2e1f..6395425 100644 (file)
@@ -36,7 +36,7 @@ struct parsedata {
   int nshare;
   Id (*dirs)[3];                       /* dirid, size, nfiles */
   int ndirs;
+  struct joindata jd;
   char *language;                      /* the default language */
   Id langcache[ID_NUM_INTERNAL];       /* cache for the default language */
   int lineno;
@@ -92,7 +92,7 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma
           exit(1);
         }
       if (kind)
-        id = pool_str2id(pool, join2(kind, ":", sp[0]), 1);
+        id = pool_str2id(pool, join2(&pd->jd, kind, ":", sp[0]), 1);
       else
         id = pool_str2id(pool, sp[0], 1);
       if (i == 3)
@@ -135,7 +135,7 @@ add_source(struct parsedata *pd, char *line, Solvable *s, Id handle)
     }
 
   name = pool_str2id(pool, sp[0], 1);
-  evr = makeevr(pool, join2(sp[1], "-", sp[2]));
+  evr = makeevr(pool, join2(&pd->jd, sp[1], "-", sp[2]));
   arch = pool_str2id(pool, sp[3], 1);
   /* XXX: could record a dep here, depends on where we want to store the data */
   if (name == s->name)
@@ -762,7 +762,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
                if (split(line + 5, sp, 5) != 5)
                  continue;
                repodata_set_id(data, handle, DELTA_SEQ_NAME, pool_str2id(pool, sp[0], 1));
-               evr = makeevr(pool, join2(sp[1], "-", sp[2]));
+               evr = makeevr(pool, join2(&pd.jd, sp[1], "-", sp[2]));
                repodata_set_id(data, handle, DELTA_SEQ_EVR, evr);
                /* repodata_set_id(data, handle, DELTA_SEQ_ARCH, pool_str2id(pool, sp[3], 1)); */
                repodata_set_str(data, handle, DELTA_SEQ_NUM, sp[4]);
@@ -818,7 +818,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
            }
          handle = repodata_new_handle(data);
          repodata_set_id(data, handle, DELTA_PACKAGE_NAME, pool_str2id(pool, sp[0], 1));
-         repodata_set_id(data, handle, DELTA_PACKAGE_EVR, makeevr(pool, join2(sp[1], "-", sp[2])));
+         repodata_set_id(data, handle, DELTA_PACKAGE_EVR, makeevr(pool, join2(&pd.jd, sp[1], "-", sp[2])));
          repodata_set_id(data, handle, DELTA_PACKAGE_ARCH, pool_str2id(pool, sp[3], 1));
          repodata_add_flexarray(data, SOLVID_META, REPOSITORY_DELTAINFO, handle);
          indelta = 1;
@@ -859,10 +859,10 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
              Id name, evr, arch;
              /* we don't use the create flag here as a simple pre-check for existance */
              if (pd.kind)
-               name = pool_str2id(pool, join2(pd.kind, ":", sp[0]), 0);
+               name = pool_str2id(pool, join2(&pd.jd, pd.kind, ":", sp[0]), 0);
              else
                name = pool_str2id(pool, sp[0], 0);
-             evr = makeevr(pool, join2(sp[1], "-", sp[2]));
+             evr = makeevr(pool, join2(&pd.jd, sp[1], "-", sp[2]));
              arch = pool_str2id(pool, sp[3], 0);
              if (name && arch)
                {
@@ -884,10 +884,10 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
              /* normal operation. create a new solvable. */
              s = pool_id2solvable(pool, repo_add_solvable(repo));
              if (pd.kind)
-               s->name = pool_str2id(pool, join2(pd.kind, ":", sp[0]), 1);
+               s->name = pool_str2id(pool, join2(&pd.jd, pd.kind, ":", sp[0]), 1);
              else
                s->name = pool_str2id(pool, sp[0], 1);
-             s->evr = makeevr(pool, join2(sp[1], "-", sp[2]));
+             s->evr = makeevr(pool, join2(&pd.jd, sp[1], "-", sp[2]));
              s->arch = pool_str2id(pool, sp[3], 1);
              s->vendor = defvendor;
              createdpkgs = 1;
@@ -1054,7 +1054,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
                  exit(1);
                }
              name = pool_str2id(pool, sp[0], 1);
-             evr = makeevr(pool, join2(sp[1], "-", sp[2]));
+             evr = makeevr(pool, join2(&pd.jd, sp[1], "-", sp[2]));
              arch = pool_str2id(pool, sp[3], 1);
              if (last_found_pack >= pd.nshare)
                {
@@ -1097,10 +1097,10 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
            repodata_set_str(data, handle, SOLVABLE_ICON, line + 6);
            break;
          case CTAG('=', 'E', 'x', 't'):
-           repodata_add_poolstr_array(data, handle, SOLVABLE_EXTENDS, join2("pattern", ":", line + 6));
+           repodata_add_poolstr_array(data, handle, SOLVABLE_EXTENDS, join2(&pd.jd, "pattern", ":", line + 6));
            break;
          case CTAG('=', 'I', 'n', 'c'):
-           repodata_add_poolstr_array(data, handle, SOLVABLE_INCLUDES, join2("pattern", ":", line + 6));
+           repodata_add_poolstr_array(data, handle, SOLVABLE_INCLUDES, join2(&pd.jd, "pattern", ":", line + 6));
            break;
          case CTAG('=', 'C', 'k', 's'):
            set_checksum(&pd, data, handle, SOLVABLE_CHECKSUM, line + 6);
@@ -1220,6 +1220,6 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
 
   solv_free(pd.language);
   free(line);
-  join_freemem();
+  join_freemem(&pd.jd);
   return 0;
 }
index 1293ad2..dc8f392 100644 (file)
@@ -125,6 +125,7 @@ struct parsedata {
   Solvable *solvable;
   time_t buildtime;
   Id collhandle;
+  struct joindata jd;
 
   struct stateswitch *swtab[NUMSTATES];
   enum state sbtab[NUMSTATES];
@@ -482,7 +483,7 @@ endElement(void *userData, const char *name)
        }
       break;
     case STATE_ID:
-      s->name = pool_str2id(pool, join2("patch", ":", pd->content), 1);
+      s->name = pool_str2id(pool, join2(&pd->jd, "patch", ":", pd->content), 1);
       break;
       /* <title>imlib-1.9.15-6.fc8</title> */
     case STATE_TITLE:
@@ -644,7 +645,7 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
     }
   XML_ParserFree(parser);
   free(pd.content);
-  join_freemem();
+  join_freemem(&pd.jd);
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
index 8882fce..f969160 100644 (file)
@@ -79,6 +79,7 @@ struct parsedata {
 
   struct stateswitch *swtab[NUMSTATES];
   enum state sbtab[NUMSTATES];
+  struct joindata jd;
 
   const char *tmplang;
 
@@ -173,7 +174,7 @@ startElement(void *userData, const char *name, const char **atts)
        const char *ver = find_attr("ver", atts, 0);
        const char *rel = find_attr("rel", atts, 0);
        /* const char *epoch = find_attr("epoch", atts, 1); ignored */
-       s->evr = makeevr(pd->pool, join2(ver, "-", rel));
+       s->evr = makeevr(pd->pool, join2(&pd->jd, ver, "-", rel));
       }
       break;
       /* <summary lang="xy">... */
@@ -219,7 +220,7 @@ endElement(void *userData, const char *name)
       pd->solvable = 0;
       break;
     case STATE_NAME:
-      s->name = pool_str2id(pd->pool, join2("product", ":", pd->content), 1);
+      s->name = pool_str2id(pd->pool, join2(&pd->jd, "product", ":", pd->content), 1);
       break;
     case STATE_ARCH:
       s->arch = pool_str2id(pd->pool, pd->content, 1);
@@ -342,7 +343,7 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
        {
          if (strlen(entry->d_name) < 3)
            continue;   /* skip '.' and '..' */
-         fullpath = join2(dirpath, "/", entry->d_name);
+         fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
          if ((fp = fopen(fullpath, "r")) == 0)
            {
              perror(fullpath);
@@ -356,7 +357,7 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
 
   solv_free((void *)pd.tmplang);
   free(pd.content);
-  join_freemem();
+  join_freemem(&pd.jd);
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
 }
index 309a433..a259976 100644 (file)
@@ -13,9 +13,6 @@
 #ifndef LIBSOLV_TOOLS_UTIL_H
 #define LIBSOLV_TOOLS_UTIL_H
 
-static char *_join_tmp;
-static int _join_tmpl;
-
 static inline Id
 makeevr(Pool *pool, const char *s)
 {
@@ -49,9 +46,16 @@ split(char *l, char **sp, int m)
 }
 #endif
 
+#ifndef DISABLE_JOIN2
+
+struct joindata {
+  char *tmp;
+  int tmpl;
+};
+
 /* this join does not depend on parsedata */
 static char *
-join2(const char *s1, const char *s2, const char *s3)
+join2(struct joindata *jd, const char *s1, const char *s2, const char *s3)
 {
   int l = 1;
   char *p;
@@ -62,15 +66,12 @@ join2(const char *s1, const char *s2, const char *s3)
     l += strlen(s2);
   if (s3)
     l += strlen(s3);
-  if (l > _join_tmpl)
+  if (l > jd->tmpl)
     {
-      _join_tmpl = l + 256;
-      if (!_join_tmp)
-        _join_tmp = malloc(_join_tmpl);
-      else
-        _join_tmp = realloc(_join_tmp, _join_tmpl);
+      jd->tmpl = l + 256;
+      jd->tmp = solv_realloc(jd->tmp, jd->tmpl);
     }
-  p = _join_tmp;
+  p = jd->tmp;
   if (s1)
     {
       strcpy(p, s1);
@@ -87,24 +88,18 @@ join2(const char *s1, const char *s2, const char *s3)
       p += strlen(s3);
     }
   *p = 0;
-  return _join_tmp;
+  return jd->tmp;
 }
 
 static inline void
-join_freemem(void)
+join_freemem(struct joindata *jd)
 {
-  if (_join_tmp)
-    free(_join_tmp);
-  _join_tmp = 0;
-  _join_tmpl = 0;
+  if (jd->tmp)
+    free(jd->tmp);
+  jd->tmp = 0;
+  jd->tmpl = 0;
 }
 
-/* util function to set a translated string */
-static inline void repodata_set_tstr(Repodata *data, Id handle, const char *attrname, const char *lang, const char *str)
-{
-  Id attrid;
-  attrid = pool_str2id(data->repo->pool, join2(attrname, ":", lang), 1);
-  repodata_set_str(data, handle, attrid, str);
-}
+#endif
 
 #endif /* LIBSOLV_TOOLS_UTIL_H */