From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 Date: Mon, 17 Feb 2020 17:05:40 +0300 From: Andrey Savchenko To: ALT Linux Team development discussions Message-Id: <20200217170540.d08bec530dc90ee5fbe3f822@altlinux.org> In-Reply-To: References: <2007feb6-b08c-b463-a0fe-d51a264bee45@altlinux.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-alt-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="PGP-SHA512"; boundary="Signature=_Mon__17_Feb_2020_17_05_40_+0300_QlyUSDy6PK9DTpZ+" Subject: Re: [devel] re APT patch with impossible error on "Can't allocate an item of size zero" X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Feb 2020 14:05:55 -0000 Archived-At: List-Archive: List-Post: --Signature=_Mon__17_Feb_2020_17_05_40_+0300_QlyUSDy6PK9DTpZ+ Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, 17 Feb 2020 11:41:36 +0300 (MSK) Ivan Zakharyaschev wrote: > =D0=9F=D0=BE=D1=8F=D0=B2=D0=B8=D0=BB=D0=B0=D1=81=D1=8C =D0=B8=D0=B4=D0=B5= =D1=8F, =D1=87=D1=82=D0=BE =D0=B5=D1=81=D1=82=D1=8C =D1=81=D0=BF=D0=BE=D1= =81=D0=BE=D0=B1 =D0=B7=D0=B4=D0=B5=D1=81=D1=8C =D0=BD=D0=B5 =D0=BF=D1=80=D0= =BE=D1=81=D1=82=D0=BE =D0=BE=D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0=BF=D0=BE=D0=BF=D1=80=D0=BE=D1=89=D0=B5 =D0=B2=D1= =8B=D0=B7=D0=BE=D0=B2=D1=8B =D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D1=8E=D1= =82=D1=81=D1=8F. >=20 > =D0=92=D0=B5=D1=82=D0=BA=D0=B0 alloc-templates =D0=B2=20 > http://git.altlinux.org/people/imz/packages/apt.git >=20 > (=D0=A0=D0=B0=D0=B7=D0=B2=D0=B8=D0=B2=D0=B0=D1=8F =D1=8D=D1=82=D0=BE, =D0= =BC=D0=BE=D0=B6=D0=BD=D0=BE RawAllocate() =D0=BF=D1=80=D0=B5=D0=B2=D1=80=D0= =B0=D1=82=D0=B8=D1=82=D1=8C =D0=B2 =D0=BA=D0=B0=D0=BA=D0=BE=D0=B9-=D0=BD=D0= =B8=D0=B1=D1=83=D0=B4=D1=8C > template RawAllocateArray(unsigned long ItemCount), > =D1=82=D0=B0=D0=BC, =D0=BF=D1=80=D0=B0=D0=B2=D0=B4=D0=B0, Pools =D0=BD=D0= =B5=D1=82=D1=80=D0=B8=D0=B2=D0=B8=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE =D0=BD=D0= =B0=D0=B4=D0=BE =D0=B1=D1=83=D0=B4=D0=B5=D1=82 =D0=BF=D0=B5=D1=80=D0=B5=D0= =B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C. >=20 > =D0=9F=D1=80=D0=B8=D1=88=D0=BB=D0=BE=D1=81=D1=8C, =D0=BF=D1=80=D0=B0=D0= =B2=D0=B4=D0=B0, =D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D1=82=D0=B8 =D0= =BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5 =D0=B8=D0= =B7 .cc =D0=B2 .h =D0=B8 =D0=BF=D0=B0=D1=82=D1=87=D0=B8 =D0=B4=D0=B0=D0=BB= =D1=8C=D0=BD=D0=B5=D0=B9=D1=88=D0=B8=D0=B5=20 > =D0=BD=D0=B5=D1=83=D0=B4=D0=BE=D0=B1=D0=BD=D0=BE =D0=BF=D1=80=D0=B8=D0=BA= =D0=BB=D0=B0=D0=B4=D1=8B=D0=B2=D0=B0=D1=82=D1=8C; =D0=BD=D0=BE =D0=BC=D0=BE= =D0=B6=D0=BD=D0=BE =D0=B8=D1=85 ifdef-=D0=B0=D0=BC=D0=B8 =D0=BE=D0=B1=D0=BB= =D0=BE=D0=B6=D0=B8=D1=82=D1=8C =D0=B2 .cc =D0=B8 =D0=B7=D0=B0=D0=B8=D0=BD= =D0=BA=D0=BB=D1=83=D0=B4=D0=B8=D1=82=D1=8C=20 > =D0=B2 .h.) >=20 > From 89499e5810575336e6a3b02d71d6c323321a0eca Mon Sep 17 00:00:00 2001 > From: Ivan Zakharyaschev > Date: Fri, 14 Feb 2020 04:04:42 +0300 > Subject: [PATCH] don't pass compile-time constants as an argument to > DynamicMMap::Allocate() >=20 > The argument was used for the size of the item we want to allocate. >=20 > Instead of an argument, use a parameter for the template DynamicMMap::All= ocate() > which denotes the type of the item. >=20 > Now, the truth of our assertion that the size is not zero is evident > (and checked by the compiler). >=20 > Note that this change may also potentially lead to more optimized code > due to compile-time specialization for each particular size. > --- > apt/apt-pkg/contrib/mmap.h | 12 ++++++------ > apt/apt-pkg/pkgcachegen.cc | 19 ++++++++++--------- > apt/apt-pkg/pkgcachegen.h | 3 ++- > 3 files changed, 18 insertions(+), 16 deletions(-) >=20 > diff --git a/apt/apt-pkg/contrib/mmap.h b/apt/apt-pkg/contrib/mmap.h > index 5b14ac9d9..7ec0fb8b1 100644 > --- a/apt/apt-pkg/contrib/mmap.h > +++ b/apt/apt-pkg/contrib/mmap.h > @@ -94,7 +94,8 @@ class DynamicMMap : public MMap > =20 > // Allocation > std::experimental::optional RawAllocate(unsigned long = Size,unsigned long Aln =3D 0); > - std::experimental::optional Allocate(unsigned long Ite= mSize); > + template > + std::experimental::optional Allocate(); > std::experimental::optional WriteString(const char *St= ring,unsigned long Len =3D std::numeric_limits::max()); > inline std::experimental::optional WriteString(const s= tring &S) {return WriteString(S.c_str(),S.length());}; > void UsePools(Pool &P,unsigned int Count) {Pools =3D &P; PoolCount = =3D Count;}; > @@ -107,17 +108,16 @@ class DynamicMMap : public MMap > /* Templates */ > =20 > #include > -#include > =20 > // DynamicMMap::Allocate - Pooled aligned allocation /*{{{*/ > // --------------------------------------------------------------------- > /* This allocates an Item of size ItemSize so that it is aligned to its > size in the file. */ > -std::experimental::optional DynamicMMap::Allocate(unsigne= d long ItemSize) > +template > +std::experimental::optional DynamicMMap::Allocate() > { > - assert(ItemSize !=3D 0); /* Actually, we are always called with sizeo= f(...) > - compile-time non-zero constant as the argum= ent. > - */ > + constexpr unsigned long ItemSize =3D sizeof(T); > + static_assert(ItemSize !=3D 0); =D0=94=D0=B0=D0=B2=D0=B0=D0=B9=D1=82=D0=B5 =D0=BD=D0=B5 =D0=B7=D0=B0=D0=BA= =D0=BB=D0=B0=D0=B4=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=D1=81=D1=8F =D0=BD=D0=B0 C= ++17: https://en.cppreference.com/w/cpp/language/static_assert static_assert ( bool_constexpr , message ) (since C++11) static_assert ( bool_constexpr ) (since C++17) =D0=A2=D0=B0=D0=BA =D1=87=D1=82=D0=BE =D0=BF=D1=80=D0=BE=D1=88=D1=83 =D0=B8= =D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C =D0=BF= =D0=B5=D1=80=D0=B2=D1=83=D1=8E =D1=84=D0=BE=D1=80=D0=BC=D1=83 (C++11 =D1=81= =D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC) =D0=B8 =D1=83=D0=B1=D0=B5=D0=B4=D0=B8=D1=82=D1=81=D1=8F, =D1=87=D1=82=D0=BE= =D1=8F=D0=B2=D0=BD=D0=BE =D0=B7=D0=B0=D0=B4=D0=B0=D0=BD =D0=BA=D0=B0=D0=BA= =D0=BC=D0=B8=D0=BD=D0=B8=D0=BC=D1=83=D0=BC -std=3Dc++11/gnu++11. > =20 > // Look for a matching pool entry > Pool *I; > diff --git a/apt/apt-pkg/pkgcachegen.cc b/apt/apt-pkg/pkgcachegen.cc > index 4bbab07bf..2a75f31e6 100644 > --- a/apt/apt-pkg/pkgcachegen.cc > +++ b/apt/apt-pkg/pkgcachegen.cc > @@ -112,8 +112,9 @@ std::experimental::optional pkgCacheGe= nerator::WriteStringInMap(c > return Map.WriteString(String); > } > /*}}}*/ > -std::experimental::optional pkgCacheGenerator::AllocateIn= Map(unsigned long size) {/*{{{*/ > - return Map.Allocate(size); > +template > +std::experimental::optional pkgCacheGenerator::AllocateIn= Map() {/*{{{*/ > + return Map.Allocate(); > } > /*}}}*/ > // CacheGenerator::MergeList - Merge the package list /*{{{*/ > @@ -376,7 +377,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgItera= tor &Pkg, const string &Nam > #endif > =20 > // Get a structure > - const auto Package =3D AllocateInMap(sizeof(pkgCache::Package)); > + const auto Package =3D AllocateInMap(); > const auto idxName =3D WriteStringInMap(Name); > if ((!Package) || (!idxName)) > return false; > @@ -429,7 +430,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerItera= tor &Ver, > return true; > =20 > // Get a structure > - const auto VerFile =3D AllocateInMap(sizeof(pkgCache::VerFile)); > + const auto VerFile =3D AllocateInMap(); > if (!VerFile) > return false; > =20 > @@ -460,7 +461,7 @@ std::experimental::optional pkgCacheGe= nerator::NewVersion(pkgCach > unsigned long Next) > { > // Get a structure > - const auto Version =3D AllocateInMap(sizeof(pkgCache::Version)); > + const auto Version =3D AllocateInMap(); > const auto idxVerStr =3D WriteStringInMap(VerStr); > if ((!Version) || (!idxVerStr)) > return std::experimental::nullopt; > @@ -487,7 +488,7 @@ bool pkgCacheGenerator::ListParser::NewDepends(pkgCac= he::VerIterator &Ver, > pkgCache &Cache =3D Owner->Cache; > =20 > // Get a structure > - const auto Dependency =3D Owner->AllocateInMap(sizeof(pkgCache::Depen= dency)); > + const auto Dependency =3D Owner->AllocateInMap(= ); > if (!Dependency) > return false; > =20 > @@ -574,7 +575,7 @@ bool pkgCacheGenerator::ListParser::NewProvides(pkgCa= che::VerIterator &Ver, > } > } > // Get a structure > - const auto Provides =3D Owner->AllocateInMap(sizeof(pkgCache::Provide= s)); > + const auto Provides =3D Owner->AllocateInMap(); > if (!Provides) > return false; > /* Note: > @@ -618,7 +619,7 @@ bool pkgCacheGenerator::SelectFile(const string &File= , const string &Site, > unsigned long Flags) > { > // Get some space for the structure > - const auto idxFile =3D AllocateInMap(sizeof(*CurrentFile)); > + const auto idxFile =3D AllocateInMap(); > const auto idxFileName =3D WriteStringInMap(File); > const auto idxSite =3D WriteUniqString(Site); > const auto idxIndexType =3D WriteUniqString(Index.GetType()->Label); > @@ -676,7 +677,7 @@ std::experimental::optional pkgCacheGe= nerator::WriteUniqString(co > } > =20 > // Get a structure > - const auto Item =3D AllocateInMap(sizeof(pkgCache::StringItem)); > + const auto Item =3D AllocateInMap(); > const auto idxString =3D WriteStringInMap(S, Size); > if ((!Item) || (!idxString)) > return std::experimental::nullopt; > diff --git a/apt/apt-pkg/pkgcachegen.h b/apt/apt-pkg/pkgcachegen.h > index b789177ef..73252802b 100644 > --- a/apt/apt-pkg/pkgcachegen.h > +++ b/apt/apt-pkg/pkgcachegen.h > @@ -39,7 +39,8 @@ class pkgCacheGenerator > std::experimental::optional WriteStringInMap(const std= ::string &String) { return WriteStringInMap(String.c_str(), String.length()= ); }; > std::experimental::optional WriteStringInMap(const cha= r *String); > std::experimental::optional WriteStringInMap(const cha= r *String, unsigned long Len); > - std::experimental::optional AllocateInMap(unsigned lon= g size); > + template > + std::experimental::optional AllocateInMap(); > =20 > public: > =20 Best regards, Andrew Savchenko --Signature=_Mon__17_Feb_2020_17_05_40_+0300_QlyUSDy6PK9DTpZ+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE63ZIHsdeM+1XgNer9lNaM7oe5I0FAl5KnbQACgkQ9lNaM7oe 5I1xaQ/+Ij3Vwkni8fivZiGTSHILHyJEXXKNhhYEhluQ8+EYGEX4U3sgTtEUs0nq HGKhe52RvKkE5e29KzogH7f+//gn8cO+EYDgeqgDcIA6Ebcra1hnNtMQ/s2qxdY8 q1zQFMNBKo7TLyUFR+LVKxnhQUHUAS7Yh7zi2D8UxYS0GbyG4lQgVdSBe4xWsWo/ yuZ3H8EPhMeWGkIa5A8nr/rd0kUubY1PNNQ8BOEPJeA8DddCabjmrr7XB8KtwBbZ 3umE8FqErUFO6pv+tpyj0qE16y7AKJmABOihcl2lpDXKmEUtS02W+QVuME2QPURo X0BA7HqEGu1wZm0eNcRRPQCitUkoEahWqgY5LqUcgosPv9AudiQxdUqxdh6keqEa uo1qGGF+RsLipjGDYkrBj3zd7T5+RpsF37emItXJoRrtjJWQj7J04eMMAtCuwqJ4 XWki7rlmMwWo3Byw4iTSBTU2g5yALqe4EpyZ2aJjHqWcjxevZj8+lYVF8FyTzGaB 9grfjyDUO9WAECSnuVa+/t6CutP1PWl4yPfB15aKy3gwjE0KcDlGDRjCxPwVAX/x fUhENaQ1E5JlU0iApym0k18NyPQa5KbLrEwu4TAUFVuvF0I+/HiniFKY8bqfBnLF poAwgTlWIN/WqYqQm4y/JstrxqCnusDpK5WxEWJA1+Gjv182mVk= =fd48 -----END PGP SIGNATURE----- --Signature=_Mon__17_Feb_2020_17_05_40_+0300_QlyUSDy6PK9DTpZ+--