e946be
diff -up texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc
e946be
--- texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler	2016-11-25 13:24:37.000000000 -0500
e946be
+++ texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc	2018-04-30 13:26:10.442342831 -0400
e946be
@@ -1,5 +1,5 @@
e946be
 /*
e946be
-Copyright 1996-2016 Han The Thanh, <thanh@pdftex.org>
e946be
+Copyright 1996-2017 Han The Thanh, <thanh@pdftex.org>
e946be
 
e946be
 This file is part of pdfTeX.
e946be
 
e946be
@@ -17,6 +17,15 @@ You should have received a copy of the G
e946be
 with this program.  If not, see <http://www.gnu.org/licenses/>.
e946be
 */
e946be
 
e946be
+/*
e946be
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
e946be
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
e946be
+by Arch Linux. A little modifications are made to avoid a crash for
e946be
+some kind of pdf images, such as figure_missing.pdf in gnuplot.
e946be
+The poppler should be 0.59.0 or newer versions.
e946be
+POPPLER_VERSION should be defined.
e946be
+*/
e946be
+
e946be
 /* Do this early in order to avoid a conflict between
e946be
    MINGW32 <rpcndr.h> defining 'boolean' as 'unsigned char' and
e946be
    <kpathsea/types.h> defining Pascal's boolean as 'int'.
e946be
@@ -39,10 +48,7 @@ with this program.  If not, see 
e946be
 #include <goo/gfile.h>
e946be
 #define GString GooString
e946be
 #else
e946be
-#include <aconf.h>
e946be
-#include <GString.h>
e946be
-#include <gmem.h>
e946be
-#include <gfile.h>
e946be
+#error POPPLER_VERSION should be defined.
e946be
 #endif
e946be
 #include <assert.h>
e946be
 
e946be
@@ -84,31 +90,6 @@ extern integer zround(double);
e946be
 #define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
e946be
 #define MASK_SUPPRESS_PTEX_INFODICT   0x08
e946be
 
e946be
-// PdfObject encapsulates the xpdf Object type,
e946be
-// and properly frees its resources on destruction.
e946be
-// Use obj-> to access members of the Object,
e946be
-// and &obj to get a pointer to the object.
e946be
-// It is no longer necessary to call Object::free explicitely.
e946be
-
e946be
-class PdfObject {
e946be
-  public:
e946be
-    PdfObject() {               // nothing
e946be
-    } ~PdfObject() {
e946be
-        iObject.free();
e946be
-    }
e946be
-    Object *operator->() {
e946be
-        return &iObject;
e946be
-    }
e946be
-    Object *operator&() {
e946be
-        return &iObject;
e946be
-    }
e946be
-  private:                     // no copying or assigning
e946be
-    PdfObject(const PdfObject &);
e946be
-    void operator=(const PdfObject &);
e946be
-  public:
e946be
-    Object iObject;
e946be
-};
e946be
-
e946be
 // When copying the Resources of the selected page, all objects are copied
e946be
 // recusively top-down. Indirect objects however are not fetched during
e946be
 // copying, but get a new object number from pdfTeX and then will be
e946be
@@ -212,18 +193,6 @@ static void delete_document(PdfDocument
e946be
     delete pdf_doc;
e946be
 }
e946be
 
e946be
-// Replacement for
e946be
-//      Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
e946be
-
e946be
-static void initDictFromDict(PdfObject & obj, Dict * dict)
e946be
-{
e946be
-    obj->initDict(xref);
e946be
-    for (int i = 0, l = dict->getLength(); i < l; i++) {
e946be
-        Object obj1;
e946be
-        obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
e946be
-    }
e946be
-}
e946be
-
e946be
 // --------------------------------------------------------------------
e946be
 
e946be
 static int addEncoding(GfxFont * gfont)
e946be
@@ -320,10 +289,10 @@ static void copyName(char *s)
e946be
 
e946be
 static void copyDictEntry(Object * obj, int i)
e946be
 {
e946be
-    PdfObject obj1;
e946be
+    Object obj1;
e946be
     copyName(obj->dictGetKey(i));
e946be
     pdf_puts(" ");
e946be
-    obj->dictGetValNF(i, &obj1);
e946be
+    obj1 = obj->dictGetValNF(i);
e946be
     copyObject(&obj1);
e946be
     pdf_puts("\n");
e946be
 }
e946be
@@ -376,17 +345,17 @@ static void copyStream(Stream * str)
e946be
 static void copyProcSet(Object * obj)
e946be
 {
e946be
     int i, l;
e946be
-    PdfObject procset;
e946be
+    Object procset;
e946be
     if (!obj->isArray())
e946be
         pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
e946be
                     obj->getTypeName());
e946be
     pdf_puts("/ProcSet [ ");
e946be
     for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
e946be
-        obj->arrayGetNF(i, &procset);
e946be
-        if (!procset->isName())
e946be
+        procset = obj->arrayGetNF(i);
e946be
+        if (!procset.isName())
e946be
             pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
e946be
-                        procset->getTypeName());
e946be
-        copyName(procset->getName());
e946be
+                        procset.getTypeName());
e946be
+        copyName(procset.getName());
e946be
         pdf_puts(" ");
e946be
     }
e946be
     pdf_puts("]\n");
e946be
@@ -394,10 +363,29 @@ static void copyProcSet(Object * obj)
e946be
 
e946be
 #define REPLACE_TYPE1C true
e946be
 
e946be
+static bool embeddableFont(Object * fontdesc)
e946be
+{
e946be
+    Object fontfile, ffsubtype;
e946be
+
e946be
+    if (!fontdesc->isDict())
e946be
+        return false;
e946be
+    fontfile = fontdesc->dictLookup("FontFile");
e946be
+    if (fontfile.isStream())
e946be
+        return true;
e946be
+    if (REPLACE_TYPE1C) {
e946be
+        fontfile = fontdesc->dictLookup("FontFile3");
e946be
+        if (!fontfile.isStream())
e946be
+            return false;
e946be
+        ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
e946be
+        return ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C");
e946be
+    }
e946be
+    return false;
e946be
+}
e946be
+
e946be
 static void copyFont(char *tag, Object * fontRef)
e946be
 {
e946be
-    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
e946be
-        fontfile, ffsubtype, stemV;
e946be
+    Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
e946be
+        stemV;
e946be
     GfxFont *gfont;
e946be
     fd_entry *fd;
e946be
     fm_entry *fontmap;
e946be
@@ -413,33 +401,39 @@ static void copyFont(char *tag, Object *
e946be
     }
e946be
     // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
e946be
     // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
e946be
-    if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
e946be
-        && fontdict->dictLookup("Subtype", &subtype)->isName()
e946be
-        && !strcmp(subtype->getName(), "Type1")
e946be
-        && fontdict->dictLookup("BaseFont", &basefont)->isName()
e946be
-        && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
e946be
-        && fontdescRef->fetch(xref, &fontdesc)->isDict()
e946be
-        && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
e946be
-            || (REPLACE_TYPE1C
e946be
-                && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
e946be
-                && fontfile->streamGetDict()->lookup("Subtype",
e946be
-                                                     &ffsubtype)->isName()
e946be
-                && !strcmp(ffsubtype->getName(), "Type1C")))
e946be
-        && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
e946be
+    fontdict = fontRef->fetch(xref);
e946be
+    fontdesc = Object(objNull);
e946be
+    if (fontdict.isDict()) {
e946be
+        subtype = fontdict.dictLookup("Subtype");
e946be
+        basefont = fontdict.dictLookup("BaseFont");
e946be
+        fontdescRef = fontdict.dictLookupNF("FontDescriptor");
e946be
+        if (fontdescRef.isRef()) {
e946be
+            fontdesc = fontdescRef.fetch(xref);
e946be
+        }
e946be
+    }
e946be
+    if (!fixedinclusioncopyfont && fontdict.isDict()
e946be
+        && subtype.isName()
e946be
+        && !strcmp(subtype.getName(), "Type1")
e946be
+        && basefont.isName()
e946be
+        && fontdescRef.isRef()
e946be
+        && fontdesc.isDict()
e946be
+        && embeddableFont(&fontdesc)
e946be
+        && (fontmap = lookup_fontmap(basefont.getName())) != NULL) {
e946be
         // round /StemV value, since the PDF input is a float
e946be
         // (see Font Descriptors in PDF reference), but we only store an
e946be
         // integer, since we don't want to change the struct.
e946be
-        fontdesc->dictLookup("StemV", &stemV);
e946be
-        fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
e946be
-        if (fontdesc->dictLookup("CharSet", &charset) &&
e946be
-            charset->isString() && is_subsetable(fontmap))
e946be
-            epdf_mark_glyphs(fd, charset->getString()->getCString());
e946be
+        stemV = fontdesc.dictLookup("StemV");
e946be
+        fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
e946be
+        charset = fontdesc.dictLookup("CharSet");
e946be
+        if (!charset.isNull() &&
e946be
+            charset.isString() && is_subsetable(fontmap))
e946be
+            epdf_mark_glyphs(fd, charset.getString()->getCString());
e946be
         else
e946be
             embed_whole_font(fd);
e946be
-        addFontDesc(fontdescRef->getRef(), fd);
e946be
+        addFontDesc(fontdescRef.getRef(), fd);
e946be
         copyName(tag);
e946be
         gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
e946be
-                                  fontdict->getDict());
e946be
+                                  fontdict.getDict());
e946be
         pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
e946be
                                        addEncoding(gfont)));
e946be
     } else {
e946be
@@ -451,24 +445,24 @@ static void copyFont(char *tag, Object *
e946be
 
e946be
 static void copyFontResources(Object * obj)
e946be
 {
e946be
-    PdfObject fontRef;
e946be
+    Object fontRef;
e946be
     int i, l;
e946be
     if (!obj->isDict())
e946be
         pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
e946be
                     obj->getTypeName());
e946be
     pdf_puts("/Font << ");
e946be
     for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
e946be
-        obj->dictGetValNF(i, &fontRef);
e946be
-        if (fontRef->isRef())
e946be
+        fontRef = obj->dictGetValNF(i);
e946be
+        if (fontRef.isRef())
e946be
             copyFont(obj->dictGetKey(i), &fontRef);
e946be
-        else if (fontRef->isDict()) {   // some programs generate pdf with embedded font object
e946be
+        else if (fontRef.isDict()) {   // some programs generate pdf with embedded font object
e946be
             copyName(obj->dictGetKey(i));
e946be
             pdf_puts(" ");
e946be
             copyObject(&fontRef);
e946be
         }
e946be
         else
e946be
             pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
e946be
-                        fontRef->getTypeName());
e946be
+                        fontRef.getTypeName());
e946be
     }
e946be
     pdf_puts(">>\n");
e946be
 }
e946be
@@ -557,7 +551,7 @@ static char *convertNumToPDF(double n)
e946be
 
e946be
 static void copyObject(Object * obj)
e946be
 {
e946be
-    PdfObject obj1;
e946be
+    Object obj1;
e946be
     int i, l, c;
e946be
     Ref ref;
e946be
     char *p;
e946be
@@ -601,8 +595,8 @@ static void copyObject(Object * obj)
e946be
     } else if (obj->isArray()) {
e946be
         pdf_puts("[");
e946be
         for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
e946be
-            obj->arrayGetNF(i, &obj1);
e946be
-            if (!obj1->isName())
e946be
+            obj1 = obj->arrayGetNF(i);
e946be
+            if (!obj1.isName())
e946be
                 pdf_puts(" ");
e946be
             copyObject(&obj1);
e946be
         }
e946be
@@ -612,9 +606,8 @@ static void copyObject(Object * obj)
e946be
         copyDict(obj);
e946be
         pdf_puts(">>");
e946be
     } else if (obj->isStream()) {
e946be
-        initDictFromDict(obj1, obj->streamGetDict());
e946be
         pdf_puts("<<\n");
e946be
-        copyDict(&obj1);
e946be
+        copyDict(obj->getStream()->getDictObject());
e946be
         pdf_puts(">>\n");
e946be
         pdf_puts("stream\n");
e946be
         copyStream(obj->getStream()->getUndecodedStream());
e946be
@@ -638,9 +631,8 @@ static void writeRefs()
e946be
     InObj *r;
e946be
     for (r = inObjList; r != 0; r = r->next) {
e946be
         if (!r->written) {
e946be
-            Object obj1;
e946be
             r->written = 1;
e946be
-            xref->fetch(r->ref.num, r->ref.gen, &obj1);
e946be
+            Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
e946be
             if (r->type == objFont) {
e946be
                 assert(!obj1.isStream());
e946be
                 pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
e946be
@@ -656,7 +648,6 @@ static void writeRefs()
e946be
                 pdf_puts("\n");
e946be
                 pdfendobj();
e946be
             }
e946be
-            obj1.free();
e946be
         }
e946be
     }
e946be
 }
e946be
@@ -685,7 +676,7 @@ static void writeEncodings()
e946be
 #ifdef POPPLER_VERSION
e946be
         r->font->decRefCnt();
e946be
 #else
e946be
-        delete r->font;
e946be
+#error POPPLER_VERSION should be defined.
e946be
 #endif
e946be
         delete r;
e946be
     }
e946be
@@ -728,7 +719,7 @@ read_pdf_info(char *image_name, char *pa
e946be
 #ifdef POPPLER_VERSION
e946be
     int pdf_major_version_found, pdf_minor_version_found;
e946be
 #else
e946be
-    float pdf_version_found, pdf_version_wanted;
e946be
+#error POPPLER_VERSION should be defined.
e946be
 #endif
e946be
     // initialize
e946be
     if (!isInit) {
e946be
@@ -760,19 +751,7 @@ read_pdf_info(char *image_name, char *pa
e946be
         }
e946be
     }
e946be
 #else
e946be
-    pdf_version_found = pdf_doc->doc->getPDFVersion();
e946be
-    pdf_version_wanted = 1 + (minor_pdf_version_wanted * 0.1);
e946be
-    if (pdf_version_found > pdf_version_wanted + 0.01) {
e946be
-        char msg[] =
e946be
-            "PDF inclusion: found PDF version <%.1f>, but at most version <%.1f> allowed";
e946be
-        if (pdf_inclusion_errorlevel > 0) {
e946be
-            pdftex_fail(msg, pdf_version_found, pdf_version_wanted);
e946be
-        } else if (pdf_inclusion_errorlevel < 0) {
e946be
-            ; /* do nothing */
e946be
-        } else { /* = 0, give warning */
e946be
-            pdftex_warn(msg, pdf_version_found, pdf_version_wanted);
e946be
-        }
e946be
-    }
e946be
+#error POPPLER_VERSION should be defined.
e946be
 #endif
