summaryrefslogtreecommitdiff
path: root/apt-pkg/tagfile.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-06-17 09:29:00 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-08-10 17:25:25 +0200
commit6c55f07a5fa3612a5d59c61a17da5fe640eadc8b (patch)
treee63587b9caf9781cb4606e0a95b4f19d7b727f92 /apt-pkg/tagfile.cc
parente8afd16892e87a6e2f17c1019ee455f5583387c2 (diff)
make all d-pointer * const pointers
Doing this disables the implicit copy assignment operator (among others) which would cause hovac if used on the classes as it would just copy the pointer, not the data the d-pointer points to. For most of the classes we don't need a copy assignment operator anyway and in many classes it was broken before as many contain a pointer of some sort. Only for our Cacheset Container interfaces we define an explicit copy assignment operator which could later be implemented to copy the data from one d-pointer to the other if we need it. Git-Dch: Ignore
Diffstat (limited to 'apt-pkg/tagfile.cc')
-rw-r--r--apt-pkg/tagfile.cc46
1 files changed, 24 insertions, 22 deletions
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index 130aef19d..4c5505bf3 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -32,13 +32,22 @@ using std::string;
class pkgTagFilePrivate
{
public:
- pkgTagFilePrivate(FileFd *pFd, unsigned long long Size) : Fd(*pFd), Buffer(NULL),
- Start(NULL), End(NULL),
- Done(false), iOffset(0),
- Size(Size)
+ void Reset(FileFd * const pFd, unsigned long long const pSize)
{
+ Fd = pFd;
+ Buffer = NULL;
+ Start = NULL;
+ End = NULL;
+ Done = false;
+ iOffset = 0;
+ Size = pSize;
}
- FileFd &Fd;
+
+ pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size)
+ {
+ Reset(pFd, Size);
+ }
+ FileFd * Fd;
char *Buffer;
char *Start;
char *End;
@@ -83,27 +92,21 @@ static unsigned long AlphaHash(const char *Text, size_t Length) /*{{{*/
// TagFile::pkgTagFile - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size)
- : d(NULL)
+pkgTagFile::pkgTagFile(FileFd * const pFd,unsigned long long const Size)
+ : d(new pkgTagFilePrivate(pFd, Size + 4))
{
Init(pFd, Size);
}
-
-void pkgTagFile::Init(FileFd *pFd,unsigned long long Size)
+void pkgTagFile::Init(FileFd * const pFd,unsigned long long Size)
{
/* The size is increased by 4 because if we start with the Size of the
filename we need to try to read 1 char more to see an EOF faster, 1
char the end-pointer can be on and maybe 2 newlines need to be added
to the end of the file -> 4 extra chars */
Size += 4;
- if(d != NULL)
- {
- free(d->Buffer);
- delete d;
- }
- d = new pkgTagFilePrivate(pFd, Size);
+ d->Reset(pFd, Size);
- if (d->Fd.IsOpen() == false)
+ if (d->Fd->IsOpen() == false)
d->Start = d->End = d->Buffer = 0;
else
d->Buffer = (char*)malloc(sizeof(char) * Size);
@@ -184,7 +187,7 @@ bool pkgTagFile::Step(pkgTagSection &Tag)
if (Resize() == false)
return _error->Error(_("Unable to parse package file %s (%d)"),
- d->Fd.Name().c_str(), 1);
+ d->Fd->Name().c_str(), 1);
} while (Tag.Scan(d->Start,d->End - d->Start, false) == false);
}
@@ -213,7 +216,7 @@ bool pkgTagFile::Fill()
{
// See if only a bit of the file is left
unsigned long long const dataSize = d->Size - ((d->End - d->Buffer) + 1);
- if (d->Fd.Read(d->End, dataSize, &Actual) == false)
+ if (d->Fd->Read(d->End, dataSize, &Actual) == false)
return false;
if (Actual != dataSize)
d->Done = true;
@@ -268,7 +271,7 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
// Reposition and reload..
d->iOffset = Offset;
d->Done = false;
- if (d->Fd.Seek(Offset) == false)
+ if (d->Fd->Seek(Offset) == false)
return false;
d->End = d->Start = d->Buffer;
@@ -283,7 +286,7 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
return false;
if (Tag.Scan(d->Start, d->End - d->Start, false) == false)
- return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd.Name().c_str(), 2);
+ return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd->Name().c_str(), 2);
return true;
}
@@ -293,9 +296,8 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
/* */
APT_IGNORE_DEPRECATED_PUSH
pkgTagSection::pkgTagSection()
- : Section(0), d(NULL), Stop(0)
+ : Section(0), d(new pkgTagSectionPrivate()), Stop(0)
{
- d = new pkgTagSectionPrivate();
#if APT_PKG_ABI < 413
TagCount = 0;
memset(&Indexes, 0, sizeof(Indexes));