[poppler] poppler/PDFDoc.cc poppler/PDFDoc.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 9 14:14:31 UTC 2022


 poppler/PDFDoc.cc |   67 ++++++++----------------------------------------------
 poppler/PDFDoc.h  |   36 ++++++++++++++---------------
 2 files changed, 28 insertions(+), 75 deletions(-)

New commits:
commit 0eb4b4b578f02bbfd507039ab1077cbb1fde5aef
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Feb 9 14:58:55 2022 +0100

    Remove PDFDoc::init
    
    By having the initialization directly in the member definition we make
    sure that if ever we introduce a new constructor we will not forget to
    call init()

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 6acde17b..82affced 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -86,7 +86,6 @@
 #include "Link.h"
 #include "OutputDev.h"
 #include "Error.h"
-#include "ErrorCodes.h"
 #include "Lexer.h"
 #include "Parser.h"
 #include "SecurityHandler.h"
@@ -120,55 +119,25 @@
 
 #define pdfdocLocker() std::unique_lock<std::recursive_mutex> locker(mutex)
 
-void PDFDoc::init()
-{
-    ok = false;
-    errCode = errNone;
-    fileName = nullptr;
-    file = nullptr;
-    str = nullptr;
-    xref = nullptr;
-    linearization = nullptr;
-    catalog = nullptr;
-    hints = nullptr;
-    outline = nullptr;
-    startXRefPos = -1;
-    secHdlr = nullptr;
-    pageCache = nullptr;
-}
-
-PDFDoc::PDFDoc()
-{
-    init();
-}
+PDFDoc::PDFDoc() { }
 
-PDFDoc::PDFDoc(const GooString *fileNameA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback)
+PDFDoc::PDFDoc(const GooString *fileNameA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : fileName(fileNameA), guiData(guiDataA)
 {
 #ifdef _WIN32
-    int n, i;
-#endif
-
-    init();
-
-    fileName = fileNameA;
-    guiData = guiDataA;
-#ifdef _WIN32
-    n = fileName->getLength();
+    const int n = fileName->getLength();
     fileNameU = (wchar_t *)gmallocn(n + 1, sizeof(wchar_t));
-    for (i = 0; i < n; ++i) {
+    for (int i = 0; i < n; ++i) {
         fileNameU[i] = (wchar_t)(fileName->getChar(i) & 0xff);
     }
     fileNameU[n] = L'\0';
-#endif
 
-    // try to open file
-#ifdef _WIN32
     wchar_t *wFileName = (wchar_t *)utf8ToUtf16(fileName->c_str());
     file = GooFile::open(wFileName);
     gfree(wFileName);
 #else
     file = GooFile::open(fileName->toStr());
 #endif
+
     if (file == nullptr) {
         // fopen() has failed.
         // Keep a copy of the errno returned by fopen so that it can be
@@ -186,19 +155,14 @@ PDFDoc::PDFDoc(const GooString *fileNameA, const GooString *ownerPassword, const
 }
 
 #ifdef _WIN32
-PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback)
+PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
 {
     OSVERSIONINFO version;
-    int i;
-
-    init();
-
-    guiData = guiDataA;
 
     // save both Unicode and 8-bit copies of the file name
     GooString *fileNameG = new GooString();
     fileNameU = (wchar_t *)gmallocn(fileNameLen + 1, sizeof(wchar_t));
-    for (i = 0; i < fileNameLen; ++i) {
+    for (int i = 0; i < fileNameLen; ++i) {
         fileNameG->append((char)fileNameA[i]);
         fileNameU[i] = fileNameA[i];
     }
@@ -227,28 +191,17 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, Go
 }
 #endif
 
-PDFDoc::PDFDoc(BaseStream *strA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback)
+PDFDoc::PDFDoc(BaseStream *strA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
 {
-#ifdef _WIN32
-    int n, i;
-#endif
-
-    init();
-    guiData = guiDataA;
     if (strA->getFileName()) {
         fileName = strA->getFileName()->copy();
 #ifdef _WIN32
-        n = fileName->getLength();
+        const int n = fileName->getLength();
         fileNameU = (wchar_t *)gmallocn(n + 1, sizeof(wchar_t));
-        for (i = 0; i < n; ++i) {
+        for (int i = 0; i < n; ++i) {
             fileNameU[i] = (wchar_t)(fileName->getChar(i) & 0xff);
         }
         fileNameU[n] = L'\0';
-#endif
-    } else {
-        fileName = nullptr;
-#ifdef _WIN32
-        fileNameU = NULL;
 #endif
     }
     str = strA;
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 61bd74a2..d54bf7d9 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2005, 2009, 2014, 2015, 2017-2021 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2009, 2014, 2015, 2017-2022 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2008 Pino Toscano <pino at kde.org>
 // Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -59,6 +59,7 @@
 #include "Catalog.h"
 #include "Page.h"
 #include "Annot.h"
+#include "ErrorCodes.h"
 #include "Form.h"
 #include "OptionalContent.h"
 #include "Stream.h"
@@ -367,7 +368,6 @@ private:
     Hints *getHints();
 
     PDFDoc();
-    void init();
     bool setup(const GooString *ownerPassword, const GooString *userPassword, const std::function<void()> &xrefReconstructedCallback);
     bool checkFooter();
     void checkHeader();
@@ -381,37 +381,37 @@ private:
     Goffset getMainXRefEntriesOffset(bool tryingToReconstruct = false);
     long long strToLongLong(const char *s);
 
-    const GooString *fileName;
+    const GooString *fileName = nullptr;
 #ifdef _WIN32
-    wchar_t *fileNameU;
+    wchar_t *fileNameU = nullptr;
 #endif
-    GooFile *file;
-    BaseStream *str;
-    void *guiData;
+    GooFile *file = nullptr;
+    BaseStream *str = nullptr;
+    void *guiData = nullptr;
     int headerPdfMajorVersion;
     int headerPdfMinorVersion;
     PDFSubtype pdfSubtype;
     PDFSubtypePart pdfPart;
     PDFSubtypeConformance pdfConformance;
-    Linearization *linearization;
+    Linearization *linearization = nullptr;
     // linearizationState = 0: unchecked
     // linearizationState = 1: checked and valid
     // linearizationState = 2: checked and invalid
     int linearizationState;
-    XRef *xref;
-    SecurityHandler *secHdlr;
-    Catalog *catalog;
-    Hints *hints;
-    Outline *outline;
-    Page **pageCache;
-
-    bool ok;
-    int errCode;
+    XRef *xref = nullptr;
+    SecurityHandler *secHdlr = nullptr;
+    Catalog *catalog = nullptr;
+    Hints *hints = nullptr;
+    Outline *outline = nullptr;
+    Page **pageCache = nullptr;
+
+    bool ok = false;
+    int errCode = errNone;
     // If there is an error opening the PDF file with fopen() in the constructor,
     // then the POSIX errno will be here.
     int fopenErrno;
 
-    Goffset startXRefPos; // offset of last xref table
+    Goffset startXRefPos = -1; // offset of last xref table
     mutable std::recursive_mutex mutex;
 };
 


More information about the poppler mailing list