52140fa
diff -up texlive-base-20170520/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler texlive-base-20170520/source/texk/web2c/pdftexdir/pdftoepdf.cc
52140fa
--- texlive-base-20170520/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler	2016-11-25 13:09:21.000000000 -0500
52140fa
+++ texlive-base-20170520/source/texk/web2c/pdftexdir/pdftoepdf.cc	2017-10-29 19:30:15.715109138 -0400
52140fa
@@ -1,5 +1,5 @@
52140fa
 /*
52140fa
-Copyright 1996-2016 Han The Thanh, <thanh@pdftex.org>
52140fa
+Copyright 1996-2017 Han The Thanh, <thanh@pdftex.org>
52140fa
 
52140fa
 This file is part of pdfTeX.
52140fa
 
52140fa
@@ -17,6 +17,15 @@ You should have received a copy of the G
52140fa
 with this program.  If not, see <http://www.gnu.org/licenses/>.
52140fa
 */
52140fa
 
52140fa
+/*
52140fa
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
52140fa
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
52140fa
+by Arch Linux. A little modifications are made to avoid a crash for
52140fa
+some kind of pdf images, such as figure_missing.pdf in gnuplot.
52140fa
+The poppler should be 0.59.0 or newer versions.
52140fa
+POPPLER_VERSION should be defined.
52140fa
+*/
52140fa
+
52140fa
 /* Do this early in order to avoid a conflict between
52140fa
    MINGW32 <rpcndr.h> defining 'boolean' as 'unsigned char' and
52140fa
    <kpathsea/types.h> defining Pascal's boolean as 'int'.
52140fa
@@ -39,10 +48,7 @@ with this program.  If not, see 
52140fa
 #include <goo/gfile.h>
52140fa
 #define GString GooString
52140fa
 #else
52140fa
-#include <aconf.h>
52140fa
-#include <GString.h>
52140fa
-#include <gmem.h>
52140fa
-#include <gfile.h>
52140fa
+#error POPPLER_VERSION should be defined.
52140fa
 #endif
52140fa
 #include <assert.h>
52140fa
 
52140fa
@@ -84,31 +90,6 @@ extern integer zround(double);
52140fa
 #define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
52140fa
 #define MASK_SUPPRESS_PTEX_INFODICT   0x08
52140fa
 
52140fa
-// PdfObject encapsulates the xpdf Object type,
52140fa
-// and properly frees its resources on destruction.
52140fa
-// Use obj-> to access members of the Object,
52140fa
-// and &obj to get a pointer to the object.
52140fa
-// It is no longer necessary to call Object::free explicitely.
52140fa
-
52140fa
-class PdfObject {
52140fa
-  public:
52140fa
-    PdfObject() {               // nothing
52140fa
-    } ~PdfObject() {
52140fa
-        iObject.free();
52140fa
-    }
52140fa
-    Object *operator->() {
52140fa
-        return &iObject;
52140fa
-    }
52140fa
-    Object *operator&() {
52140fa
-        return &iObject;
52140fa
-    }
52140fa
-  private:                     // no copying or assigning
52140fa
-    PdfObject(const PdfObject &);
52140fa
-    void operator=(const PdfObject &);
52140fa
-  public:
52140fa
-    Object iObject;
52140fa
-};
52140fa
-
52140fa
 // When copying the Resources of the selected page, all objects are copied
52140fa
 // recusively top-down. Indirect objects however are not fetched during
52140fa
 // copying, but get a new object number from pdfTeX and then will be
52140fa
@@ -212,18 +193,6 @@ static void delete_document(PdfDocument
52140fa
     delete pdf_doc;
52140fa
 }
52140fa
 
52140fa
-// Replacement for
52140fa
-//      Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
52140fa
-
52140fa
-static void initDictFromDict(PdfObject & obj, Dict * dict)
52140fa
-{
52140fa
-    obj->initDict(xref);
52140fa
-    for (int i = 0, l = dict->getLength(); i < l; i++) {
52140fa
-        Object obj1;
52140fa
-        obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
52140fa
-    }
52140fa
-}
52140fa
-
52140fa
 // --------------------------------------------------------------------
52140fa
 
52140fa
 static int addEncoding(GfxFont * gfont)
52140fa
@@ -320,10 +289,10 @@ static void copyName(char *s)
52140fa
 
52140fa
 static void copyDictEntry(Object * obj, int i)
52140fa
 {
52140fa
-    PdfObject obj1;
52140fa
+    Object obj1;
52140fa
     copyName(obj->dictGetKey(i));
52140fa
     pdf_puts(" ");
52140fa
-    obj->dictGetValNF(i, &obj1);
52140fa
+    obj1 = obj->dictGetValNF(i);
52140fa
     copyObject(&obj1);
52140fa
     pdf_puts("\n");
52140fa
 }
52140fa
@@ -376,17 +345,17 @@ static void copyStream(Stream * str)
52140fa
 static void copyProcSet(Object * obj)
52140fa
 {
52140fa
     int i, l;
52140fa
-    PdfObject procset;
52140fa
+    Object procset;
52140fa
     if (!obj->isArray())
52140fa
         pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
52140fa
                     obj->getTypeName());
52140fa
     pdf_puts("/ProcSet [ ");
52140fa
     for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
52140fa
-        obj->arrayGetNF(i, &procset);
52140fa
-        if (!procset->isName())
52140fa
+        procset = obj->arrayGetNF(i);
52140fa
+        if (!procset.isName())
52140fa
             pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
52140fa
-                        procset->getTypeName());
52140fa
-        copyName(procset->getName());
52140fa
+                        procset.getTypeName());
52140fa
+        copyName(procset.getName());
52140fa
         pdf_puts(" ");
52140fa
     }
52140fa
     pdf_puts("]\n");
52140fa
@@ -394,10 +363,29 @@ static void copyProcSet(Object * obj)
52140fa
 
52140fa
 #define REPLACE_TYPE1C true
52140fa
 
52140fa
+static bool embeddableFont(Object * fontdesc)
52140fa
+{
52140fa
+    Object fontfile, ffsubtype;
52140fa
+
52140fa
+    if (!fontdesc->isDict())
52140fa
+        return false;
52140fa
+    fontfile = fontdesc->dictLookup("FontFile");
52140fa
+    if (fontfile.isStream())
52140fa
+        return true;
52140fa
+    if (REPLACE_TYPE1C) {
52140fa
+        fontfile = fontdesc->dictLookup("FontFile3");
52140fa
+        if (!fontfile.isStream())
52140fa
+            return false;
52140fa
+        ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
52140fa
+        return ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C");
52140fa
+    }
52140fa
+    return false;
52140fa
+}
52140fa
+
52140fa
 static void copyFont(char *tag, Object * fontRef)
52140fa
 {
52140fa
-    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
52140fa
-        fontfile, ffsubtype, stemV;
52140fa
+    Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
52140fa
+        stemV;
52140fa
     GfxFont *gfont;
52140fa
     fd_entry *fd;
52140fa
     fm_entry *fontmap;
52140fa
@@ -413,33 +401,39 @@ static void copyFont(char *tag, Object *
52140fa
     }
52140fa
     // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
52140fa
     // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
52140fa
-    if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
52140fa
-        && fontdict->dictLookup("Subtype", &subtype)->isName()
52140fa
-        && !strcmp(subtype->getName(), "Type1")
52140fa
-        && fontdict->dictLookup("BaseFont", &basefont)->isName()
52140fa
-        && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
52140fa
-        && fontdescRef->fetch(xref, &fontdesc)->isDict()
52140fa
-        && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
52140fa
-            || (REPLACE_TYPE1C
52140fa
-                && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
52140fa
-                && fontfile->streamGetDict()->lookup("Subtype",
52140fa
-                                                     &ffsubtype)->isName()
52140fa
-                && !strcmp(ffsubtype->getName(), "Type1C")))
52140fa
-        && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
52140fa
+    fontdict = fontRef->fetch(xref);
52140fa
+    fontdesc = Object(objNull);
52140fa
+    if (fontdict.isDict()) {
52140fa
+        subtype = fontdict.dictLookup("Subtype");
52140fa
+        basefont = fontdict.dictLookup("BaseFont");
52140fa
+        fontdescRef = fontdict.dictLookupNF("FontDescriptor");
52140fa
+        if (fontdescRef.isRef()) {
52140fa
+            fontdesc = fontdescRef.fetch(xref);
52140fa
+        }
52140fa
+    }
52140fa
+    if (!fixedinclusioncopyfont && fontdict.isDict()
52140fa
+        && subtype.isName()
52140fa
+        && !strcmp(subtype.getName(), "Type1")
52140fa
+        && basefont.isName()
52140fa
+        && fontdescRef.isRef()
52140fa
+        && fontdesc.isDict()
52140fa
+        && embeddableFont(&fontdesc)
52140fa
+        && (fontmap = lookup_fontmap(basefont.getName())) != NULL) {
52140fa
         // round /StemV value, since the PDF input is a float
52140fa
         // (see Font Descriptors in PDF reference), but we only store an
52140fa
         // integer, since we don't want to change the struct.
52140fa
-        fontdesc->dictLookup("StemV", &stemV);
52140fa
-        fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
52140fa
-        if (fontdesc->dictLookup("CharSet", &charset) &&
52140fa
-            charset->isString() && is_subsetable(fontmap))
52140fa
-            epdf_mark_glyphs(fd, charset->getString()->getCString());
52140fa
+        stemV = fontdesc.dictLookup("StemV");
52140fa
+        fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
52140fa
+        charset = fontdesc.dictLookup("CharSet");
52140fa
+        if (!charset.isNull() &&
52140fa
+            charset.isString() && is_subsetable(fontmap))
52140fa
+            epdf_mark_glyphs(fd, charset.getString()->getCString());
52140fa
         else
52140fa
             embed_whole_font(fd);
52140fa
-        addFontDesc(fontdescRef->getRef(), fd);
52140fa
+        addFontDesc(fontdescRef.getRef(), fd);
52140fa
         copyName(tag);
52140fa
         gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
52140fa
-                                  fontdict->getDict());
52140fa
+                                  fontdict.getDict());
52140fa
         pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
52140fa
                                        addEncoding(gfont)));
52140fa
     } else {
52140fa
@@ -451,24 +445,24 @@ static void copyFont(char *tag, Object *
52140fa
 
52140fa
 static void copyFontResources(Object * obj)
52140fa
 {
52140fa
-    PdfObject fontRef;
52140fa
+    Object fontRef;
52140fa
     int i, l;
52140fa
     if (!obj->isDict())
52140fa
         pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
52140fa
                     obj->getTypeName());
52140fa
     pdf_puts("/Font << ");
52140fa
     for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
52140fa
-        obj->dictGetValNF(i, &fontRef);
52140fa
-        if (fontRef->isRef())
52140fa
+        fontRef = obj->dictGetValNF(i);
52140fa
+        if (fontRef.isRef())
52140fa
             copyFont(obj->dictGetKey(i), &fontRef);
52140fa
-        else if (fontRef->isDict()) {   // some programs generate pdf with embedded font object
52140fa
+        else if (fontRef.isDict()) {   // some programs generate pdf with embedded font object
52140fa
             copyName(obj->dictGetKey(i));
52140fa
             pdf_puts(" ");
52140fa
             copyObject(&fontRef);
52140fa
         }
52140fa
         else
52140fa
             pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
52140fa
-                        fontRef->getTypeName());
52140fa
+                        fontRef.getTypeName());
52140fa
     }
52140fa
     pdf_puts(">>\n");
52140fa
 }
52140fa
@@ -557,7 +551,7 @@ static char *convertNumToPDF(double n)
52140fa
 
52140fa
 static void copyObject(Object * obj)
52140fa
 {
52140fa
-    PdfObject obj1;
52140fa
+    Object obj1;
52140fa
     int i, l, c;
52140fa
     Ref ref;
52140fa
     char *p;
52140fa
@@ -601,8 +595,8 @@ static void copyObject(Object * obj)
52140fa
     } else if (obj->isArray()) {
52140fa
         pdf_puts("[");
52140fa
         for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
52140fa
-            obj->arrayGetNF(i, &obj1);
52140fa
-            if (!obj1->isName())
52140fa
+            obj1 = obj->arrayGetNF(i);
52140fa
+            if (!obj1.isName())
52140fa
                 pdf_puts(" ");
52140fa
             copyObject(&obj1);
52140fa
         }
52140fa
@@ -612,9 +606,8 @@ static void copyObject(Object * obj)
52140fa
         copyDict(obj);
52140fa
         pdf_puts(">>");
52140fa
     } else if (obj->isStream()) {
52140fa
-        initDictFromDict(obj1, obj->streamGetDict());
52140fa
         pdf_puts("<<\n");
52140fa
-        copyDict(&obj1);
52140fa
+        copyDict(obj->getStream()->getDictObject());
52140fa
         pdf_puts(">>\n");
52140fa
         pdf_puts("stream\n");
52140fa
         copyStream(obj->getStream()->getUndecodedStream());
52140fa
@@ -638,9 +631,8 @@ static void writeRefs()
52140fa
     InObj *r;
52140fa
     for (r = inObjList; r != 0; r = r->next) {
52140fa
         if (!r->written) {
52140fa
-            Object obj1;
52140fa
             r->written = 1;
52140fa
-            xref->fetch(r->ref.num, r->ref.gen, &obj1);
52140fa
+            Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
52140fa
             if (r->type == objFont) {
52140fa
                 assert(!obj1.isStream());
52140fa
                 pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
52140fa
@@ -656,7 +648,6 @@ static void writeRefs()
52140fa
                 pdf_puts("\n");
52140fa
                 pdfendobj();
52140fa
             }
52140fa
-            obj1.free();
52140fa
         }
52140fa
     }
52140fa
 }
52140fa
@@ -685,7 +676,7 @@ static void writeEncodings()
52140fa
 #ifdef POPPLER_VERSION
52140fa
         r->font->decRefCnt();
52140fa
 #else
52140fa
-        delete r->font;
52140fa
+#error POPPLER_VERSION should be defined.
52140fa
 #endif
52140fa
         delete r;
52140fa
     }
52140fa
@@ -728,7 +719,7 @@ read_pdf_info(char *image_name, char *pa
52140fa
 #ifdef POPPLER_VERSION
52140fa
     int pdf_major_version_found, pdf_minor_version_found;
52140fa
 #else
52140fa
-    float pdf_version_found, pdf_version_wanted;
52140fa
+#error POPPLER_VERSION should be defined.
52140fa
 #endif
52140fa
     // initialize
52140fa
     if (!isInit) {
52140fa
@@ -760,19 +751,7 @@ read_pdf_info(char *image_name, char *pa
52140fa
         }
52140fa
     }
52140fa
 #else
52140fa
-    pdf_version_found = pdf_doc->doc->getPDFVersion();
52140fa
-    pdf_version_wanted = 1 + (minor_pdf_version_wanted * 0.1);
52140fa
-    if (pdf_version_found > pdf_version_wanted + 0.01) {
52140fa
-        char msg[] =
52140fa
-            "PDF inclusion: found PDF version <%.1f>, but at most version <%.1f> allowed";
52140fa
-        if (pdf_inclusion_errorlevel > 0) {
52140fa
-            pdftex_fail(msg, pdf_version_found, pdf_version_wanted);
52140fa
-        } else if (pdf_inclusion_errorlevel < 0) {
52140fa
-            ; /* do nothing */
52140fa
-        } else { /* = 0, give warning */
52140fa
-            pdftex_warn(msg, pdf_version_found, pdf_version_wanted);
52140fa
-        }
52140fa
-    }
52140fa
+#error POPPLER_VERSION should be defined.
52140fa
 #endif
