[poppler] glib/poppler-document.cc poppler/Catalog.cc poppler/Catalog.h poppler/PDFDoc.h qt5/src qt6/src utils/pdfinfo.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Sep 26 17:25:20 UTC 2021
glib/poppler-document.cc | 5 ++---
poppler/Catalog.cc | 8 ++++----
poppler/Catalog.h | 2 +-
poppler/PDFDoc.h | 2 +-
qt5/src/poppler-document.cc | 5 ++---
qt6/src/poppler-document.cc | 5 ++---
utils/pdfinfo.cc | 8 +++-----
7 files changed, 15 insertions(+), 20 deletions(-)
New commits:
commit bf92b981ece533e814d10bc2bae20c8d4f96bdf4
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Sep 26 19:16:31 2021 +0200
Make Catalog::readMetadata return an unique_ptr
Makes ownership much clearer
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index fd080510..38d89b71 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -1949,11 +1949,10 @@ gchar *poppler_document_get_metadata(PopplerDocument *document)
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
- GooString *s = catalog->readMetadata();
+ std::unique_ptr<GooString> s = catalog->readMetadata();
- if (s != nullptr) {
+ if (s) {
retval = g_strdup(s->c_str());
- delete s;
}
}
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 616f43d7..f830c7a9 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -166,7 +166,7 @@ Catalog::~Catalog()
delete structTreeRoot;
}
-GooString *Catalog::readMetadata()
+std::unique_ptr<GooString> Catalog::readMetadata()
{
catalogLocker();
if (metadata.isNone()) {
@@ -180,14 +180,14 @@ GooString *Catalog::readMetadata()
}
if (!metadata.isStream()) {
- return nullptr;
+ return {};
}
Object obj = metadata.streamGetDict()->lookup("Subtype");
if (!obj.isName("XML")) {
error(errSyntaxWarning, -1, "Unknown Metadata type: '{0:s}'", obj.isName() ? obj.getName() : "???");
}
- GooString *s = new GooString();
- metadata.getStream()->fillGooString(s);
+ std::unique_ptr<GooString> s = std::make_unique<GooString>();
+ metadata.getStream()->fillGooString(s.get());
metadata.streamClose();
return s;
}
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 3f95f3a2..7a30ebbf 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -136,7 +136,7 @@ public:
// Return the contents of the metadata stream, or NULL if there is
// no metadata.
- GooString *readMetadata();
+ std::unique_ptr<GooString> readMetadata();
// Return the structure tree root object.
StructTreeRoot *getStructTreeRoot();
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index b4c7cd21..aca23585 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -184,7 +184,7 @@ public:
// Return the contents of the metadata stream, or nullptr if there is
// no metadata.
- const GooString *readMetadata() const { return catalog->readMetadata(); }
+ std::unique_ptr<GooString> readMetadata() const { return catalog->readMetadata(); }
// Return the structure tree root object.
const StructTreeRoot *getStructTreeRoot() const { return catalog->getStructTreeRoot(); }
diff --git a/qt5/src/poppler-document.cc b/qt5/src/poppler-document.cc
index 474f9055..4690f313 100644
--- a/qt5/src/poppler-document.cc
+++ b/qt5/src/poppler-document.cc
@@ -738,10 +738,9 @@ QString Document::metadata() const
QString result;
Catalog *catalog = m_doc->doc->getCatalog();
if (catalog && catalog->isOk()) {
- GooString *s = catalog->readMetadata();
+ std::unique_ptr<GooString> s = catalog->readMetadata();
if (s)
- result = UnicodeParsedString(s);
- delete s;
+ result = UnicodeParsedString(s.get());
}
return result;
}
diff --git a/qt6/src/poppler-document.cc b/qt6/src/poppler-document.cc
index 580d92a2..ac469637 100644
--- a/qt6/src/poppler-document.cc
+++ b/qt6/src/poppler-document.cc
@@ -714,10 +714,9 @@ QString Document::metadata() const
QString result;
Catalog *catalog = m_doc->doc->getCatalog();
if (catalog && catalog->isOk()) {
- GooString *s = catalog->readMetadata();
+ std::unique_ptr<GooString> s = catalog->readMetadata();
if (s)
- result = UnicodeParsedString(s);
- delete s;
+ result = UnicodeParsedString(s.get());
}
return result;
}
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index c923a6b8..e34f21fc 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -15,7 +15,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dom Lachowicz <cinamod at hotmail.com>
-// Copyright (C) 2007-2010, 2012, 2016-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2010, 2012, 2016-2021 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
// Copyright (C) 2011 Vittal Aithal <vittal.aithal at cognidox.com>
// Copyright (C) 2012, 2013, 2016-2018, 2021 Adrian Johnson <ajohnson at redneon.com>
@@ -732,10 +732,9 @@ static void printInfo(PDFDoc *doc, const UnicodeMap *uMap, long long filesize, b
}
bool hasMetadata = false;
- const GooString *metadata = doc->readMetadata();
+ std::unique_ptr<GooString> metadata = doc->readMetadata();
if (metadata) {
hasMetadata = true;
- delete metadata;
}
const std::set<std::string> docInfoStandardKeys { "Title", "Author", "Subject", "Keywords", "Creator", "Producer", "CreationDate", "ModDate", "Trapped" };
@@ -995,11 +994,10 @@ int main(int argc, char *argv[])
if (printMetadata) {
// print the metadata
- const GooString *metadata = doc->readMetadata();
+ const std::unique_ptr<GooString> metadata = doc->readMetadata();
if (metadata) {
fputs(metadata->c_str(), stdout);
fputc('\n', stdout);
- delete metadata;
}
} else if (printCustom) {
printCustomInfo(doc.get(), uMap);
More information about the poppler
mailing list