Browse Source

fixups for obstack usage

Ben Collins 25 years ago
parent
commit
853630b88a
6 changed files with 54 additions and 30 deletions
  1. 10 0
      ChangeLog
  2. 5 9
      include/dpkg-db.h
  3. 0 7
      lib/dbmodify.c
  4. 19 4
      lib/nfmalloc.c
  5. 18 8
      main/archives.c
  6. 2 2
      main/processarc.c

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+Sun Jan 14 23:37:30 EST 2001 Ben Collins <bcollins@debian.org>
+
+  * include/dpkg-db.h: redeclare nfmalloc(), remove obstack definitions
+  * lib/dbmodify.c (modstatdb_init): remove obstack init
+  * lib/nfmalloc.c: redefine nfmalloc to be an inline function. It now checks
+    to make sure db_obs is initliazed.
+  * main/archives.c (tarobject): declare our own obstack, and use it instead
+    (cu_fileslist) just call obstack_free
+  * main/processarc.c: correct calling of cu_fileslist
+
 Sun Jan 14 18:23:07 CST 2001 Adam Heath <doogie@debian.org>
 
   * main/dpkg.8: Document --command-fd.

+ 5 - 9
include/dpkg-db.h

@@ -307,15 +307,11 @@ int epochsdiffer(const struct versionrevision *a,
                  const struct versionrevision *b);
 
 /*** from nfmalloc.c ***/
-
-#include <obstack.h>
-#define obstack_chunk_alloc m_malloc
-#define obstack_chunk_free free
-#define ALIGN_BOUNDARY 64
-#define ALIGN_MASK (ALIGN_BOUNDARY - 1)
-
-extern struct obstack db_obs;
-#define nfmalloc(size) obstack_alloc(&db_obs, size)
+#ifdef HAVE_INLINE
+extern inline void *nfmalloc(size_t);
+#else
+extern void *nfmalloc(size_t);
+#endif
 char *nfstrsave(const char*);
 char *nfstrnsave(const char*, int);
 void nffreeall(void);

+ 0 - 7
lib/dbmodify.c

@@ -125,15 +125,8 @@ enum modstatdb_rw modstatdb_init(const char *adir, enum modstatdb_rw readwritere
     {   0                                               }
   }, *fnip;
   
-  static int obs_inited = 0;
-
   admindir= adir;
 
-  if (!obs_inited) {
-    obstack_init(&db_obs);
-    obs_inited = 1;
-  }
-  
   for (fnip=fnis; fnip->suffix; fnip++) {
     free(*fnip->store);
     *fnip->store= m_malloc(strlen(adir)+strlen(fnip->suffix)+2);

+ 19 - 4
lib/nfmalloc.c

@@ -24,12 +24,27 @@
 
 #include <config.h>
 #include <dpkg.h>
-
-/* This also defines our obstack usage */
 #include <dpkg-db.h>
 
-struct obstack db_obs;
-int ob_init = 0;
+#include <obstack.h>
+
+#define obstack_chunk_alloc m_malloc
+#define obstack_chunk_free free
+#define ALIGN_BOUNDARY 64
+#define ALIGN_MASK (ALIGN_BOUNDARY - 1)
+
+static struct obstack db_obs;
+static int dbobs_init = 0;
+
+#ifdef HAVE_INLINE
+inline void *nfmalloc(size_t size)
+#else
+void *nfmalloc(size_t size)
+#endif
+{
+  if (!dbobs_init) { obstack_init(&db_obs); dbobs_init = 1; }
+    return obstack_alloc(&db_obs, size);
+}
 
 char *nfstrsave(const char *string) {
   int i = strlen(string) + 1;

+ 18 - 8
main/archives.c

@@ -33,6 +33,10 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <obstack.h>
+#define obstack_chunk_alloc m_malloc
+#define obstack_chunk_free free
+
 #include <config.h>
 #include <dpkg.h>
 #include <dpkg-db.h>
@@ -208,7 +212,10 @@ int unlinkorrmdir(const char *filename) {
         filename, r ? strerror(e) : "OK");
   errno= e; return r;
 }
-     
+
+static struct obstack tar_obs;
+static int tarobs_init = 0;
+
 int tarobject(struct TarInfo *ti) {
   static struct varbuf conffderefn, hardlinkfn, symlinkfn;
   const char *usename;
@@ -222,11 +229,16 @@ int tarobject(struct TarInfo *ti) {
   struct filepackages *packageslump;
   mode_t am;
 
+  if (!tarobs_init) {
+    obstack_init(&tar_obs);
+    tarobs_init = 1;
+  }
+
   /* Append to list of files.
    * The trailing / put on the end of names in tarfiles has already
    * been stripped by TarExtractor (lib/tarfn.c).
    */
-  nifd= m_malloc(sizeof(struct fileinlist));
+  nifd= obstack_alloc(&tar_obs, sizeof(struct fileinlist));
   nifd->namenode= findnamenode(ti->Name, 0);
   nifd->next= 0; *tc->newfilesp= nifd; tc->newfilesp= &nifd->next;
   nifd->namenode->flags |= fnnf_new_inarchive;
@@ -548,7 +560,7 @@ static int try_remove_can(struct deppossi *pdep,
       }
     }
     pdep->up->up->clientdata->istobe= itb_deconfigure;
-    newdeconf= m_malloc(sizeof(struct packageinlist));
+    newdeconf= obstack_alloc(&tar_obs, sizeof(struct packageinlist));
     newdeconf->next= deconfigure;
     newdeconf->pkg= pdep->up->up;
     deconfigure= newdeconf;
@@ -676,11 +688,9 @@ void cu_cidir(int argc, void **argv) {
 }  
 
 void cu_fileslist(int argc, void **argv) {
-  struct fileinlist **headp= (struct fileinlist**)argv[0];
-  struct fileinlist *current, *next;
-  for (current= *headp; current; current= next) {
-    next= current->next;
-    free(current);
+  if (tarobs_init) {
+    obstack_free(&tar_obs, 0);
+    tarobs_init = 0;
   }
 }  
 

+ 2 - 2
main/processarc.c

@@ -270,7 +270,7 @@ void process_archive(const char *filename) {
    * hashes across.
    */
   newconffiles= 0; newconffileslastp= &newconffiles;
-  push_cleanup(cu_fileslist,~0, 0,0, 1,(void*)&newconffiles);
+  push_cleanup(cu_fileslist,~0, 0, 0, 0);
   strcpy(cidirrest,CONFFILESFILE);
   conff= fopen(cidir,"r");
   if (conff) {
@@ -512,7 +512,7 @@ void process_archive(const char *filename) {
   close(p1[1]);
 
   newfileslist= 0; tc.newfilesp= &newfileslist;
-  push_cleanup(cu_fileslist,~0, 0,0, 1,(void*)&newfileslist);
+  push_cleanup(cu_fileslist,~0, 0, 0, 0);
   tc.pkg= pkg;
   tc.backendpipe= p1[0];
   push_cleanup(cu_closefd,~ehflag_bombout, 0,0, 1,(void*)&tc.backendpipe);