52140fa
     epdf_num_pages = pdf_doc->doc->getCatalog()->getNumPages();
52140fa
     if (page_name) {
52140fa
@@ -839,8 +818,8 @@ void write_epdf(void)
52140fa
     Page *page;
52140fa
     Ref *pageRef;
52140fa
     Dict *pageDict;
52140fa
-    PdfObject contents, obj1, obj2, pageObj, dictObj;
52140fa
-    PdfObject groupDict;
52140fa
+    Object contents, obj1, obj2, pageObj, dictObj;
52140fa
+    Object groupDict;
52140fa
     bool writeSepGroup = false;
52140fa
     Object info;
52140fa
     char *key;
52140fa
@@ -867,8 +846,8 @@ void write_epdf(void)
52140fa
     encodingList = 0;
52140fa
     page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
52140fa
     pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
52140fa
-    xref->fetch(pageRef->num, pageRef->gen, &pageObj);
52140fa
-    pageDict = pageObj->getDict();
52140fa
+    pageObj = xref->fetch(pageRef->num, pageRef->gen);
52140fa
+    pageDict = pageObj.getDict();
52140fa
     rotate = page->getRotate();
52140fa
     PDFRectangle *pagebox;
52140fa
     // write the Page header
52140fa
@@ -886,7 +865,7 @@ void write_epdf(void)
52140fa
         pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
52140fa
     }