e946be
     epdf_num_pages = pdf_doc->doc->getCatalog()->getNumPages();
e946be
     if (page_name) {
e946be
@@ -839,8 +818,8 @@ void write_epdf(void)
e946be
     Page *page;
e946be
     Ref *pageRef;
e946be
     Dict *pageDict;
e946be
-    PdfObject contents, obj1, obj2, pageObj, dictObj;
e946be
-    PdfObject groupDict;
e946be
+    Object contents, obj1, obj2, pageObj, dictObj;
e946be
+    Object groupDict;
e946be
     bool writeSepGroup = false;
e946be
     Object info;
e946be
     char *key;
e946be
@@ -867,8 +846,8 @@ void write_epdf(void)
e946be
     encodingList = 0;
e946be
     page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
e946be
     pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
e946be
-    xref->fetch(pageRef->num, pageRef->gen, &pageObj);
e946be
-    pageDict = pageObj->getDict();
e946be
+    pageObj = xref->fetch(pageRef->num, pageRef->gen);
e946be
+    pageDict = pageObj.getDict();
e946be
     rotate = page->getRotate();
e946be
     PDFRectangle *pagebox;
e946be
     // write the Page header
e946be
@@ -886,7 +865,7 @@ void write_epdf(void)
e946be
         pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
e946be
     }
