[Reproducible-commits] [dpkg] 22/63: dpkg: Encapsulate obstack usage inside new tar_pool functions

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Mar 4 17:44:43 UTC 2016


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/buildinfo
in repository dpkg.

commit 13b5c7b4b9e492a27c6f592414fb253720f006c4
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Feb 26 17:53:35 2016 +0100

    dpkg: Encapsulate obstack usage inside new tar_pool functions
    
    These functions hide tar obstack usage, and stop requiring an explicit
    initialization, so that we can always safely call the allocator and it
    will always start from a known good state.
---
 src/archives.c | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/archives.c b/src/archives.c
index 03f828d..4b21270 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -75,27 +75,41 @@ fd_writeback_init(int fd)
 #endif
 }
 
-static struct obstack tar_obs;
-static bool tarobs_init = false;
+static struct obstack tar_pool;
+static bool tar_pool_init = false;
 
 /**
- * Ensure the obstack is properly initialized.
+ * Allocate memory from the tar memory pool.
  */
-static void ensureobstackinit(void) {
-
-  if (!tarobs_init) {
-    obstack_init(&tar_obs);
-    tarobs_init = true;
+static void *
+tar_pool_alloc(size_t size)
+{
+  if (!tar_pool_init) {
+    obstack_init(&tar_pool);
+    tar_pool_init = true;
   }
+
+  return obstack_alloc(&tar_pool, size);
+}
+
+/**
+ * Free memory from the tar memory pool.
+ */
+static void
+tar_pool_free(void *ptr)
+{
+  obstack_free(&tar_pool, ptr);
 }
 
 /**
- * Destroy the obstack.
+ * Release the tar memory pool.
  */
-static void destroyobstack(void) {
-  if (tarobs_init) {
-    obstack_free(&tar_obs, NULL);
-    tarobs_init = false;
+static void
+tar_pool_release(void)
+{
+  if (tar_pool_init) {
+    obstack_free(&tar_pool, NULL);
+    tar_pool_init = false;
   }
 }
 
@@ -571,7 +585,7 @@ struct fileinlist *addfiletolist(struct tarcontext *tc,
 				 struct filenamenode *namenode) {
   struct fileinlist *nifd;
 
-  nifd= obstack_alloc(&tar_obs, sizeof(struct fileinlist));
+  nifd = tar_pool_alloc(sizeof(*nifd));
   nifd->namenode= namenode;
   nifd->next = NULL;
   *tc->newfilesp = nifd;
@@ -584,7 +598,7 @@ remove_file_from_list(struct tarcontext *tc, struct tar_entry *ti,
                       struct fileinlist **oldnifd,
                       struct fileinlist *nifd)
 {
-  obstack_free(&tar_obs, nifd);
+  tar_pool_free(nifd);
   tc->newfilesp = oldnifd;
   *oldnifd = NULL;
 }
@@ -654,8 +668,6 @@ tarobject(void *ctx, struct tar_entry *ti)
   struct pkgset *divpkgset;
   struct pkginfo *otherpkg;
 
-  ensureobstackinit();
-
   tar_entry_update_from_system(ti);
 
   /* Perform some sanity checks on the tar entry. */
@@ -1410,7 +1422,7 @@ void cu_cidir(int argc, void **argv) {
 }
 
 void cu_fileslist(int argc, void **argv) {
-  destroyobstack();
+  tar_pool_release();
 }
 
 int

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list