52140fa
     if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
52140fa
-        pdf_doc->doc->getDocInfoNF(&info;;
52140fa
+        info = pdf_doc->doc->getDocInfoNF();
52140fa
         if (info.isRef()) {
52140fa
             // the info dict must be indirect (PDF Ref p. 61)
52140fa
             pdf_printf("/%s.InfoDict ", pdfkeyprefix);
52140fa
@@ -942,14 +921,14 @@ void write_epdf(void)
52140fa
     pdf_puts(stripzeros(s));
52140fa
 
52140fa
     // Metadata validity check (as a stream it must be indirect)
52140fa
-    pageDict->lookupNF("Metadata", &dictObj);
52140fa
-    if (!dictObj->isNull() && !dictObj->isRef())
52140fa
+    dictObj = pageDict->lookupNF("Metadata");
52140fa
+    if (!dictObj.isNull() && !dictObj.isRef())
52140fa
         pdftex_warn("PDF inclusion: /Metadata must be indirect object");
52140fa
 
52140fa
     // copy selected items in Page dictionary except Resources & Group
52140fa
     for (i = 0; pageDictKeys[i] != NULL; i++) {
52140fa
-        pageDict->lookupNF(pageDictKeys[i], &dictObj);
52140fa
-        if (!dictObj->isNull()) {
52140fa
+        dictObj = pageDict->lookupNF(pageDictKeys[i]);
52140fa
+        if (!dictObj.isNull()) {
52140fa
             pdf_newline();
52140fa
             pdf_printf("/%s ", pageDictKeys[i]);
52140fa
             copyObject(&dictObj); // preserves indirection
52140fa
@@ -957,8 +936,8 @@ void write_epdf(void)
52140fa
     } 
52140fa
 
52140fa
     // handle page group
52140fa
-    pageDict->lookupNF("Group", &dictObj);
52140fa
-    if (!dictObj->isNull()) {
52140fa
+    dictObj = pageDict->lookupNF("Group");
52140fa
+    if (!dictObj.isNull()) {
52140fa
         if (pdfpagegroupval == 0) { 
52140fa
             // another pdf with page group was included earlier on the
52140fa
             // same page; copy the Group entry as is.  See manual for
52140fa
@@ -972,11 +951,36 @@ void write_epdf(void)
52140fa
             copyObject(&dictObj);
52140fa
         } else {
52140fa
             // write Group dict as a separate object, since the Page dict also refers to it
52140fa
-            pageDict->lookup("Group", &dictObj);
52140fa
-            if (!dictObj->isDict())
52140fa
+            dictObj = pageDict->lookup("Group");
52140fa
+            if (!dictObj.isDict())
52140fa
                 pdftex_fail("PDF inclusion: /Group dict missing");
52140fa
             writeSepGroup = true;
52140fa
-            initDictFromDict(groupDict, page->getGroup());
52140fa
+/*
52140fa
+This part is only a single line
52140fa
+            groupDict = Object(page->getGroup());
52140fa
+in the original patch. In this case, however, pdftex crashes at
52140fa
+"delete pdf_doc->doc" in "delete_document()" for inclusion of some
52140fa
+kind of pdf images, for example, figure_missing.pdf in gnuplot.
52140fa
+A change
52140fa
+            groupDict = Object(page->getGroup()).copy();
52140fa
+does not improve the situation.
52140fa
+The changes below seem to work fine. 
52140fa
+*/
52140fa
+// begin modification
52140fa
+            groupDict = pageDict->lookup("Group");
8f2dd7d
+            const Dict& dic1 = page->getGroup();
8f2dd7d
+            const Dict& dic2 = groupDict.getDict();
52140fa
+            // replace dic2 in groupDict with dic1
52140fa
+            l = dic2.getLength();
52140fa
+            for (i = 0; i < l; i++) {
52140fa
+                groupDict.dictRemove(dic2.getKey(i));
52140fa
+            }
52140fa
+            l = dic1.getLength();
52140fa
+            for (i = 0; i < l; i++) {
52140fa
+                groupDict.dictAdd(copyString(dic1.getKey(i)),
52140fa
+                                  dic1.getValNF(i));
52140fa
+            }
52140fa
+// end modification
52140fa
             pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
52140fa
         }
52140fa
     }
52140fa
@@ -989,14 +993,14 @@ void write_epdf(void)
52140fa
         pdftex_warn
52140fa
             ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
52140fa
     } else {
52140fa
-        initDictFromDict(obj1, page->getResourceDict());
52140fa
+        Object *obj1 = page->getResourceDictObject();
52140fa
         if (!obj1->isDict())
52140fa
             pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
52140fa
                         obj1->getTypeName());
52140fa
         pdf_newline();
52140fa
         pdf_puts("/Resources <<\n");
52140fa
         for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
52140fa
-            obj1->dictGetVal(i, &obj2);
52140fa
+            obj2 = obj1->dictGetVal(i);
52140fa
             key = obj1->dictGetKey(i);
52140fa
             if (strcmp("Font", key) == 0)
52140fa
                 copyFontResources(&obj2);
52140fa
@@ -1009,8 +1013,8 @@ void write_epdf(void)
52140fa
     }
52140fa
 
52140fa
     // write the page contents
52140fa
-    page->getContents(&contents);
52140fa
-    if (contents->isStream()) {
52140fa
+    contents = page->getContents();
52140fa
+    if (contents.isStream()) {
52140fa
 
52140fa
         // Variant A: get stream and recompress under control
52140fa
         // of \pdfcompresslevel
52140fa
@@ -1021,36 +1025,35 @@ void write_epdf(void)
52140fa
 
52140fa
         // Variant B: copy stream without recompressing
52140fa
         //
52140fa
-        contents->streamGetDict()->lookup("F", &obj1);
52140fa
-        if (!obj1->isNull()) {
52140fa
+        obj1 = contents.streamGetDict()->lookup("F");
52140fa
+        if (!obj1.isNull()) {
52140fa
             pdftex_fail("PDF inclusion: Unsupported external stream");
52140fa
         }
52140fa
-        contents->streamGetDict()->lookup("Length", &obj1);
52140fa
-        assert(!obj1->isNull());
52140fa
+        obj1 = contents.streamGetDict()->lookup("Length");
52140fa
+        assert(!obj1.isNull());
52140fa
         pdf_puts("/Length ");
52140fa
         copyObject(&obj1);
52140fa
         pdf_puts("\n");
52140fa
-        contents->streamGetDict()->lookup("Filter", &obj1);
52140fa
-        if (!obj1->isNull()) {
52140fa
+        obj1 = contents.streamGetDict()->lookup("Filter");
52140fa
+        if (!obj1.isNull()) {
52140fa
             pdf_puts("/Filter ");
52140fa
             copyObject(&obj1);
52140fa
             pdf_puts("\n");
52140fa
-            contents->streamGetDict()->lookup("DecodeParms", &obj1);
52140fa
-            if (!obj1->isNull()) {
52140fa
+            obj1 = contents.streamGetDict()->lookup("DecodeParms");
52140fa
+            if (!obj1.isNull()) {
52140fa
                 pdf_puts("/DecodeParms ");
52140fa
                 copyObject(&obj1);
52140fa
                 pdf_puts("\n");
52140fa
             }
52140fa
         }
52140fa
         pdf_puts(">>\nstream\n");
52140fa
-        copyStream(contents->getStream()->getUndecodedStream());
52140fa
+        copyStream(contents.getStream()->getUndecodedStream());
52140fa
         pdfendstream();
52140fa
-    } else if (contents->isArray()) {
52140fa
+    } else if (contents.isArray()) {
52140fa
         pdfbeginstream();
52140fa
-        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
52140fa
-            Object contentsobj;
52140fa
-            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
52140fa
-            contentsobj.free();
52140fa
+        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
52140fa
+            Object contentsobj = contents.arrayGet(i);
52140fa
+            copyStream(contentsobj.getStream());
52140fa
             if (i < l - 1)
52140fa
                 pdf_newline();  // add a newline after each stream except the last
52140fa
         }
52140fa
diff -up texlive-base-20170520/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler texlive-base-20170520/source/texk/web2c/pdftexdir/pdftosrc.cc
52140fa
--- texlive-base-20170520/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler	2016-11-25 13:09:21.000000000 -0500
52140fa
+++ texlive-base-20170520/source/texk/web2c/pdftexdir/pdftosrc.cc	2017-10-29 19:30:29.988736531 -0400
52140fa
@@ -1,5 +1,5 @@
52140fa
 /*
52140fa
-Copyright 1996-2014 Han The Thanh, <thanh@pdftex.org>
52140fa
+Copyright 1996-2017 Han The Thanh, <thanh@pdftex.org>
52140fa
 
52140fa
 This file is part of pdfTeX.
52140fa
 
52140fa
@@ -16,6 +16,14 @@ GNU General Public License for more deta
52140fa
 You should have received a copy of the GNU General Public License along
52140fa
 with this program.  If not, see <http://www.gnu.org/licenses/>.
52140fa
 */
52140fa
+
52140fa
+/*
52140fa
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
52140fa
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
52140fa
+by Arch Linux. The poppler should be 0.59.0 or newer versions.
52140fa
+POPPLER_VERSION should be defined.
52140fa
+*/
52140fa
+
52140fa
 #include <w2c/config.h>
52140fa
 
52140fa
 #include <stdlib.h>
52140fa
@@ -32,10 +40,7 @@ with this program.  If not, see 
52140fa
 #include <goo/gmem.h>
52140fa
 #include <goo/gfile.h>
52140fa
 #else
52140fa
-#include <aconf.h>
52140fa
-#include <GString.h>
52140fa
-#include <gmem.h>
52140fa
-#include <gfile.h>
52140fa
+#error POPPLER_VERSION should be defined.
52140fa
 #endif
52140fa
 #include <assert.h>
52140fa
 
52140fa
@@ -86,22 +91,20 @@ int main(int argc, char *argv[])
52140fa
             objgen = atoi(argv[3]);
52140fa
     }
52140fa
     xref = doc->getXRef();
52140fa
-    catalogDict.initNull();
52140fa
-    xref->getCatalog(&catalogDict);
52140fa
+    catalogDict = xref->getCatalog();
52140fa
     if (!catalogDict.isDict("Catalog")) {
52140fa
         fprintf(stderr, "No Catalog found\n");
52140fa
         exit(1);
52140fa
     }
52140fa
-    srcStream.initNull();
52140fa
+    srcStream = Object(objNull);
52140fa
     if (objnum == 0) {
52140fa
-        catalogDict.dictLookup("SourceObject", &srcStream);
52140fa
+        srcStream = catalogDict.dictLookup("SourceObject");
52140fa
         static char const_SourceFile[] = "SourceFile";
52140fa
         if (!srcStream.isStream(const_SourceFile)) {
52140fa
             fprintf(stderr, "No SourceObject found\n");
52140fa
             exit(1);
52140fa
         }
52140fa
-        srcName.initNull();
52140fa
-        srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
52140fa
+        srcName = srcStream.getStream()->getDict()->lookup("SourceName");
52140fa
         if (!srcName.isString()) {
52140fa
             fprintf(stderr, "No SourceName found\n");
52140fa
             exit(1);
52140fa
@@ -110,7 +113,7 @@ int main(int argc, char *argv[])
52140fa
         // We cannot free srcName, as objname shares its string.
52140fa
         // srcName.free();
52140fa
     } else if (objnum > 0) {
52140fa
-        xref->fetch(objnum, objgen, &srcStream);
52140fa
+        srcStream = xref->fetch(objnum, objgen);
52140fa
         if (!srcStream.isStream()) {
52140fa
             fprintf(stderr, "Not a Stream object\n");
52140fa
             exit(1);
52140fa
@@ -153,35 +156,34 @@ int main(int argc, char *argv[])
52140fa
                         (e->type == xrefEntryFree ? "f" : "n"));
52140fa
             else {              // e->offset is the object number of the object stream
52140fa
                 Stream *str;
52140fa
+                Lexer *lexer;
52140fa
                 Parser *parser;
52140fa
                 Object objStr, obj1, obj2;
52140fa
                 int nObjects, first, n;
52140fa
                 int localOffset = 0;
52140fa
                 Guint firstOffset;
52140fa
 
52140fa
-                assert(xref->fetch(e->offset, 0, &objStr)->isStream());
52140fa
-                nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
52140fa
-                obj1.free();
52140fa
-                first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
52140fa
-                obj1.free();
52140fa
+                objStr = xref->fetch(e->offset, 0);
52140fa
+                assert(objStr.isStream());
52140fa
+                obj1 = objStr.streamGetDict()->lookup("N");
52140fa
+                nObjects = obj1.getInt();
52140fa
+                obj1 = objStr.streamGetDict()->lookup("First");
52140fa
+                first = obj1.getInt();
52140fa
                 firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
52140fa
 
52140fa
                 // parse the header: object numbers and offsets
52140fa
                 objStr.streamReset();
52140fa
-                obj1.initNull();
52140fa
-                str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
52140fa
-                parser = new Parser(xref, new Lexer(xref, str), gFalse);
52140fa
+                str = new EmbedStream(objStr.getStream(), Object(objNull), gTrue, first);
52140fa
+                lexer = new Lexer(xref, str);
52140fa
+                parser = new Parser(xref, lexer, gFalse);
52140fa
                 for (n = 0; n < nObjects; ++n) {
52140fa
-                    parser->getObj(&obj1);
52140fa
-                    parser->getObj(&obj2);
52140fa
+                    obj1 = parser->getObj();
52140fa
+                    obj2 = parser->getObj();
52140fa
                     if (n == e->gen)
52140fa
                         localOffset = obj2.getInt();
52140fa
-                    obj1.free();
52140fa
-                    obj2.free();
52140fa
                 }
52140fa
                 while (str->getChar() != EOF) ;
52140fa
                 delete parser;
52140fa
-                objStr.free();
52140fa
 
52140fa
                 fprintf(outfile, "%.10lu 00000 n\n",
52140fa
                         (long unsigned)(firstOffset + localOffset));
52140fa
@@ -192,7 +194,6 @@ int main(int argc, char *argv[])
52140fa
         s->reset();
52140fa
         while ((c = s->getChar()) != EOF)
52140fa
             fputc(c, outfile);
52140fa
-        srcStream.free();
52140fa
     }
52140fa
     if (objnum == 0)
52140fa
         fprintf(stderr, "Source file extracted to %s\n", outname);
52140fa
@@ -201,7 +202,6 @@ int main(int argc, char *argv[])
52140fa
     else
52140fa
         fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
52140fa
     fclose(outfile);
52140fa
-    catalogDict.free();
52140fa
     delete doc;
52140fa
     delete globalParams;
52140fa
 }
52140fa
--- texlive-base-20170520/source/texk/web2c/luatexdir/image/pdftoepdf.w.newpoppler	2017-05-08 22:39:36.639375783 +0200
52140fa
+++ texlive-base-20170520/source/texk/web2c/luatexdir/image/pdftoepdf.w	2017-09-19 11:23:36.586768739 +0200
52140fa
@@ -224,7 +224,7 @@
52140fa
         free(checksum);
52140fa
     }
52140fa
     if (pdf_doc->doc == NULL) {
52140fa
-        docmemstream = new MemStream( docstream,0,streamsize, obj.initNull() );
52140fa
+        docmemstream = new MemStream( docstream,0,streamsize, Object(objNull) );
52140fa
         doc = new PDFDoc(docmemstream); /* takes ownership of docmemstream */
52140fa
         pdf_doc->pc++;
52140fa
         if (!doc->isOk() || !doc->okToPrint()) {
52140fa
@@ -408,9 +408,8 @@
52140fa
     Object obj1;
52140fa
     pdf_begin_array(pdf);
52140fa
     for (i = 0, l = array->getLength(); i < l; ++i) {
52140fa
-        array->getNF(i, &obj1);
52140fa
+        obj1 = array->getNF(i);
52140fa
         copyObject(pdf, pdf_doc, &obj1);
52140fa
-        obj1.free();
52140fa
     }
52140fa
     pdf_end_array(pdf);
52140fa
 }
52140fa
@@ -422,9 +421,8 @@
52140fa
     pdf_begin_dict(pdf);
52140fa
     for (i = 0, l = dict->getLength(); i < l; ++i) {
52140fa
         copyName(pdf, dict->getKey(i));
52140fa
-        dict->getValNF(i, &obj1);
52140fa
+        obj1 = dict->getValNF(i);
52140fa
         copyObject(pdf, pdf_doc, &obj1);
52140fa
-        obj1.free();
52140fa
     }
52140fa
     pdf_end_dict(pdf);
52140fa
 }
52140fa
@@ -510,13 +508,12 @@
52140fa
     PDFDoc *doc = pdf_doc->doc;
52140fa
     xref = doc->getXRef();
52140fa
     for (r = pdf_doc->inObjList; r != NULL;) {
52140fa
-        xref->fetch(r->ref.num, r->ref.gen, &obj1);
52140fa
+        obj1 = xref->fetch(r->ref.num, r->ref.gen);
52140fa
         if (obj1.isStream())
52140fa
             pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
52140fa
         else
52140fa
             pdf_begin_obj(pdf, r->num, 2);
52140fa
         copyObject(pdf, pdf_doc, &obj1);
52140fa
-        obj1.free();
52140fa
         pdf_end_obj(pdf);
52140fa
         n = r->next;
52140fa
         delete r;
52140fa
@@ -740,7 +737,7 @@
52140fa
     catalog = doc->getCatalog();
52140fa
     page = catalog->getPage(img_pagenum(idict));
52140fa
     pageref = catalog->getPageRef(img_pagenum(idict));
52140fa
-    doc->getXRef()->fetch(pageref->num, pageref->gen, &pageobj);
52140fa
+    pageobj = doc->getXRef()->fetch(pageref->num, pageref->gen);
52140fa
     pageDict = pageobj.getDict();
52140fa
     /* write the Page header */
52140fa
     pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER);
52140fa
@@ -757,12 +754,11 @@
52140fa
         pdf_dict_add_int(pdf, "PTEX.PageNumber", (int) img_pagenum(idict));
52140fa
     }
52140fa
     if ((suppress_optional_info & 8) == 0) {
52140fa
-        doc->getDocInfoNF(&obj1);
52140fa
+        obj1 = doc->getDocInfoNF();
52140fa
         if (obj1.isRef()) {
52140fa
             /* the info dict must be indirect (PDF Ref p. 61) */
52140fa
             pdf_dict_add_ref(pdf, "PTEX.InfoDict", addInObj(pdf, pdf_doc, obj1.getRef()));
52140fa
         }
52140fa
-        obj1.free();
52140fa
     }
52140fa
     if (img_is_bbox(idict)) {
52140fa
         bbox[0] = sp2bp(img_bbox(idict)[0]);
52140fa
@@ -788,19 +784,17 @@
52140fa
         Now all relevant parts of the Page dictionary are copied. Metadata validity
52140fa
         check is needed(as a stream it must be indirect).
52140fa
     */
52140fa
-    pageDict->lookupNF("Metadata", &obj1);
52140fa
+    obj1 = pageDict->lookupNF("Metadata");
52140fa
     if (!obj1.isNull() && !obj1.isRef())
52140fa
         formatted_warning("pdf inclusion","/Metadata must be indirect object");
52140fa
-    obj1.free();
52140fa
     /* copy selected items in Page dictionary */
52140fa
     for (i = 0; pagedictkeys[i] != NULL; i++) {
52140fa
-        pageDict->lookupNF(pagedictkeys[i], &obj1);
52140fa
+        obj1 = pageDict->lookupNF(pagedictkeys[i]);
52140fa
         if (!obj1.isNull()) {
52140fa
             pdf_add_name(pdf, pagedictkeys[i]);
52140fa
             /* preserves indirection */
52140fa
             copyObject(pdf, pdf_doc, &obj1);
52140fa
         }
52140fa
-        obj1.free();
52140fa
     }
52140fa
     /*
52140fa
         If there are no Resources in the Page dict of the embedded page,
52140fa
@@ -808,32 +802,28 @@
52140fa
         PDF file, climbing up the tree until the Resources are found.
52140fa
         (This fixes a problem with Scribus 1.3.3.14.)
52140fa
     */
52140fa
-    pageDict->lookupNF("Resources", &obj1);
52140fa
+    obj1 = pageDict->lookupNF("Resources");
52140fa
     if (obj1.isNull()) {
52140fa
         op1 = &pagesobj1;
52140fa
         op2 = &pagesobj2;
52140fa
-        pageDict->lookup("Parent", op1);
52140fa
+        *op1 = pageDict->lookup("Parent");
52140fa
         while (op1->isDict()) {
52140fa
-            obj1.free();
52140fa
-            op1->dictLookupNF("Resources", &obj1);
52140fa
+            obj1 = op1->dictLookupNF("Resources");
52140fa
             if (!obj1.isNull()) {
52140fa
                 pdf_add_name(pdf, "Resources");
52140fa
                 copyObject(pdf, pdf_doc, &obj1);
52140fa
                 break;
52140fa
             }
52140fa
-            op1->dictLookup("Parent", op2);
52140fa
+            *op2 = op1->dictLookup("Parent");
52140fa
             optmp = op1;
52140fa
             op1 = op2;
52140fa
             op2 = optmp;
52140fa
-            op2->free();
52140fa
         };
52140fa
         if (!op1->isDict())
52140fa
             formatted_warning("pdf inclusion","Page /Resources missing");
52140fa
-        op1->free();
52140fa
     }
52140fa
-    obj1.free();
52140fa
     /* Write the Page contents. */
52140fa
-    page->getContents(&contents);
52140fa
+    contents = page->getContents();
52140fa
     if (contents.isStream()) {
52140fa
         /*
52140fa
             Variant A: get stream and recompress under control of \pdfcompresslevel
52140fa
@@ -844,27 +834,23 @@
52140fa
 
52140fa
             Variant B: copy stream without recompressing
52140fa
         */
52140fa
-        contents.streamGetDict()->lookup("F", &obj1);
52140fa
+        obj1 = contents.streamGetDict()->lookup("F");
52140fa
         if (!obj1.isNull()) {
52140fa
             normal_error("pdf inclusion","unsupported external stream");
52140fa
         }
52140fa
-        obj1.free();
52140fa
-        contents.streamGetDict()->lookup("Length", &obj1);
52140fa
+        obj1 = contents.streamGetDict()->lookup("Length");
52140fa
         pdf_add_name(pdf, "Length");
52140fa
         copyObject(pdf, pdf_doc, &obj1);
52140fa
-        obj1.free();
52140fa
-        contents.streamGetDict()->lookup("Filter", &obj1);
52140fa
+        obj1 = contents.streamGetDict()->lookup("Filter");
52140fa
         if (!obj1.isNull()) {
52140fa
             pdf_add_name(pdf, "Filter");
52140fa
             copyObject(pdf, pdf_doc, &obj1);
52140fa
-            obj1.free();
52140fa
-            contents.streamGetDict()->lookup("DecodeParms", &obj1);
52140fa
+            obj1 = contents.streamGetDict()->lookup("DecodeParms");
52140fa
             if (!obj1.isNull()) {
52140fa
                 pdf_add_name(pdf, "DecodeParms");
52140fa
                 copyObject(pdf, pdf_doc, &obj1);
52140fa
             }
52140fa
         }
52140fa
-        obj1.free();
52140fa
         pdf_end_dict(pdf);
52140fa
         pdf_begin_stream(pdf);
52140fa
         copyStreamStream(pdf, contents.getStream()->getUndecodedStream());
52140fa
@@ -875,8 +861,8 @@
52140fa
         pdf_end_dict(pdf);
52140fa
         pdf_begin_stream(pdf);
52140fa
         for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
52140fa
-            copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream());
52140fa
-            obj1.free();
52140fa
+            obj1 = contents.arrayGet(i);
52140fa
+            copyStreamStream(pdf, obj1.getStream());
52140fa
             if (i < (l - 1)) {
52140fa
                 /*
52140fa
                     Put a space between streams to be on the safe side (streams
52140fa
@@ -897,8 +883,6 @@
52140fa
     }
52140fa
     /* write out all indirect objects */
52140fa
     writeRefs(pdf, pdf_doc);
52140fa
-    contents.free();
52140fa
-    pageobj.free();
52140fa
     /*
52140fa
         unrefPdfDocument() must come after contents.free() and pageobj.free()!
52140fa
         TH: The next line makes repeated pdf inclusion unacceptably slow
52140fa
--- texlive-base-20170520/source/texk/web2c/luatexdir/lua/lepdflib.cc.newpoppler	2017-05-08 22:39:36.689375107 +0200
52140fa
+++ texlive-base-20170520/source/texk/web2c/luatexdir/lua/lepdflib.cc	2017-09-19 09:48:19.658021769 +0200
52140fa
@@ -538,7 +538,7 @@
52140fa
         pdfdoc_changed_error(L);                               \
52140fa
     uout = new_Object_userdata(L);                             \
52140fa
     uout->d = new Object();                                    \
52140fa
-    ((in *) uin->d)->function((Object *) uout->d);             \
52140fa
+    *((Object *)uout->d) = ((in *) uin->d)->function();                  \
52140fa
     uout->atype = ALLOC_LEPDF;                                 \
52140fa
     uout->pc = uin->pc;                                        \
52140fa
     uout->pd = uin->pd;                                        \
52140fa
@@ -668,13 +668,11 @@
52140fa
 
52140fa
 static int m_Array_incRef(lua_State * L)
52140fa
 {
52140fa
-    int i;
52140fa
     udstruct *uin;
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    i = ((Array *) uin->d)->incRef();
52140fa
-    lua_pushinteger(L, i);
52140fa
+    lua_pushinteger(L, 1);
52140fa
     return 1;
52140fa
 }
52140fa
 
52140fa
@@ -685,8 +683,7 @@
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    i = ((Array *) uin->d)->decRef();
52140fa
-    lua_pushinteger(L, i);
52140fa
+    lua_pushinteger(L, 1);
52140fa
     return 1;
52140fa
 }
52140fa
 
52140fa
@@ -702,7 +699,7 @@
52140fa
     if ((uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         || (uobj->pd != NULL && uobj->pd->pc != uobj->pc))
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Array *) uin->d)->add(((Object *) uobj->d));
52140fa
+    ((Array *) uin->d)->add(std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -718,7 +715,7 @@
52140fa
     if (i > 0 && i <= len) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Array *) uin->d)->get(i - 1, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Array *) uin->d)->get(i - 1);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -739,7 +736,7 @@
52140fa
     if (i > 0 && i <= len) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Array *) uin->d)->getNF(i - 1, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Array *) uin->d)->getNF(i - 1);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -953,25 +950,21 @@
52140fa
 
52140fa
 static int m_Dict_incRef(lua_State * L)
52140fa
 {
52140fa
-    int i;
52140fa
     udstruct *uin;
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    i = ((Dict *) uin->d)->incRef();
52140fa
-    lua_pushinteger(L, i);
52140fa
+    lua_pushinteger(L, 1);
52140fa
     return 1;
52140fa
 }
52140fa
 
52140fa
 static int m_Dict_decRef(lua_State * L)
52140fa
 {
52140fa
-    int i;
52140fa
     udstruct *uin;
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    i = ((Dict *) uin->d)->decRef();
52140fa
-    lua_pushinteger(L, i);
52140fa
+    lua_pushinteger(L, 1);
52140fa
     return 1;
52140fa
 }
52140fa
 
52140fa
@@ -986,7 +979,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     s = copyString(luaL_checkstring(L, 2));
52140fa
     uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
52140fa
-    ((Dict *) uin->d)->add(s, ((Object *) uobj->d));
52140fa
+    ((Dict *) uin->d)->add(s, std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -999,7 +992,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     s = luaL_checkstring(L, 2);
52140fa
     uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
52140fa
-    ((Dict *) uin->d)->set(s, ((Object *) uobj->d));
52140fa
+    ((Dict *) uin->d)->set(s, std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1027,7 +1020,7 @@
52140fa
     s = luaL_checkstring(L, 2);
52140fa
     uout = new_Object_userdata(L);
52140fa
     uout->d = new Object();
52140fa
-    ((Dict *) uin->d)->lookup(s, (Object *) uout->d);
52140fa
+    *((Object *) uout->d) = ((Dict *) uin->d)->lookup(s);
52140fa
     uout->atype = ALLOC_LEPDF;
52140fa
     uout->pc = uin->pc;
52140fa
     uout->pd = uin->pd;
52140fa
@@ -1044,7 +1037,7 @@
52140fa
     s = luaL_checkstring(L, 2);
52140fa
     uout = new_Object_userdata(L);
52140fa
     uout->d = new Object();
52140fa
-    ((Dict *) uin->d)->lookupNF(s, (Object *) uout->d);
52140fa
+    *((Object *) uout->d) = ((Dict *) uin->d)->lookupNF(s);
52140fa
     uout->atype = ALLOC_LEPDF;
52140fa
     uout->pc = uin->pc;
52140fa
     uout->pd = uin->pd;
52140fa
@@ -1096,7 +1089,7 @@
52140fa
     if (i > 0 && i <= len) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Dict *) uin->d)->getVal(i - 1, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Dict *) uin->d)->getVal(i - 1);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -1117,7 +1110,7 @@
52140fa
     if (i > 0 && i <= len) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Dict *) uin->d)->getValNF(i - 1, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Dict *) uin->d)->getValNF(i - 1);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -1381,9 +1374,9 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     luaL_checktype(L, 2, LUA_TBOOLEAN);
52140fa
     if (lua_toboolean(L, 2) != 0)
52140fa
-        ((Object *) uin->d)->initBool(gTrue);
52140fa
+        *((Object *) uin->d) = Object(gTrue);
52140fa
     else
52140fa
-        ((Object *) uin->d)->initBool(gFalse);
52140fa
+        *((Object *) uin->d) = Object(gFalse);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1395,7 +1388,7 @@
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
     i = luaL_checkint(L, 2);
52140fa
-    ((Object *) uin->d)->initInt(i);
52140fa
+    *((Object *) uin->d) = Object(i);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1407,7 +1400,7 @@
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
     d = luaL_checknumber(L, 2);
52140fa
-    ((Object *) uin->d)->initReal(d);
52140fa
+    *((Object *) uin->d) = Object(d);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1422,7 +1415,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     s = luaL_checklstring(L, 2, &len;;
52140fa
     gs = new GooString(s, len);
52140fa
-    ((Object *) uin->d)->initString(gs);
52140fa
+    *((Object *) uin->d) = Object(gs);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1434,7 +1427,7 @@
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
     s = luaL_checkstring(L, 2);
52140fa
-    ((Object *) uin->d)->initName(s);
52140fa
+    *((Object *) uin->d) = Object(objName, s);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1444,13 +1437,14 @@
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initNull();
52140fa
+    *((Object *) uin->d) = Object(objNull);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
 static int m_Object_initArray(lua_State * L)
52140fa
 {
52140fa
     udstruct *uin, *uxref;
52140fa
+    Array *a;
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
52140fa
     uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
52140fa
     if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
52140fa
@@ -1458,7 +1452,8 @@
52140fa
     if ((uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initArray((XRef *) uxref->d);
52140fa
+    a = new Array((XRef *) uxref->d);
52140fa
+    *((Object *) uin->d) = Object(a);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1469,6 +1464,7 @@
52140fa
 static int m_Object_initDict(lua_State * L)
52140fa
 {
52140fa
     udstruct *uin, *uxref;
52140fa
+    Dict *d;
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
52140fa
     uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
52140fa
     if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
52140fa
@@ -1476,7 +1472,8 @@
52140fa
     if ((uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initDict((XRef *) uxref->d);
52140fa
+    d = new Dict((XRef *) uxref->d);
52140fa
+    *((Object *) uin->d) = Object(d);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1490,7 +1487,7 @@
52140fa
     if ((uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         || (ustream->pd != NULL && ustream->pd->pc != ustream->pc))
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initStream((Stream *) ustream->d);
52140fa
+    *((Object *) uin->d) = Object((Stream *) ustream->d);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1503,7 +1500,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     num = luaL_checkint(L, 2);
52140fa
     gen = luaL_checkint(L, 3);
52140fa
-    ((Object *) uin->d)->initRef(num, gen);
52140fa
+    *((Object *) uin->d) = Object(num, gen);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1515,7 +1512,7 @@
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
     s = luaL_checkstring(L, 2);
52140fa
-    ((Object *) uin->d)->initCmd(CHARP_CAST s);
52140fa
+    *((Object *) uin->d) = Object(objCmd, CHARP_CAST s);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1525,7 +1522,7 @@
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initError();
52140fa
+    *((Object *) uin->d) = Object(objError);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1535,7 +1532,7 @@
52140fa
     uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
52140fa
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
52140fa
         pdfdoc_changed_error(L);
52140fa
-    ((Object *) uin->d)->initEOF();
52140fa
+    *((Object *) uin->d) = Object(objEOF);
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1551,7 +1548,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     uout = new_Object_userdata(L);
52140fa
     uout->d = new Object();
52140fa
-    ((Object *) uin->d)->fetch((XRef *) uxref->d, (Object *) uout->d);
52140fa
+    *((Object *) uout->d) = ((Object *) uin->d)->fetch((XRef *) uxref->d);
52140fa
     uout->atype = ALLOC_LEPDF;
52140fa
     uout->pc = uin->pc;
52140fa
     uout->pd = uin->pd;
52140fa
@@ -1816,7 +1813,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     if (!((Object *) uin->d)->isArray())
52140fa
         luaL_error(L, "Object is not an Array");
52140fa
-    ((Object *) uin->d)->arrayAdd((Object *) uobj->d);
52140fa
+    ((Object *) uin->d)->arrayAdd(std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1833,7 +1830,7 @@
52140fa
         if (i > 0 && i <= len) {
52140fa
             uout = new_Object_userdata(L);
52140fa
             uout->d = new Object();
52140fa
-            ((Object *) uin->d)->arrayGet(i - 1, (Object *) uout->d);
52140fa
+            *((Object *) uout->d) = ((Object *) uin->d)->arrayGet(i - 1);
52140fa
             uout->atype = ALLOC_LEPDF;
52140fa
             uout->pc = uin->pc;
52140fa
             uout->pd = uin->pd;
52140fa
@@ -1857,7 +1854,7 @@
52140fa
         if (i > 0 && i <= len) {
52140fa
             uout = new_Object_userdata(L);
52140fa
             uout->d = new Object();
52140fa
-            ((Object *) uin->d)->arrayGetNF(i - 1, (Object *) uout->d);
52140fa
+            *((Object *) uout->d) = ((Object *) uin->d)->arrayGetNF(i - 1);
52140fa
             uout->atype = ALLOC_LEPDF;
52140fa
             uout->pc = uin->pc;
52140fa
             uout->pd = uin->pd;
52140fa
@@ -1897,7 +1894,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     if (!((Object *) uin->d)->isDict())
52140fa
         luaL_error(L, "Object is not a Dict");
52140fa
-    ((Object *) uin->d)->dictAdd(copyString(s), (Object *) uobj->d);
52140fa
+    ((Object *) uin->d)->dictAdd(copyString(s), std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1915,7 +1912,7 @@
52140fa
         pdfdoc_changed_error(L);
52140fa
     if (!((Object *) uin->d)->isDict())
52140fa
         luaL_error(L, "Object is not a Dict");
52140fa
-    ((Object *) uin->d)->dictSet(s, (Object *) uobj->d);
52140fa
+    ((Object *) uin->d)->dictSet(s, std::move(*((Object *) uobj->d)));
52140fa
     return 0;
52140fa
 }
52140fa
 
52140fa
@@ -1930,7 +1927,7 @@
52140fa
     if (((Object *) uin->d)->isDict()) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Object *) uin->d)->dictLookup(s, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Object *) uin->d)->dictLookup(s);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -1950,7 +1947,7 @@
52140fa
     if (((Object *) uin->d)->isDict()) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((Object *) uin->d)->dictLookupNF(s, (Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((Object *) uin->d)->dictLookupNF(s);
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -1991,7 +1988,7 @@
52140fa
         if (i > 0 && i <= len) {
52140fa
             uout = new_Object_userdata(L);
52140fa
             uout->d = new Object();
52140fa
-            ((Object *) uin->d)->dictGetVal(i - 1, (Object *) uout->d);
52140fa
+	    *((Object *) uout->d) = ((Object *) uin->d)->dictGetVal(i - 1);
52140fa
             uout->atype = ALLOC_LEPDF;
52140fa
             uout->pc = uin->pc;
52140fa
             uout->pd = uin->pd;
52140fa
@@ -2015,7 +2012,7 @@
52140fa
         if (i > 0 && i <= len) {
52140fa
             uout = new_Object_userdata(L);
52140fa
             uout->d = new Object();
52140fa
-            ((Object *) uin->d)->dictGetValNF(i - 1, (Object *) uout->d);
52140fa
+            *((Object *) uout->d) = ((Object *) uin->d)->dictGetValNF(i - 1);
52140fa
             uout->atype = ALLOC_LEPDF;
52140fa
             uout->pc = uin->pc;
52140fa
             uout->pd = uin->pd;
52140fa
@@ -2243,7 +2240,7 @@
52140fa
 m_poppler_get_poppler(Page, Dict, getPieceInfo);
52140fa
 m_poppler_get_poppler(Page, Dict, getSeparationInfo);
52140fa
 m_poppler_get_poppler(Page, Dict, getResourceDict);
52140fa
-m_poppler_get_OBJECT(Page, getAnnots);
52140fa
+m_poppler_get_OBJECT(Page, getAnnotsObject);
52140fa
 
52140fa
 m_poppler_get_OBJECT(Page, getContents);
52140fa
 
52140fa
@@ -2270,7 +2267,7 @@
52140fa
     {"getPieceInfo", m_Page_getPieceInfo},
52140fa
     {"getSeparationInfo", m_Page_getSeparationInfo},
52140fa
     {"getResourceDict", m_Page_getResourceDict},
52140fa
-    {"getAnnots", m_Page_getAnnots},
52140fa
+    {"getAnnots", m_Page_getAnnotsObject},
52140fa
     {"getContents", m_Page_getContents},
52140fa
     {"__tostring", m_Page__tostring},
52140fa
     {NULL, NULL}                // sentinel
52140fa
@@ -2520,7 +2517,7 @@
52140fa
     if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((PdfDocument *) uin->d)->doc->getDocInfo((Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfo();
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -2538,7 +2535,7 @@
52140fa
     if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
52140fa
         uout = new_Object_userdata(L);
52140fa
         uout->d = new Object();
52140fa
-        ((PdfDocument *) uin->d)->doc->getDocInfoNF((Object *) uout->d);
52140fa
+        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfoNF();
52140fa
         uout->atype = ALLOC_LEPDF;
52140fa
         uout->pc = uin->pc;
52140fa
         uout->pd = uin->pd;
52140fa
@@ -2841,7 +2838,7 @@
52140fa
     uout = new_Object_userdata(L);
52140fa
     uout->d = new Object();
52140fa
     origin = (Object *) (((Attribute *) uin->d)->getValue());
52140fa
-    origin->copy ( ((Object *)uout->d) );
52140fa
+    *((Object *) uout->d) = origin->copy();
52140fa
     uout->atype = ALLOC_LEPDF;
52140fa
     uout->pc = uin->pc;
52140fa
     uout->pd = uin->pd;
52140fa
@@ -3320,7 +3317,7 @@
52140fa
     parent = root->findParentElement(i-1);
52140fa
     if (parent != NULL) {
52140fa
        uout = new_StructElement_userdata(L);
52140fa
-       uout->d = new StructElement( *parent );
52140fa
+       uout->d = (StructElement *) parent;
52140fa
        uout->atype = ALLOC_LEPDF;
52140fa
        uout->pc = uin->pc;
52140fa
        uout->pd = uin->pd;
52140fa
@@ -3370,7 +3367,7 @@
52140fa
     gen = luaL_checkint(L, 3);
52140fa
     uout = new_Object_userdata(L);
52140fa
     uout->d = new Object();
52140fa
-    ((XRef *) uin->d)->fetch(num, gen, (Object *) uout->d);
52140fa
+    *((Object *) uout->d) = ((XRef *) uin->d)->fetch(num, gen);
52140fa
     uout->atype = ALLOC_LEPDF;
52140fa
     uout->pc = uin->pc;
52140fa
     uout->pd = uin->pd;
52140fa
--- texlive-base-20170520/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc.newpoppler	2017-05-08 22:39:36.692708395 +0200
52140fa
+++ texlive-base-20170520/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc	2017-09-19 09:48:19.658021769 +0200
52140fa
@@ -634,7 +634,7 @@
52140fa
       int i;
52140fa
       for (i=0;i
52140fa
 	Object *val = new Object();
52140fa
-	arrayref->get(i, val);
52140fa
+	*val = arrayref->get(i);
52140fa
 	if (val->isStream()) {
52140fa
 	  ObjectList *rover = self->_streams;
52140fa
 	  ObjectList *item = (ObjectList *)priv_xmalloc (sizeof(ObjectList));