From 229fb1a3a35bade26cfff373087461d7a98aade3 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 4 May 2010 17:05:23 +0200 Subject: * apt-pkg/contrib/weakptr.h: - add a class WeakPointable which allows one to register weak pointers to an object which will be set to NULL when the object is deallocated. * [ABI break] apt-pkg/acquire{-worker,-item,}.h: - subclass pkgAcquire::{Worker,Item,ItemDesc} from WeakPointable. --- apt-pkg/acquire-item.h | 3 ++- apt-pkg/acquire-worker.h | 3 ++- apt-pkg/acquire.h | 3 ++- apt-pkg/contrib/weakptr.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/makefile | 2 +- 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 apt-pkg/contrib/weakptr.h (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index bafa8263a..b338b2a41 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -27,6 +27,7 @@ #include #include #include +#include /** \addtogroup acquire * @{ @@ -46,7 +47,7 @@ * * \see pkgAcquire */ -class pkgAcquire::Item +class pkgAcquire::Item : public WeakPointable { protected: diff --git a/apt-pkg/acquire-worker.h b/apt-pkg/acquire-worker.h index 2942df69f..06283922e 100644 --- a/apt-pkg/acquire-worker.h +++ b/apt-pkg/acquire-worker.h @@ -20,6 +20,7 @@ #define PKGLIB_ACQUIRE_WORKER_H #include +#include /** \brief A fetch subprocess. @@ -41,7 +42,7 @@ * * \sa pkgAcqMethod, pkgAcquire::Item, pkgAcquire */ -class pkgAcquire::Worker +class pkgAcquire::Worker : public WeakPointable { friend class pkgAcquire; diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 9e91a9f67..8e2c21151 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -67,6 +67,7 @@ #define PKGLIB_ACQUIRE_H #include +#include #include #include @@ -376,7 +377,7 @@ class pkgAcquire * * An item may have several assocated ItemDescs over its lifetime. */ -struct pkgAcquire::ItemDesc +struct pkgAcquire::ItemDesc : public WeakPointable { /** \brief The URI from which to download this item. */ string URI; diff --git a/apt-pkg/contrib/weakptr.h b/apt-pkg/contrib/weakptr.h new file mode 100644 index 000000000..5158e393c --- /dev/null +++ b/apt-pkg/contrib/weakptr.h @@ -0,0 +1,62 @@ +/* weakptr.h - An object which supports weak pointers. + * + * Copyright (C) 2010 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef WEAK_POINTER_H +#define WEAK_POINTER_H + +#include +/** + * Class for objects providing support for weak pointers. + * + * This class allows for the registration of certain pointers as weak, + * which will cause them to be set to NULL when the destructor of the + * object is called. + */ +class WeakPointable { +private: + std::set pointers; + +public: + + /** + * Add a new weak pointer. + */ + inline void AddWeakPointer(WeakPointable** weakptr) { + pointers.insert(weakptr); + } + + /** + * Remove the weak pointer from the list of weak pointers. + */ + inline void RemoveWeakPointer(WeakPointable **weakptr) { + pointers.erase(weakptr); + } + + /** + * Deconstruct the object, set all weak pointers to NULL. + */ + ~WeakPointable() { + std::set::iterator iter = pointers.begin(); + while (iter != pointers.end()) + **(iter++) = NULL; + } +}; + +#endif // WEAK_POINTER_H diff --git a/apt-pkg/makefile b/apt-pkg/makefile index bdd49c089..148ad581b 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -25,7 +25,7 @@ SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \ contrib/fileutl.cc HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h netrc.h\ md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h \ - macros.h + macros.h weakptr.h # Source code for the core main library SOURCE+= pkgcache.cc version.cc depcache.cc \ -- cgit v1.2.3 From 61d15f9104e1f574b0786700207675b892a0e241 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 4 May 2010 18:01:51 +0200 Subject: * apt-pkg/pkgcache.cc: - Merge fix from David to correct handling in single-arch environments. This makes apt-get showauto working. --- apt-pkg/pkgcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 1bbd74bd9..351702240 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -218,7 +218,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) { /* Returns 0 on error, pointer to the package otherwise */ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) { if (MultiArchCache() == false) { - if (Arch == "native" || Arch == "all" || + if (Arch == "native" || Arch == "all" || Arch == "any" || Arch == _config->Find("APT::Architecture")) return SingleArchFindPkg(Name); else -- cgit v1.2.3 From 63b528a4585d10926a9972663435bc0abc815345 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 5 May 2010 09:54:49 +0200 Subject: * apt-pkg/deb/debrecords.cc: - fix max tag buffer size (LP: #545336, closes: #578959) --- apt-pkg/deb/debrecords.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 8ed0bb7eb..57d30dc62 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -19,7 +19,8 @@ /* */ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : File(FileName,FileFd::ReadOnly), - Tags(&File,Cache.Head().MaxVerFileSize + 200) + Tags(&File, std::max(Cache.Head().MaxVerFileSize, + Cache.Head().MaxDescFileSize) + 200) { } /*}}}*/ -- cgit v1.2.3