From: Ben Collins Date: Mon, 15 Jan 2001 04:53:42 +0000 (+0000) Subject: fixups for obstack usage X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=853630b88a420b936679ab50b0097811d7f3f8a7;p=dpkg fixups for obstack usage --- diff --git a/ChangeLog b/ChangeLog index 96138c85..19f40957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sun Jan 14 23:37:30 EST 2001 Ben Collins + + * 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 * main/dpkg.8: Document --command-fd. diff --git a/include/dpkg-db.h b/include/dpkg-db.h index ef8f2bba..f9342048 100644 --- a/include/dpkg-db.h +++ b/include/dpkg-db.h @@ -307,15 +307,11 @@ int epochsdiffer(const struct versionrevision *a, const struct versionrevision *b); /*** from nfmalloc.c ***/ - -#include -#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); diff --git a/lib/dbmodify.c b/lib/dbmodify.c index 2ec6d321..2cfe9407 100644 --- a/lib/dbmodify.c +++ b/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); diff --git a/lib/nfmalloc.c b/lib/nfmalloc.c index 9515520a..83d59630 100644 --- a/lib/nfmalloc.c +++ b/lib/nfmalloc.c @@ -24,12 +24,27 @@ #include #include - -/* This also defines our obstack usage */ #include -struct obstack db_obs; -int ob_init = 0; +#include + +#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; diff --git a/main/archives.c b/main/archives.c index f970606e..fa7de121 100644 --- a/main/archives.c +++ b/main/archives.c @@ -33,6 +33,10 @@ #include #include +#include +#define obstack_chunk_alloc m_malloc +#define obstack_chunk_free free + #include #include #include @@ -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; } } diff --git a/main/processarc.c b/main/processarc.c index 34383041..534a2e1e 100644 --- a/main/processarc.c +++ b/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);