[poppler] 3 commits - cpp/poppler-document.cpp glib/poppler-document.cc poppler/GlobalParams.cc poppler/GlobalParams.h qt5/src qt5/tests test/gtk-test.cc test/pdf-fullrewrite.cc test/pdf-inspector.cc test/perf-test.cc utils/pdfattach.cc utils/pdfdetach.cc utils/pdffonts.cc utils/pdfimages.cc utils/pdfinfo.cc utils/pdfseparate.cc utils/pdfsig.cc utils/pdftocairo.cc utils/pdftohtml.cc utils/pdftoppm.cc utils/pdftops.cc utils/pdftotext.cc utils/pdfunite.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Nov 11 14:48:23 UTC 2019
cpp/poppler-document.cpp | 5 ++---
glib/poppler-document.cc | 8 ++++----
poppler/GlobalParams.cc | 2 +-
poppler/GlobalParams.h | 3 ++-
qt5/src/poppler-private.cc | 4 ++--
qt5/tests/check_optcontent.cpp | 8 ++++----
qt5/tests/check_strings.cpp | 4 ++--
test/gtk-test.cc | 4 +---
test/pdf-fullrewrite.cc | 3 +--
test/pdf-inspector.cc | 3 +--
test/perf-test.cc | 3 +--
utils/pdfattach.cc | 3 +--
utils/pdfdetach.cc | 6 ++----
utils/pdffonts.cc | 20 ++++++--------------
utils/pdfimages.cc | 3 +--
utils/pdfinfo.cc | 4 +---
utils/pdfseparate.cc | 3 +--
utils/pdfsig.cc | 3 +--
utils/pdftocairo.cc | 3 +--
utils/pdftohtml.cc | 4 +---
utils/pdftoppm.cc | 3 +--
utils/pdftops.cc | 3 +--
utils/pdftotext.cc | 4 +---
utils/pdfunite.cc | 3 +--
24 files changed, 40 insertions(+), 69 deletions(-)
New commits:
commit 020d2d0e6fb097a24a34e2be6180e3eedefc68dd
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Sat Nov 9 06:32:46 2019 +0100
Remove goto-based error handling in pdffonts.cc
Now that globalParams is a unique_ptr, there is no need
for these gotos anymore.
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index e5d193ea..9a8abc7b 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -94,10 +94,8 @@ static const ArgDesc argDesc[] = {
int main(int argc, char *argv[]) {
std::unique_ptr<GooString> ownerPW, userPW;
bool ok;
- int exitCode;
Win32Console win32Console(&argc, &argv);
- exitCode = 99;
// parse args
ok = parseArgs(argDesc, &argc, argv);
@@ -109,8 +107,8 @@ int main(int argc, char *argv[]) {
printUsage("pdffonts", "<PDF-file>", argDesc);
}
if (printVersion || printHelp)
- exitCode = 0;
- return exitCode;
+ return 0;
+ return 99;
}
std::string fileName(argv[1]);
@@ -132,8 +130,7 @@ int main(int argc, char *argv[]) {
auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW.get(), userPW.get()));
if (!doc->isOk()) {
- exitCode = 1;
- goto err1;
+ return 1;
}
// get page range
@@ -147,7 +144,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr,
"Wrong page range given: the first page (%d) can not be after the last page (%d).\n",
firstPage, lastPage);
- goto err1;
+ return 99;
}
// get the fonts
@@ -198,11 +195,7 @@ int main(int argc, char *argv[]) {
}
}
- exitCode = 0;
-
- err1:
-
- return exitCode;
+ return 0;
}
commit c6479d6cb7b57fea9319f24f8ab46e54aea7235d
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Sat Nov 2 21:31:30 2019 +0100
Remove obsolete label 'err1'
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index 4080c342..3e4fbbc7 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
if (!(uMap = globalParams->getTextEncoding())) {
error(errConfig, -1, "Couldn't get text encoding");
delete fileName;
- goto err1;
+ goto err0;
}
// open PDF file
@@ -331,7 +331,6 @@ int main(int argc, char *argv[]) {
delete file;
uMap->decRefCnt();
delete doc;
- err1:
err0:
return exitCode;
commit 759d190581f8ff069ecee9155313a8e69a2ca9c6
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Sat Nov 2 17:50:59 2019 +0100
Make globalParams a std::unique_ptr
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 498d9f78..1a797752 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -58,7 +58,7 @@ initer::initer()
std::lock_guard<std::mutex> lock{mutex};
if (!count) {
- globalParams = new GlobalParams(!data_dir.empty() ? data_dir.c_str() : nullptr);
+ globalParams = std::make_unique<GlobalParams>(!data_dir.empty() ? data_dir.c_str() : nullptr);
setErrorCallback(detail::error_function, nullptr);
}
count++;
@@ -71,8 +71,7 @@ initer::~initer()
if (count > 0) {
--count;
if (!count) {
- delete globalParams;
- globalParams = nullptr;
+ globalParams.reset();
}
}
}
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 22b3e4e2..5b00e64f 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -192,7 +192,7 @@ poppler_document_new_from_file (const char *uri,
char *filename;
if (!globalParams) {
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
}
filename = g_filename_from_uri (uri, nullptr, error);
@@ -254,7 +254,7 @@ poppler_document_new_from_data (char *data,
GooString *password_g;
if (!globalParams) {
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
}
// create stream
@@ -308,7 +308,7 @@ poppler_document_new_from_bytes (GBytes *bytes,
g_return_val_if_fail(error == nullptr || *error == nullptr, nullptr);
if (!globalParams) {
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
}
// create stream
@@ -361,7 +361,7 @@ poppler_document_new_from_stream (GInputStream *stream,
g_return_val_if_fail(length == (goffset)-1 || length > 0, NULL);
if (!globalParams) {
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
}
if (!G_IS_SEEKABLE(stream) || !g_seekable_can_seek(G_SEEKABLE(stream))) {
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index d737003f..8200f620 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -96,7 +96,7 @@
//------------------------------------------------------------------------
-GlobalParams *globalParams = nullptr;
+std::unique_ptr<GlobalParams> globalParams;
#if defined(ENABLE_RELOCATABLE) && defined(_WIN32)
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 25ad68d9..c7824524 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -44,6 +44,7 @@
#include "UnicodeMap.h"
#include <unordered_map>
#include <string>
+#include <memory>
#include <mutex>
#include <vector>
@@ -63,7 +64,7 @@ class SysFontList;
//------------------------------------------------------------------------
// The global parameters object.
-extern GlobalParams *globalParams;
+extern std::unique_ptr<GlobalParams> globalParams;
//------------------------------------------------------------------------
diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 6553eb08..74dbe960 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -249,7 +249,7 @@ namespace Debug {
if ( count == 0 )
{
utf8Map = nullptr;
- delete globalParams;
+ globalParams.reset();
}
}
@@ -265,7 +265,7 @@ namespace Debug {
if ( count == 0 )
{
utf8Map = nullptr;
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
setErrorCallback(qt5ErrorFunction, nullptr);
}
count ++;
diff --git a/qt5/tests/check_optcontent.cpp b/qt5/tests/check_optcontent.cpp
index d1372307..c9f23a45 100644
--- a/qt5/tests/check_optcontent.cpp
+++ b/qt5/tests/check_optcontent.cpp
@@ -89,7 +89,7 @@ void TestOptionalContent::checkNoOptionalContent()
void TestOptionalContent::checkIsVisible()
{
GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf");
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
PDFDoc *doc = new PDFDoc( fileName );
QVERIFY( doc );
@@ -157,12 +157,12 @@ void TestOptionalContent::checkIsVisible()
QCOMPARE( ocgs->optContentIsVisible( &obj ), false );
delete doc;
- delete globalParams;
+ globalParams.reset();
}
void TestOptionalContent::checkVisibilitySetting()
{
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf");
PDFDoc *doc = new PDFDoc( fileName );
QVERIFY( doc );
@@ -363,7 +363,7 @@ void TestOptionalContent::checkVisibilitySetting()
QCOMPARE( ocgs->optContentIsVisible( &obj ), false );
delete doc;
- delete globalParams;
+ globalParams.reset();
}
void TestOptionalContent::checkRadioButtons()
diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp
index e7b3f990..4f38b315 100644
--- a/qt5/tests/check_strings.cpp
+++ b/qt5/tests/check_strings.cpp
@@ -57,14 +57,14 @@ void TestStrings::initTestCase()
qRegisterMetaType<GooString*>("GooString*");
qRegisterMetaType<Unicode*>("Unicode*");
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
}
void TestStrings::cleanupTestCase()
{
qDeleteAll(m_gooStrings);
- delete globalParams;
+ globalParams.reset();
}
void TestStrings::check_unicodeToQString_data()
diff --git a/test/gtk-test.cc b/test/gtk-test.cc
index 24fd39ce..f103185d 100644
--- a/test/gtk-test.cc
+++ b/test/gtk-test.cc
@@ -369,7 +369,7 @@ main (int argc, char *argv [])
gtk_init (&argc, &argv);
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
for (int i = 0; file_arguments[i]; i++) {
View *view;
@@ -399,7 +399,5 @@ main (int argc, char *argv [])
gtk_main ();
- delete globalParams;
-
return 0;
}
diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index a9e3e8ef..2cb4b028 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -75,7 +75,7 @@ int main (int argc, char *argv[])
}
// load input document
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
doc = new PDFDoc(inputName, ownerPW, userPW);
if (!doc->isOk()) {
fprintf(stderr, "Error loading input document\n");
@@ -107,7 +107,6 @@ int main (int argc, char *argv[])
done:
delete docOut;
delete doc;
- delete globalParams;
delete userPW;
delete ownerPW;
return res;
diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index d2df5e30..17f5fc69 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -334,7 +334,7 @@ main (int argc, char *argv [])
gtk_init (&argc, &argv);
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
globalParams->setProfileCommands (true);
globalParams->setPrintCommands (true);
@@ -354,7 +354,6 @@ main (int argc, char *argv [])
inspector->run ();
delete inspector;
- delete globalParams;
return 0;
}
diff --git a/test/perf-test.cc b/test/perf-test.cc
index 83c8c5f8..2b0d9c4e 100644
--- a/test/perf-test.cc
+++ b/test/perf-test.cc
@@ -1237,7 +1237,7 @@ int main(int argc, char **argv)
assert(gArgsListRoot);
SplashColorsInit();
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (!globalParams)
return 1;
globalParams->setErrQuiet(false);
@@ -1270,7 +1270,6 @@ int main(int argc, char **argv)
fclose(outFile);
PreviewBitmapDestroy();
StrList_Destroy(&gArgsListRoot);
- delete globalParams;
free(gOutFileName);
return 0;
}
diff --git a/utils/pdfattach.cc b/utils/pdfattach.cc
index e4f40a32..39f31026 100644
--- a/utils/pdfattach.cc
+++ b/utils/pdfattach.cc
@@ -70,8 +70,7 @@ int main(int argc, char *argv[]) {
const GooString attachFilePath(argv[2]);
// init GlobalParams
- auto gp = std::make_unique<GlobalParams>();
- globalParams = gp.get();
+ globalParams = std::make_unique<GlobalParams>();
// open PDF file
std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(pdfFileName, nullptr, nullptr));
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index 52b5f946..4080c342 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -123,7 +123,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString(argv[1]);
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (textEncName[0]) {
globalParams->setTextEncoding(textEncName);
}
@@ -332,7 +332,6 @@ int main(int argc, char *argv[]) {
uMap->decRefCnt();
delete doc;
err1:
- delete globalParams;
err0:
return exitCode;
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index fe98b8d1..e5d193ea 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
}
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
// open PDF file
if (ownerPassword[0] != '\001') {
@@ -201,7 +201,6 @@ int main(int argc, char *argv[]) {
exitCode = 0;
err1:
- delete globalParams;
return exitCode;
}
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index 1dfe3027..ad65932e 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
imgRoot = argv[2];
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (quiet) {
globalParams->setErrQuiet(quiet);
}
@@ -227,7 +227,6 @@ int main(int argc, char *argv[]) {
// clean up
err1:
delete doc;
- delete globalParams;
err0:
return exitCode;
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 053b03b3..0120d919 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -868,11 +868,10 @@ int main(int argc, char *argv[]) {
printStructure = true;
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (printEnc) {
printEncodings();
- delete globalParams;
exitCode = 0;
goto err0;
}
@@ -985,7 +984,6 @@ int main(int argc, char *argv[]) {
delete doc;
delete fileName;
err1:
- delete globalParams;
err0:
return exitCode;
diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
index 935b04a0..e4d1f49d 100644
--- a/utils/pdfseparate.cc
+++ b/utils/pdfseparate.cc
@@ -168,12 +168,11 @@ main (int argc, char *argv[])
exitCode = 0;
goto err0;
}
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
ok = extractPages (argv[1], argv[2]);
if (ok) {
exitCode = 0;
}
- delete globalParams;
err0:
diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index ab545add..5cb3a554 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
SignatureInfo *sig_info = nullptr;
char *time_str = nullptr;
std::vector<FormWidgetSignature*> sig_widgets;
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
Win32Console win32Console(&argc, &argv);
int exitCode = 99;
@@ -277,7 +277,6 @@ int main(int argc, char *argv[])
end:
delete fileName;
delete doc;
- delete globalParams;
return exitCode;
}
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 7bdbb679..49ffe86f 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -1079,7 +1079,7 @@ int main(int argc, char *argv[]) {
if (printdlg)
printToWin32 = true;
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (quiet) {
globalParams->setErrQuiet(quiet);
}
@@ -1262,7 +1262,6 @@ int main(int argc, char *argv[]) {
// clean up
delete cairoOut;
delete doc;
- delete globalParams;
if (fileName)
delete fileName;
if (outputName)
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index a28c1518..43f9f4af 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
//errorInit();
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (errQuiet) {
globalParams->setErrQuiet(errQuiet);
@@ -440,7 +440,6 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Your pdftohtml was built without splash backend support. It is needed for the option you want to use.\n");
delete htmlOut;
delete htmlFileName;
- delete globalParams;
delete fileName;
delete doc;
return -1;
@@ -462,7 +461,6 @@ int main(int argc, char *argv[]) {
error:
if(doc) delete doc;
delete fileName;
- if(globalParams) delete globalParams;
if(htmlFileName) delete htmlFileName;
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 48a39f78..2ac1bb06 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -440,7 +440,7 @@ int main(int argc, char *argv[]) {
}
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (enableFreeTypeStr[0]) {
if (!globalParams->setEnableFreeType(enableFreeTypeStr)) {
fprintf(stderr, "Bad '-freetype' value on command line\n");
@@ -642,7 +642,6 @@ int main(int argc, char *argv[]) {
// clean up
err1:
delete doc;
- delete globalParams;
err0:
return exitCode;
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index 00ec7892..005c94d6 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -269,7 +269,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString(argv[1]);
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (origPageSizes) {
paperWidth = paperHeight = -1;
}
@@ -434,7 +434,6 @@ int main(int argc, char *argv[]) {
delete doc;
delete fileName;
err0:
- delete globalParams;
return exitCode;
}
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index ccf91f01..1c81cfa9 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -212,11 +212,10 @@ int main(int argc, char *argv[]) {
}
// read config file
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
if (printEnc) {
printEncodings();
- delete globalParams;
exitCode = 0;
goto err0;
}
@@ -433,7 +432,6 @@ int main(int argc, char *argv[]) {
delete fileName;
uMap->decRefCnt();
err1:
- delete globalParams;
err0:
return exitCode;
diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index f5fca6a7..75949d78 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -161,7 +161,7 @@ int main (int argc, char *argv[])
return exitCode;
}
exitCode = 0;
- globalParams = new GlobalParams();
+ globalParams = std::make_unique<GlobalParams>();
for (i = 1; i < argc - 1; i++) {
GooString *gfileName = new GooString(argv[i]);
@@ -405,6 +405,5 @@ int main (int argc, char *argv[])
delete yRef;
delete countRef;
for (i = 0; i < (int) docs.size (); i++) delete docs[i];
- delete globalParams;
return exitCode;
}
More information about the poppler
mailing list