e946be
     if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
e946be
-        pdf_doc->doc->getDocInfoNF(&info;;
e946be
+        info = pdf_doc->doc->getDocInfoNF();
e946be
         if (info.isRef()) {
e946be
             // the info dict must be indirect (PDF Ref p. 61)
e946be
             pdf_printf("/%s.InfoDict ", pdfkeyprefix);
e946be
@@ -942,14 +921,14 @@ void write_epdf(void)
e946be
     pdf_puts(stripzeros(s));
e946be
 
e946be
     // Metadata validity check (as a stream it must be indirect)
e946be
-    pageDict->lookupNF("Metadata", &dictObj);
e946be
-    if (!dictObj->isNull() && !dictObj->isRef())
e946be
+    dictObj = pageDict->lookupNF("Metadata");
e946be
+    if (!dictObj.isNull() && !dictObj.isRef())
e946be
         pdftex_warn("PDF inclusion: /Metadata must be indirect object");
e946be
 
e946be
     // copy selected items in Page dictionary except Resources & Group
e946be
     for (i = 0; pageDictKeys[i] != NULL; i++) {
e946be
-        pageDict->lookupNF(pageDictKeys[i], &dictObj);
e946be
-        if (!dictObj->isNull()) {
e946be
+        dictObj = pageDict->lookupNF(pageDictKeys[i]);
e946be
+        if (!dictObj.isNull()) {
e946be
             pdf_newline();
e946be
             pdf_printf("/%s ", pageDictKeys[i]);
e946be
             copyObject(&dictObj); // preserves indirection
e946be
@@ -957,8 +936,8 @@ void write_epdf(void)
e946be
     } 
e946be
 
e946be
     // handle page group
e946be
-    pageDict->lookupNF("Group", &dictObj);
e946be
-    if (!dictObj->isNull()) {
e946be
+    dictObj = pageDict->lookupNF("Group");
e946be
+    if (!dictObj.isNull()) {
e946be
         if (pdfpagegroupval == 0) { 
e946be
             // another pdf with page group was included earlier on the
e946be
             // same page; copy the Group entry as is.  See manual for
e946be
@@ -972,11 +951,36 @@ void write_epdf(void)
e946be
             copyObject(&dictObj);
e946be
         } else {
e946be
             // write Group dict as a separate object, since the Page dict also refers to it
e946be
-            pageDict->lookup("Group", &dictObj);
e946be
-            if (!dictObj->isDict())
e946be
+            dictObj = pageDict->lookup("Group");
e946be
+            if (!dictObj.isDict())
e946be
                 pdftex_fail("PDF inclusion: /Group dict missing");
e946be
             writeSepGroup = true;
e946be
-            initDictFromDict(groupDict, page->getGroup());
e946be
+/*
e946be
+This part is only a single line
e946be
+            groupDict = Object(page->getGroup());
e946be
+in the original patch. In this case, however, pdftex crashes at
e946be
+"delete pdf_doc->doc" in "delete_document()" for inclusion of some
e946be
+kind of pdf images, for example, figure_missing.pdf in gnuplot.
e946be
+A change
e946be
+            groupDict = Object(page->getGroup()).copy();
e946be
+does not improve the situation.
e946be
+The changes below seem to work fine. 
e946be
+*/
e946be
+// begin modification
e946be
+            groupDict = pageDict->lookup("Group");
e946be
+            const Dict& dic1 = page->getGroup();
e946be
+            const Dict& dic2 = groupDict.getDict();
e946be
+            // replace dic2 in groupDict with dic1
e946be
+            l = dic2.getLength();
e946be
+            for (i = 0; i < l; i++) {
e946be
+                groupDict.dictRemove(dic2.getKey(i));
e946be
+            }
e946be
+            l = dic1.getLength();
e946be
+            for (i = 0; i < l; i++) {
e946be
+                groupDict.dictAdd(copyString(dic1.getKey(i)),
e946be
+                                  dic1.getValNF(i));
e946be
+            }
e946be
+// end modification
e946be
             pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
e946be
         }
e946be
     }
e946be
@@ -989,14 +993,14 @@ void write_epdf(void)
e946be
         pdftex_warn
e946be
             ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
e946be
     } else {
e946be
-        initDictFromDict(obj1, page->getResourceDict());
e946be
+        Object *obj1 = page->getResourceDictObject();
e946be
         if (!obj1->isDict())
e946be
             pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
e946be
                         obj1->getTypeName());
e946be
         pdf_newline();
e946be
         pdf_puts("/Resources <<\n");
e946be
         for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
e946be
-            obj1->dictGetVal(i, &obj2);
e946be
+            obj2 = obj1->dictGetVal(i);
e946be
             key = obj1->dictGetKey(i);
e946be
             if (strcmp("Font", key) == 0)
e946be
                 copyFontResources(&obj2);
e946be
@@ -1009,8 +1013,8 @@ void write_epdf(void)
e946be
     }
e946be
 
e946be
     // write the page contents
e946be
-    page->getContents(&contents);
e946be
-    if (contents->isStream()) {
e946be
+    contents = page->getContents();
e946be
+    if (contents.isStream()) {
e946be
 
e946be
         // Variant A: get stream and recompress under control
e946be
         // of \pdfcompresslevel
e946be
@@ -1021,36 +1025,35 @@ void write_epdf(void)
e946be
 
e946be
         // Variant B: copy stream without recompressing
e946be
         //
e946be
-        contents->streamGetDict()->lookup("F", &obj1);
e946be
-        if (!obj1->isNull()) {
e946be
+        obj1 = contents.streamGetDict()->lookup("F");
e946be
+        if (!obj1.isNull()) {
e946be
             pdftex_fail("PDF inclusion: Unsupported external stream");
e946be
         }
e946be
-        contents->streamGetDict()->lookup("Length", &obj1);
e946be
-        assert(!obj1->isNull());
e946be
+        obj1 = contents.streamGetDict()->lookup("Length");
e946be
+        assert(!obj1.isNull());
e946be
         pdf_puts("/Length ");
e946be
         copyObject(&obj1);
e946be
         pdf_puts("\n");
e946be
-        contents->streamGetDict()->lookup("Filter", &obj1);
e946be
-        if (!obj1->isNull()) {
e946be
+        obj1 = contents.streamGetDict()->lookup("Filter");
e946be
+        if (!obj1.isNull()) {
e946be
             pdf_puts("/Filter ");
e946be
             copyObject(&obj1);
e946be
             pdf_puts("\n");
e946be
-            contents->streamGetDict()->lookup("DecodeParms", &obj1);
e946be
-            if (!obj1->isNull()) {
e946be
+            obj1 = contents.streamGetDict()->lookup("DecodeParms");
e946be
+            if (!obj1.isNull()) {
e946be
                 pdf_puts("/DecodeParms ");
e946be
                 copyObject(&obj1);
e946be
                 pdf_puts("\n");
e946be
             }
e946be
         }
e946be
         pdf_puts(">>\nstream\n");
e946be
-        copyStream(contents->getStream()->getUndecodedStream());
e946be
+        copyStream(contents.getStream()->getUndecodedStream());
e946be
         pdfendstream();
e946be
-    } else if (contents->isArray()) {
e946be
+    } else if (contents.isArray()) {
e946be
         pdfbeginstream();
e946be
-        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
e946be
-            Object contentsobj;
e946be
-            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
e946be
-            contentsobj.free();
e946be
+        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
e946be
+            Object contentsobj = contents.arrayGet(i);
e946be
+            copyStream(contentsobj.getStream());
e946be
             if (i < l - 1)
e946be
                 pdf_newline();  // add a newline after each stream except the last
e946be
         }
e946be
diff -up texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc
e946be
--- texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler	2018-04-30 13:32:27.005472583 -0400
e946be
+++ texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc	2018-04-30 13:38:12.805326988 -0400
e946be
@@ -16,6 +16,14 @@ GNU General Public License for more deta
e946be
 You should have received a copy of the GNU General Public License along
e946be
 with this program.  If not, see <http://www.gnu.org/licenses/>.
e946be
 */
e946be
+
e946be
+/*
e946be
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
e946be
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
e946be
+by Arch Linux. The poppler should be 0.59.0 or newer versions.
e946be
+POPPLER_VERSION should be defined.
e946be
+*/
e946be
+
e946be
 #include <w2c/config.h>
e946be
 
e946be
 #include <stdlib.h>
e946be
@@ -32,10 +40,7 @@ with this program.  If not, see 
e946be
 #include <goo/gmem.h>
e946be
 #include <goo/gfile.h>
e946be
 #else
e946be
-#include <aconf.h>
e946be
-#include <GString.h>
e946be
-#include <gmem.h>
e946be
-#include <gfile.h>
e946be
+#error POPPLER_VERSION should be defined.
e946be
 #endif
e946be
 #include <assert.h>
e946be
 
e946be
@@ -86,22 +91,20 @@ int main(int argc, char *argv[])
e946be
             objgen = atoi(argv[3]);
e946be
     }
e946be
     xref = doc->getXRef();
e946be
-    catalogDict.initNull();
e946be
-    xref->getCatalog(&catalogDict);
e946be
+    catalogDict = xref->getCatalog();
e946be
     if (!catalogDict.isDict("Catalog")) {
e946be
         fprintf(stderr, "No Catalog found\n");
e946be
         exit(1);
e946be
     }
e946be
-    srcStream.initNull();
e946be
+    srcStream = Object(objNull);
e946be
     if (objnum == 0) {
e946be
-        catalogDict.dictLookup("SourceObject", &srcStream);
e946be
+        srcStream = catalogDict.dictLookup("SourceObject");
e946be
         static char const_SourceFile[] = "SourceFile";
e946be
         if (!srcStream.isStream(const_SourceFile)) {
e946be
             fprintf(stderr, "No SourceObject found\n");
e946be
             exit(1);
e946be
         }
e946be
-        srcName.initNull();
e946be
-        srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
e946be
+        srcName = srcStream.getStream()->getDict()->lookup("SourceName");
e946be
         if (!srcName.isString()) {
e946be
             fprintf(stderr, "No SourceName found\n");
e946be
             exit(1);
e946be
@@ -110,7 +113,7 @@ int main(int argc, char *argv[])
e946be
         // We cannot free srcName, as objname shares its string.
e946be
         // srcName.free();
e946be
     } else if (objnum > 0) {
e946be
-        xref->fetch(objnum, objgen, &srcStream);
e946be
+        srcStream = xref->fetch(objnum, objgen);
e946be
         if (!srcStream.isStream()) {
e946be
             fprintf(stderr, "Not a Stream object\n");
e946be
             exit(1);
e946be
@@ -160,26 +163,24 @@ int main(int argc, char *argv[])
e946be
                 int localOffset = 0;
e946be
                 Guint firstOffset;
e946be
 
e946be
-                assert(xref->fetch(e->offset, 0, &objStr)->isStream());
e946be
-                nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
e946be
-                obj1.free();
e946be
-                first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
e946be
-                obj1.free();
e946be
+                objStr = xref->fetch(e->offset, 0);
e946be
+                assert(objStr.isStream());
e946be
+                obj1 = objStr.streamGetDict()->lookup("N");
e946be
+                nObjects = obj1.getInt();
e946be
+                obj1 = objStr.streamGetDict()->lookup("First");
e946be
+                first = obj1.getInt();
e946be
                 firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
e946be
 
e946be
                 // parse the header: object numbers and offsets
e946be
                 objStr.streamReset();
e946be
-                obj1.initNull();
e946be
-                str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
e946be
+                str = new EmbedStream(objStr.getStream(), Object(objNull), gTrue, first);
e946be
                 lexer = new Lexer(xref, str);
e946be
                 parser = new Parser(xref, lexer, gFalse);
e946be
                 for (n = 0; n < nObjects; ++n) {
e946be
-                    parser->getObj(&obj1);
e946be
-                    parser->getObj(&obj2);
e946be
+                    obj1 = parser->getObj();
e946be
+                    obj2 = parser->getObj();
e946be
                     if (n == e->gen)
e946be
                         localOffset = obj2.getInt();
e946be
-                    obj1.free();
e946be
-                    obj2.free();
e946be
                 }
e946be
 #if defined(POPPLER_VERSION) || defined(XPDF304)
e946be
                 while (str->getChar() != EOF) ;
e946be
@@ -187,7 +188,6 @@ int main(int argc, char *argv[])
e946be
                 lexer->skipToEOF();
e946be
 #endif
e946be
                 delete parser;
e946be
-                objStr.free();
e946be
 
e946be
                 fprintf(outfile, "%.10lu 00000 n\n",
e946be
                         (long unsigned)(firstOffset + localOffset));
e946be
@@ -198,7 +198,6 @@ int main(int argc, char *argv[])
e946be
         s->reset();
e946be
         while ((c = s->getChar()) != EOF)
e946be
             fputc(c, outfile);
e946be
-        srcStream.free();
e946be
     }
e946be
     if (objnum == 0)
e946be
         fprintf(stderr, "Source file extracted to %s\n", outname);
e946be
@@ -207,7 +206,6 @@ int main(int argc, char *argv[])
e946be
     else
e946be
         fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
e946be
     fclose(outfile);
e946be
-    catalogDict.free();
e946be
     delete doc;
e946be
     delete globalParams;
e946be
 }