chiark / gitweb /
texlive-tlmgr: add subpackage
[termux-packages] / packages / texlive-bin / luatex-poppler-0.59.patch
1 --- ./texk/web2c/luatexdir/image/pdftoepdf.w    2018-01-23 07:12:10.789476867 +0000
2 +++ ../pdftoepdf.w      2018-01-23 08:08:05.626143676 +0000
3 @@ -27,6 +27,10 @@
4  /*
5      This file is mostly C and not very much C++; it's just used to interface
6      the functions of poppler, which happens to be written in C++.
7 +    Patches for the new poppler 0.59 from
8 +    https://www.mail-archive.com/arch-commits@archlinux.org/msg357548.html
9 +    with some modifications to comply the poppler API.
10 +
11  */
12  
13  extern void md5(Guchar *msg, int msgLen, Guchar *digest);
14 @@ -71,12 +75,7 @@
15          ck = (char *) malloc(PDF_CHECKSUM_SIZE);
16          if (ck == NULL)
17              formatted_error("pdf inclusion","out of memory while processing '%s'", a);
18 -        snprintf(ck, PDF_CHECKSUM_SIZE, "%"
19 -               PRIu64
20 -               "_%"
21 -               PRIu64,
22 -               (uint64_t) size,
23 -               (uint64_t) mtime);
24 +        snprintf(ck, PDF_CHECKSUM_SIZE, "%"@= @>PRIu64@= @>"_%"@=  @>PRIu64, (uint64_t) size,(uint64_t) mtime);
25     } else {
26          switch (fe) {
27              case FE_FAIL:
28 @@ -229,7 +228,7 @@
29          free(checksum);
30      }
31      if (pdf_doc->doc == NULL) {
32 -        docmemstream = new MemStream( docstream,0,streamsize, obj.initNull() );
33 +        docmemstream = new MemStream( docstream,0,streamsize, Object(objNull) );
34          doc = new PDFDoc(docmemstream); /* takes ownership of docmemstream */
35          pdf_doc->pc++;
36          if (!doc->isOk() || !doc->okToPrint()) {
37 @@ -413,9 +412,8 @@
38      Object obj1;
39      pdf_begin_array(pdf);
40      for (i = 0, l = array->getLength(); i < l; ++i) {
41 -        array->getNF(i, &obj1);
42 +        obj1 = array->getNF(i);
43          copyObject(pdf, pdf_doc, &obj1);
44 -        obj1.free();
45      }
46      pdf_end_array(pdf);
47  }
48 @@ -427,9 +425,8 @@
49      pdf_begin_dict(pdf);
50      for (i = 0, l = dict->getLength(); i < l; ++i) {
51          copyName(pdf, dict->getKey(i));
52 -        dict->getValNF(i, &obj1);
53 +        obj1 = dict->getValNF(i);
54          copyObject(pdf, pdf_doc, &obj1);
55 -        obj1.free();
56      }
57      pdf_end_dict(pdf);
58  }
59 @@ -515,13 +512,12 @@
60      PDFDoc *doc = pdf_doc->doc;
61      xref = doc->getXRef();
62      for (r = pdf_doc->inObjList; r != NULL;) {
63 -        xref->fetch(r->ref.num, r->ref.gen, &obj1);
64 +        obj1 = xref->fetch(r->ref.num, r->ref.gen);
65          if (obj1.isStream())
66              pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
67          else
68              pdf_begin_obj(pdf, r->num, 2);
69          copyObject(pdf, pdf_doc, &obj1);
70 -        obj1.free();
71          pdf_end_obj(pdf);
72          n = r->next;
73          delete r;
74 @@ -601,7 +597,7 @@
75          pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL);
76      else if (img_type(idict) == IMG_TYPE_PDFMEMSTREAM) {
77          pdf_doc = findPdfDocument(img_filepath(idict)) ;
78 -        if (pdf_doc == NULL ) 
79 +        if (pdf_doc == NULL )
80             normal_error("pdf inclusion", "memstream not initialized");
81          if (pdf_doc->doc == NULL)
82             normal_error("pdf inclusion", "memstream document is empty");
83 @@ -618,12 +614,12 @@
84      */
85      pdf_major_version_found = doc->getPDFMajorVersion();
86      pdf_minor_version_found = doc->getPDFMinorVersion();
87 -    if ((pdf_major_version_found > 1) || (pdf_minor_version_found > img_pdfminorversion(idict))) {
88 -        const char *msg = "PDF inclusion: found PDF version '%d.%d', but at most version '1.%d' allowed";
89 +    if ((100 * pdf_major_version_found + pdf_major_version_found) > (100 * img_pdfmajorversion(idict) + img_pdfminorversion(idict))) {
90 +        const char *msg = "PDF inclusion: found PDF version '%d.%d', but at most version '%d.%d' allowed";
91          if (img_errorlevel(idict) > 0) {
92 -            formatted_error("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfminorversion(idict));
93 +            formatted_error("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfmajorversion(idict), img_pdfminorversion(idict));
94          } else {
95 -            formatted_warning("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfminorversion(idict));
96 +            formatted_warning("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfmajorversion(idict), img_pdfminorversion(idict));
97          }
98      }
99      img_totalpages(idict) = catalog->getNumPages();
100 @@ -697,7 +693,7 @@
101              unrefPdfDocument(img_filepath(idict));
102          }
103  
104 -        and also unref'd in the finalizer zo we got an extra unrefs when garbage was
105 +        and also unref'd in the finalizer so we got an extra unrefs when garbage was
106          collected. However it is more efficient to keep the file open so we do that
107          now. The (slower) alternative is to unref here (which in most cases forcing a
108          close of the file) but then we must not call flush_pdf_info.
109 @@ -745,7 +741,7 @@
110      catalog = doc->getCatalog();
111      page = catalog->getPage(img_pagenum(idict));
112      pageref = catalog->getPageRef(img_pagenum(idict));
113 -    doc->getXRef()->fetch(pageref->num, pageref->gen, &pageobj);
114 +    pageobj = doc->getXRef()->fetch(pageref->num, pageref->gen);
115      pageDict = pageobj.getDict();
116      /* write the Page header */
117      pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER);
118 @@ -762,12 +758,11 @@
119          pdf_dict_add_int(pdf, "PTEX.PageNumber", (int) img_pagenum(idict));
120      }
121      if ((suppress_optional_info & 8) == 0) {
122 -        doc->getDocInfoNF(&obj1);
123 +        obj1 = doc->getDocInfoNF();
124          if (obj1.isRef()) {
125              /* the info dict must be indirect (PDF Ref p. 61) */
126              pdf_dict_add_ref(pdf, "PTEX.InfoDict", addInObj(pdf, pdf_doc, obj1.getRef()));
127          }
128 -        obj1.free();
129      }
130      if (img_is_bbox(idict)) {
131          bbox[0] = sp2bp(img_bbox(idict)[0]);
132 @@ -793,19 +788,17 @@
133          Now all relevant parts of the Page dictionary are copied. Metadata validity
134          check is needed(as a stream it must be indirect).
135      */
136 -    pageDict->lookupNF("Metadata", &obj1);
137 +    obj1 = pageDict->lookupNF("Metadata");
138      if (!obj1.isNull() && !obj1.isRef())
139          formatted_warning("pdf inclusion","/Metadata must be indirect object");
140 -    obj1.free();
141      /* copy selected items in Page dictionary */
142      for (i = 0; pagedictkeys[i] != NULL; i++) {
143 -        pageDict->lookupNF(pagedictkeys[i], &obj1);
144 +        obj1 = pageDict->lookupNF(pagedictkeys[i]);
145          if (!obj1.isNull()) {
146              pdf_add_name(pdf, pagedictkeys[i]);
147              /* preserves indirection */
148              copyObject(pdf, pdf_doc, &obj1);
149          }
150 -        obj1.free();
151      }
152      /*
153          If there are no Resources in the Page dict of the embedded page,
154 @@ -813,32 +806,28 @@
155          PDF file, climbing up the tree until the Resources are found.
156          (This fixes a problem with Scribus 1.3.3.14.)
157      */
158 -    pageDict->lookupNF("Resources", &obj1);
159 +    obj1 = pageDict->lookupNF("Resources");
160      if (obj1.isNull()) {
161          op1 = &pagesobj1;
162          op2 = &pagesobj2;
163 -        pageDict->lookup("Parent", op1);
164 +        *op1 = pageDict->lookup("Parent");
165          while (op1->isDict()) {
166 -            obj1.free();
167 -            op1->dictLookupNF("Resources", &obj1);
168 +            obj1 = op1->dictLookupNF("Resources");
169              if (!obj1.isNull()) {
170                  pdf_add_name(pdf, "Resources");
171                  copyObject(pdf, pdf_doc, &obj1);
172                  break;
173              }
174 -            op1->dictLookup("Parent", op2);
175 +            *op2 = op1->dictLookup("Parent");
176              optmp = op1;
177              op1 = op2;
178              op2 = optmp;
179 -            op2->free();
180          };
181          if (!op1->isDict())
182              formatted_warning("pdf inclusion","Page /Resources missing");
183 -        op1->free();
184      }
185 -    obj1.free();
186      /* Write the Page contents. */
187 -    page->getContents(&contents);
188 +    contents = page->getContents();
189      if (contents.isStream()) {
190          /*
191              Variant A: get stream and recompress under control of \pdfcompresslevel
192 @@ -849,27 +838,23 @@
193  
194              Variant B: copy stream without recompressing
195          */
196 -        contents.streamGetDict()->lookup("F", &obj1);
197 +        obj1 = contents.streamGetDict()->lookup("F");
198          if (!obj1.isNull()) {
199              normal_error("pdf inclusion","unsupported external stream");
200          }
201 -        obj1.free();
202 -        contents.streamGetDict()->lookup("Length", &obj1);
203 +        obj1 = contents.streamGetDict()->lookup("Length");
204          pdf_add_name(pdf, "Length");
205          copyObject(pdf, pdf_doc, &obj1);
206 -        obj1.free();
207 -        contents.streamGetDict()->lookup("Filter", &obj1);
208 +        obj1 = contents.streamGetDict()->lookup("Filter");
209          if (!obj1.isNull()) {
210              pdf_add_name(pdf, "Filter");
211              copyObject(pdf, pdf_doc, &obj1);
212 -            obj1.free();
213 -            contents.streamGetDict()->lookup("DecodeParms", &obj1);
214 +            obj1 = contents.streamGetDict()->lookup("DecodeParms");
215              if (!obj1.isNull()) {
216                  pdf_add_name(pdf, "DecodeParms");
217                  copyObject(pdf, pdf_doc, &obj1);
218              }
219          }
220 -        obj1.free();
221          pdf_end_dict(pdf);
222          pdf_begin_stream(pdf);
223          copyStreamStream(pdf, contents.getStream()->getUndecodedStream());
224 @@ -880,8 +865,8 @@
225          pdf_end_dict(pdf);
226          pdf_begin_stream(pdf);
227          for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
228 -            copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream());
229 -            obj1.free();
230 +            obj1 = contents.arrayGet(i);
231 +            copyStreamStream(pdf, obj1.getStream());
232              if (i < (l - 1)) {
233                  /*
234                      Put a space between streams to be on the safe side (streams
235 @@ -902,14 +887,18 @@
236      }
237      /* write out all indirect objects */
238      writeRefs(pdf, pdf_doc);
239 -    contents.free();
240 -    pageobj.free();
241      /*
242          unrefPdfDocument() must come after contents.free() and pageobj.free()!
243          TH: The next line makes repeated pdf inclusion unacceptably slow
244  
245          unrefPdfDocument(img_filepath(idict));
246      */
247 +
248 +if (! img_keepopen(idict)) {
249 +    unrefPdfDocument(img_filepath(idict));
250 +}
251 +
252 +
253  }
254  
255  /* Deallocate a PdfDocument with all its resources. */
256 --- ./texk/web2c/luatexdir/lua/lepdflib.cc      2017-03-11 01:04:06.000000000 +0000
257 +++ ../lepdflib.cc      2018-01-23 08:07:59.790233165 +0000
258 @@ -21,7 +21,9 @@
259  
260  #include "image/epdf.h"
261  
262 -
263 +// Patches for the new poppler 0.59 from
264 +// https://www.mail-archive.com/arch-commits@archlinux.org/msg357548.html
265 +// with some modifications to comply the poppler API.
266  
267  // define DEBUG
268  
269 @@ -253,6 +255,12 @@
270     lua_settable(L,-3)
271  
272  
273 +#define OBJECT_TYPE(name)                   \
274 +   lua_pushstring(L, #name);                \
275 +   lua_pushinteger(L, (int)name);           \
276 +   lua_settable(L,-3)
277 +
278 +
279  #define STRUCTELEMENT_TYPE_ENTRY(name)      \
280     lua_pushstring(L, #name);                \
281     lua_pushinteger(L, StructElement::name); \
282 @@ -306,6 +314,28 @@
283     return 1;
284  }
285  
286 +static int l_Object_Type(lua_State * L) {
287 +   lua_createtable(L,0,16);/*nr of ObjType values*/ ;
288 +   OBJECT_TYPE(objBool);
289 +   OBJECT_TYPE(objInt);
290 +   OBJECT_TYPE(objReal);
291 +   OBJECT_TYPE(objString);
292 +   OBJECT_TYPE(objName);
293 +   OBJECT_TYPE(objNull);
294 +   OBJECT_TYPE(objArray);
295 +   OBJECT_TYPE(objDict);
296 +   OBJECT_TYPE(objStream);
297 +   OBJECT_TYPE(objRef);
298 +   OBJECT_TYPE(objCmd);
299 +   OBJECT_TYPE(objError);
300 +   OBJECT_TYPE(objEOF);
301 +   OBJECT_TYPE(objNone);
302 +   OBJECT_TYPE(objInt64);
303 +   OBJECT_TYPE(objDead);
304 +   return 1;
305 +}
306 +
307 +
308  static int l_StructElement_Type(lua_State * L) {
309     lua_createtable (L, 0, 50);
310     STRUCTELEMENT_TYPE_ENTRY(Document);
311 @@ -398,14 +428,136 @@
312  static int l_new_Object(lua_State * L)
313  {
314      udstruct *uout;
315 +    int n = lua_gettop(L); // number of arguments
316      uout = new_Object_userdata(L);
317 -    uout->d = new Object();     // automatic init to type "none"
318 -    uout->atype = ALLOC_LEPDF;
319 -    uout->pc = 0;
320 -    uout->pd = NULL;            // not connected to any PDFDoc
321 +    switch(n) {
322 +    case 0:
323 +      uout->d = new Object();     // automatic init to type "none"
324 +      uout->atype = ALLOC_LEPDF;
325 +      uout->pc = 0;
326 +      uout->pd = NULL;            // not connected to any PDFDoc
327 +      break;
328 +    case 1:
329 +      if (lua_isboolean (L,1)) {
330 +       uout->d = new Object(lua_toboolean(L, 1)? gTrue : gFalse);
331 +       uout->atype = ALLOC_LEPDF;
332 +       uout->pc = 0;
333 +       uout->pd = NULL;
334 +      } else if (lua_isnumber (L,1)) {
335 +       double d = lua_tonumber(L,1);
336 +       // Missed :Object(long long int64gA)
337 +       if (d==((int)d)) {
338 +         uout->d = new Object((int)d);
339 +       } else {
340 +         uout->d = new Object(d);
341 +       }
342 +       uout->atype = ALLOC_LEPDF;
343 +       uout->pc = 0;
344 +       uout->pd = NULL;
345 +      } else if (lua_isstring (L,1)){
346 +       GooString *gs;
347 +       const char *s;
348 +       size_t len;
349 +       s = luaL_checklstring(L, 2, &len);
350 +       gs = new GooString(s, len);
351 +       uout->d = new Object(gs);
352 +       uout->atype = ALLOC_LEPDF;
353 +       uout->pc = 0;
354 +       uout->pd = NULL;
355 +      } else if (luaL_testudata(L,1,M_Array)){
356 +       udstruct *u;
357 +       Array *a;
358 +       u = (udstruct *) luaL_checkudata(L, 1, M_Array);
359 +       a = (Array *)u->d;
360 +       uout->d = new Object(a);
361 +       uout->atype = ALLOC_LEPDF;
362 +       uout->pc = 0;
363 +       uout->pd = NULL;
364 +      } else if (luaL_testudata(L,1,M_Dict)){
365 +       udstruct *u;
366 +       Dict *d;
367 +       u = (udstruct *) luaL_checkudata(L, 1, M_Dict);
368 +       d = (Dict *)u->d;
369 +       uout->d = new Object(d);
370 +       uout->atype = ALLOC_LEPDF;
371 +       uout->pc = 0;
372 +       uout->pd = NULL;
373 +      } else if (luaL_testudata(L,1,M_Stream)){
374 +       udstruct *u;
375 +       Stream *s;
376 +       u = (udstruct *) luaL_checkudata(L, 1, M_Stream);
377 +       s = (Stream *)u->d;
378 +       *((Object *) uout->d) = Object(s);
379 +      } else
380 +       luaL_error(L, "Invalid/unsupported value for Object constructor");
381 +      break;
382 +    case 2:
383 +      if (lua_isnumber (L,1) && lua_isnumber (L,2)) {
384 +       double numA = lua_tonumber(L,1);
385 +       double genA = lua_tonumber(L,2);
386 +       if ( ((numA)==(int)(numA)) && ((genA)==(int)(genA)) ){
387 +         uout->d = new Object((int)(numA), (int)(genA));
388 +         uout->atype = ALLOC_LEPDF;
389 +         uout->pc = 0;
390 +         uout->pd = NULL;
391 +       }
392 +      } else if (lua_isnumber (L,1) && (lua_isstring(L,2)|| lua_isnoneornil(L,2))) {
393 +       double d_typeA = lua_tonumber(L,1);
394 +       int typeA = (int)(d_typeA);
395 +       if (d_typeA==typeA){
396 +         switch((int)(typeA)) {
397 +         case     objBool:
398 +         case     objInt:
399 +         case     objReal:
400 +         case     objString:
401 +         case     objName:
402 +         case     objNull:
403 +         case     objArray:
404 +         case     objDict:
405 +         case     objStream:
406 +         case     objRef:
407 +         case     objCmd:
408 +         case     objError:
409 +         case     objEOF:
410 +         case     objNone:
411 +         case     objInt64:
412 +         case     objDead:
413 +           if (lua_isstring(L,2))
414 +             uout->d = new Object((ObjType)(typeA), luaL_checkstring(L, 2));
415 +           else
416 +             uout->d = new Object((ObjType)(typeA));
417 +           uout->atype = ALLOC_LEPDF;
418 +           uout->pc = 0;
419 +           uout->pd = NULL;
420 +
421 +           break;
422 +         default:
423 +           luaL_error(L, "Invalid values for Object constructor");
424 +           break;
425 +         }//switch((int)(d))
426 +       } else //  (d_typeA)!=(typeA)
427 +         luaL_error(L, "Invalid/unsupported values for Object constructor");
428 +      } // if (lua_isnumber (L,1) && (lua_isstring(L,2)|| lua_isnoneornil(L,2)))
429 +      break;
430 +    default:
431 +      luaL_error(L, "Invalid specification for Object constructor");
432 +    }
433 +    lua_settop(L,1);
434      return 1;
435  }
436  
437 +// static int l_new_Object(lua_State * L)
438 +// {
439 +//     udstruct *uout;
440 +//     uout = new_Object_userdata(L);
441 +//     uout->d = new Object();     // automatic init to type "none"
442 +//     uout->atype = ALLOC_LEPDF;
443 +//     uout->pc = 0;
444 +//     uout->pd = NULL;            // not connected to any PDFDoc
445 +//     return 1;
446 +// }
447 +
448 +
449  // PDFRectangle see Page.h
450  
451  static int l_new_PDFRectangle(lua_State * L)
452 @@ -429,6 +581,7 @@
453      {"AttributeOwner_Type",l_AttributeOwner_Type},
454      {"Dict", l_new_Dict},
455      {"Object", l_new_Object},
456 +    {"Object_Type", l_Object_Type},
457      {"PDFRectangle", l_new_PDFRectangle},
458      {NULL, NULL}                // sentinel
459  };
460 @@ -538,7 +691,7 @@
461          pdfdoc_changed_error(L);                               \
462      uout = new_Object_userdata(L);                             \
463      uout->d = new Object();                                    \
464 -    ((in *) uin->d)->function((Object *) uout->d);             \
465 +    *((Object *)uout->d) = ((in *) uin->d)->function();                  \
466      uout->atype = ALLOC_LEPDF;                                 \
467      uout->pc = uin->pc;                                        \
468      uout->pd = uin->pd;                                        \
469 @@ -665,30 +818,27 @@
470  
471  //**********************************************************************
472  // Array
473 -
474 -static int m_Array_incRef(lua_State * L)
475 -{
476 -    int i;
477 -    udstruct *uin;
478 -    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
479 -    if (uin->pd != NULL && uin->pd->pc != uin->pc)
480 -        pdfdoc_changed_error(L);
481 -    i = ((Array *) uin->d)->incRef();
482 -    lua_pushinteger(L, i);
483 -    return 1;
484 -}
485 -
486 -static int m_Array_decRef(lua_State * L)
487 -{
488 -    int i;
489 -    udstruct *uin;
490 -    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
491 -    if (uin->pd != NULL && uin->pd->pc != uin->pc)
492 -        pdfdoc_changed_error(L);
493 -    i = ((Array *) uin->d)->decRef();
494 -    lua_pushinteger(L, i);
495 -    return 1;
496 -}
497 +// Now private
498 +// static int m_Array_incRef(lua_State * L)
499 +// {
500 +//     udstruct *uin;
501 +//     uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
502 +//     if (uin->pd != NULL && uin->pd->pc != uin->pc)
503 +//         pdfdoc_changed_error(L);
504 +//     lua_pushinteger(L, 1);
505 +//     return 1;
506 +// }
507 +// Now private
508 +// static int m_Array_decRef(lua_State * L)
509 +// {
510 +//     int i;
511 +//     udstruct *uin;
512 +//     uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
513 +//     if (uin->pd != NULL && uin->pd->pc != uin->pc)
514 +//         pdfdoc_changed_error(L);
515 +//     lua_pushinteger(L, 1);
516 +//     return 1;
517 +// }
518  
519  m_poppler_get_INT(Array, getLength);
520  
521 @@ -702,7 +852,7 @@
522      if ((uin->pd != NULL && uin->pd->pc != uin->pc)
523          || (uobj->pd != NULL && uobj->pd->pc != uobj->pc))
524          pdfdoc_changed_error(L);
525 -    ((Array *) uin->d)->add(((Object *) uobj->d));
526 +    ((Array *) uin->d)->add(std::move(*((Object *) uobj->d)));
527      return 0;
528  }
529  
530 @@ -718,7 +868,7 @@
531      if (i > 0 && i <= len) {
532          uout = new_Object_userdata(L);
533          uout->d = new Object();
534 -        ((Array *) uin->d)->get(i - 1, (Object *) uout->d);
535 +        *((Object *) uout->d) = ((Array *) uin->d)->get(i - 1);
536          uout->atype = ALLOC_LEPDF;
537          uout->pc = uin->pc;
538          uout->pd = uin->pd;
539 @@ -739,7 +889,7 @@
540      if (i > 0 && i <= len) {
541          uout = new_Object_userdata(L);
542          uout->d = new Object();
543 -        ((Array *) uin->d)->getNF(i - 1, (Object *) uout->d);
544 +        *((Object *) uout->d) = ((Array *) uin->d)->getNF(i - 1);
545          uout->atype = ALLOC_LEPDF;
546          uout->pc = uin->pc;
547          uout->pd = uin->pd;
548 @@ -773,8 +923,8 @@
549  m_poppler__tostring(Array);
550  
551  static const struct luaL_Reg Array_m[] = {
552 -    {"incRef", m_Array_incRef},
553 -    {"decRef", m_Array_decRef},
554 +    // {"incRef", m_Array_incRef},// Now private
555 +    // {"decRef", m_Array_decRef},// Now private
556      {"getLength", m_Array_getLength},
557      {"add", m_Array_add},
558      {"get", m_Array_get},
559 @@ -950,30 +1100,26 @@
560  
561  //**********************************************************************
562  // Dict
563 -
564 -static int m_Dict_incRef(lua_State * L)
565 -{
566 -    int i;
567 -    udstruct *uin;
568 -    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
569 -    if (uin->pd != NULL && uin->pd->pc != uin->pc)
570 -        pdfdoc_changed_error(L);
571 -    i = ((Dict *) uin->d)->incRef();
572 -    lua_pushinteger(L, i);
573 -    return 1;
574 -}
575 -
576 -static int m_Dict_decRef(lua_State * L)
577 -{
578 -    int i;
579 -    udstruct *uin;
580 -    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
581 -    if (uin->pd != NULL && uin->pd->pc != uin->pc)
582 -        pdfdoc_changed_error(L);
583 -    i = ((Dict *) uin->d)->decRef();
584 -    lua_pushinteger(L, i);
585 -    return 1;
586 -}
587 +// Now private
588 +// static int m_Dict_incRef(lua_State * L)
589 +// {
590 +//     udstruct *uin;
591 +//     uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
592 +//     if (uin->pd != NULL && uin->pd->pc != uin->pc)
593 +//         pdfdoc_changed_error(L);
594 +//     lua_pushinteger(L, 1);
595 +//     return 1;
596 +// }
597 +// Now private
598 +// static int m_Dict_decRef(lua_State * L)
599 +// {
600 +//     udstruct *uin;
601 +//     uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
602 +//     if (uin->pd != NULL && uin->pd->pc != uin->pc)
603 +//         pdfdoc_changed_error(L);
604 +//     lua_pushinteger(L, 1);
605 +//     return 1;
606 +// }
607  
608  m_poppler_get_INT(Dict, getLength);
609  
610 @@ -986,7 +1132,7 @@
611          pdfdoc_changed_error(L);
612      s = copyString(luaL_checkstring(L, 2));
613      uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
614 -    ((Dict *) uin->d)->add(s, ((Object *) uobj->d));
615 +    ((Dict *) uin->d)->add(s, std::move(*((Object *) uobj->d)));
616      return 0;
617  }
618  
619 @@ -999,7 +1145,7 @@
620          pdfdoc_changed_error(L);
621      s = luaL_checkstring(L, 2);
622      uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
623 -    ((Dict *) uin->d)->set(s, ((Object *) uobj->d));
624 +    ((Dict *) uin->d)->set(s, std::move(*((Object *) uobj->d)));
625      return 0;
626  }
627  
628 @@ -1027,7 +1173,7 @@
629      s = luaL_checkstring(L, 2);
630      uout = new_Object_userdata(L);
631      uout->d = new Object();
632 -    ((Dict *) uin->d)->lookup(s, (Object *) uout->d);
633 +    *((Object *) uout->d) = ((Dict *) uin->d)->lookup(s);
634      uout->atype = ALLOC_LEPDF;
635      uout->pc = uin->pc;
636      uout->pd = uin->pd;
637 @@ -1044,7 +1190,7 @@
638      s = luaL_checkstring(L, 2);
639      uout = new_Object_userdata(L);
640      uout->d = new Object();
641 -    ((Dict *) uin->d)->lookupNF(s, (Object *) uout->d);
642 +    *((Object *) uout->d) = ((Dict *) uin->d)->lookupNF(s);
643      uout->atype = ALLOC_LEPDF;
644      uout->pc = uin->pc;
645      uout->pd = uin->pd;
646 @@ -1096,7 +1242,7 @@
647      if (i > 0 && i <= len) {
648          uout = new_Object_userdata(L);
649          uout->d = new Object();
650 -        ((Dict *) uin->d)->getVal(i - 1, (Object *) uout->d);
651 +        *((Object *) uout->d) = ((Dict *) uin->d)->getVal(i - 1);
652          uout->atype = ALLOC_LEPDF;
653          uout->pc = uin->pc;
654          uout->pd = uin->pd;
655 @@ -1117,7 +1263,7 @@
656      if (i > 0 && i <= len) {
657          uout = new_Object_userdata(L);
658          uout->d = new Object();
659 -        ((Dict *) uin->d)->getValNF(i - 1, (Object *) uout->d);
660 +        *((Object *) uout->d) = ((Dict *) uin->d)->getValNF(i - 1);
661          uout->atype = ALLOC_LEPDF;
662          uout->pc = uin->pc;
663          uout->pd = uin->pd;
664 @@ -1131,8 +1277,8 @@
665  m_poppler__tostring(Dict);
666  
667  static const struct luaL_Reg Dict_m[] = {
668 -    {"incRef", m_Dict_incRef},
669 -    {"decRef", m_Dict_decRef},
670 +    // {"incRef", m_Dict_incRef},// Now private
671 +    // {"decRef", m_Dict_decRef},// Now private
672      {"getLength", m_Dict_getLength},
673      {"add", m_Dict_add},
674      {"set", m_Dict_set},
675 @@ -1381,9 +1527,9 @@
676          pdfdoc_changed_error(L);
677      luaL_checktype(L, 2, LUA_TBOOLEAN);
678      if (lua_toboolean(L, 2) != 0)
679 -        ((Object *) uin->d)->initBool(gTrue);
680 +        *((Object *) uin->d) = Object(gTrue);
681      else
682 -        ((Object *) uin->d)->initBool(gFalse);
683 +        *((Object *) uin->d) = Object(gFalse);
684      return 0;
685  }
686  
687 @@ -1395,7 +1541,7 @@
688      if (uin->pd != NULL && uin->pd->pc != uin->pc)
689          pdfdoc_changed_error(L);
690      i = luaL_checkint(L, 2);
691 -    ((Object *) uin->d)->initInt(i);
692 +    *((Object *) uin->d) = Object(i);
693      return 0;
694  }
695  
696 @@ -1407,7 +1553,7 @@
697      if (uin->pd != NULL && uin->pd->pc != uin->pc)
698          pdfdoc_changed_error(L);
699      d = luaL_checknumber(L, 2);
700 -    ((Object *) uin->d)->initReal(d);
701 +    *((Object *) uin->d) = Object(d);
702      return 0;
703  }
704  
705 @@ -1422,7 +1568,7 @@
706          pdfdoc_changed_error(L);
707      s = luaL_checklstring(L, 2, &len);
708      gs = new GooString(s, len);
709 -    ((Object *) uin->d)->initString(gs);
710 +    *((Object *) uin->d) = Object(gs);
711      return 0;
712  }
713  
714 @@ -1434,7 +1580,7 @@
715      if (uin->pd != NULL && uin->pd->pc != uin->pc)
716          pdfdoc_changed_error(L);
717      s = luaL_checkstring(L, 2);
718 -    ((Object *) uin->d)->initName(s);
719 +    *((Object *) uin->d) = Object(objName, s);
720      return 0;
721  }
722  
723 @@ -1444,13 +1590,14 @@
724      uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
725      if (uin->pd != NULL && uin->pd->pc != uin->pc)
726          pdfdoc_changed_error(L);
727 -    ((Object *) uin->d)->initNull();
728 +    *((Object *) uin->d) = Object(objNull);
729      return 0;
730  }
731  
732  static int m_Object_initArray(lua_State * L)
733  {
734      udstruct *uin, *uxref;
735 +    Array *a;
736      uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
737      uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
738      if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
739 @@ -1458,7 +1605,8 @@
740      if ((uin->pd != NULL && uin->pd->pc != uin->pc)
741          || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
742          pdfdoc_changed_error(L);
743 -    ((Object *) uin->d)->initArray((XRef *) uxref->d);
744 +    a = new Array((XRef *) uxref->d);
745 +    *((Object *) uin->d) = Object(a);
746      return 0;
747  }
748  
749 @@ -1469,6 +1617,7 @@
750  static int m_Object_initDict(lua_State * L)
751  {
752      udstruct *uin, *uxref;
753 +    Dict *d;
754      uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
755      uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
756      if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
757 @@ -1476,7 +1625,8 @@
758      if ((uin->pd != NULL && uin->pd->pc != uin->pc)
759          || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
760          pdfdoc_changed_error(L);
761 -    ((Object *) uin->d)->initDict((XRef *) uxref->d);
762 +    d = new Dict((XRef *) uxref->d);
763 +    *((Object *) uin->d) = Object(d);
764      return 0;
765  }
766  
767 @@ -1490,7 +1640,7 @@
768      if ((uin->pd != NULL && uin->pd->pc != uin->pc)
769          || (ustream->pd != NULL && ustream->pd->pc != ustream->pc))
770          pdfdoc_changed_error(L);
771 -    ((Object *) uin->d)->initStream((Stream *) ustream->d);
772 +    *((Object *) uin->d) = Object((Stream *) ustream->d);
773      return 0;
774  }
775  
776 @@ -1503,7 +1653,7 @@
777          pdfdoc_changed_error(L);
778      num = luaL_checkint(L, 2);
779      gen = luaL_checkint(L, 3);
780 -    ((Object *) uin->d)->initRef(num, gen);
781 +    *((Object *) uin->d) = Object(num, gen);
782      return 0;
783  }
784  
785 @@ -1515,7 +1665,7 @@
786      if (uin->pd != NULL && uin->pd->pc != uin->pc)
787          pdfdoc_changed_error(L);
788      s = luaL_checkstring(L, 2);
789 -    ((Object *) uin->d)->initCmd(CHARP_CAST s);
790 +    *((Object *) uin->d) = Object(objCmd, CHARP_CAST s);
791      return 0;
792  }
793  
794 @@ -1525,7 +1675,7 @@
795      uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
796      if (uin->pd != NULL && uin->pd->pc != uin->pc)
797          pdfdoc_changed_error(L);
798 -    ((Object *) uin->d)->initError();
799 +    *((Object *) uin->d) = Object(objError);
800      return 0;
801  }
802  
803 @@ -1535,7 +1685,7 @@
804      uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
805      if (uin->pd != NULL && uin->pd->pc != uin->pc)
806          pdfdoc_changed_error(L);
807 -    ((Object *) uin->d)->initEOF();
808 +    *((Object *) uin->d) = Object(objEOF);
809      return 0;
810  }
811  
812 @@ -1551,7 +1701,7 @@
813          pdfdoc_changed_error(L);
814      uout = new_Object_userdata(L);
815      uout->d = new Object();
816 -    ((Object *) uin->d)->fetch((XRef *) uxref->d, (Object *) uout->d);
817 +    *((Object *) uout->d) = ((Object *) uin->d)->fetch((XRef *) uxref->d);
818      uout->atype = ALLOC_LEPDF;
819      uout->pc = uin->pc;
820      uout->pd = uin->pd;
821 @@ -1816,7 +1966,7 @@
822          pdfdoc_changed_error(L);
823      if (!((Object *) uin->d)->isArray())
824          luaL_error(L, "Object is not an Array");
825 -    ((Object *) uin->d)->arrayAdd((Object *) uobj->d);
826 +    ((Object *) uin->d)->arrayAdd(std::move(*((Object *) uobj->d)));
827      return 0;
828  }
829  
830 @@ -1833,7 +1983,7 @@
831          if (i > 0 && i <= len) {
832              uout = new_Object_userdata(L);
833              uout->d = new Object();
834 -            ((Object *) uin->d)->arrayGet(i - 1, (Object *) uout->d);
835 +            *((Object *) uout->d) = ((Object *) uin->d)->arrayGet(i - 1);
836              uout->atype = ALLOC_LEPDF;
837              uout->pc = uin->pc;
838              uout->pd = uin->pd;
839 @@ -1857,7 +2007,7 @@
840          if (i > 0 && i <= len) {
841              uout = new_Object_userdata(L);
842              uout->d = new Object();
843 -            ((Object *) uin->d)->arrayGetNF(i - 1, (Object *) uout->d);
844 +            *((Object *) uout->d) = ((Object *) uin->d)->arrayGetNF(i - 1);
845              uout->atype = ALLOC_LEPDF;
846              uout->pc = uin->pc;
847              uout->pd = uin->pd;
848 @@ -1897,7 +2047,7 @@
849          pdfdoc_changed_error(L);
850      if (!((Object *) uin->d)->isDict())
851          luaL_error(L, "Object is not a Dict");
852 -    ((Object *) uin->d)->dictAdd(copyString(s), (Object *) uobj->d);
853 +    ((Object *) uin->d)->dictAdd(copyString(s), std::move(*((Object *) uobj->d)));
854      return 0;
855  }
856  
857 @@ -1915,7 +2065,7 @@
858          pdfdoc_changed_error(L);
859      if (!((Object *) uin->d)->isDict())
860          luaL_error(L, "Object is not a Dict");
861 -    ((Object *) uin->d)->dictSet(s, (Object *) uobj->d);
862 +    ((Object *) uin->d)->dictSet(s, std::move(*((Object *) uobj->d)));
863      return 0;
864  }
865  
866 @@ -1930,7 +2080,7 @@
867      if (((Object *) uin->d)->isDict()) {
868          uout = new_Object_userdata(L);
869          uout->d = new Object();
870 -        ((Object *) uin->d)->dictLookup(s, (Object *) uout->d);
871 +        *((Object *) uout->d) = ((Object *) uin->d)->dictLookup(s);
872          uout->atype = ALLOC_LEPDF;
873          uout->pc = uin->pc;
874          uout->pd = uin->pd;
875 @@ -1950,7 +2100,7 @@
876      if (((Object *) uin->d)->isDict()) {
877          uout = new_Object_userdata(L);
878          uout->d = new Object();
879 -        ((Object *) uin->d)->dictLookupNF(s, (Object *) uout->d);
880 +        *((Object *) uout->d) = ((Object *) uin->d)->dictLookupNF(s);
881          uout->atype = ALLOC_LEPDF;
882          uout->pc = uin->pc;
883          uout->pd = uin->pd;
884 @@ -1991,7 +2141,7 @@
885          if (i > 0 && i <= len) {
886              uout = new_Object_userdata(L);
887              uout->d = new Object();
888 -            ((Object *) uin->d)->dictGetVal(i - 1, (Object *) uout->d);
889 +           *((Object *) uout->d) = ((Object *) uin->d)->dictGetVal(i - 1);
890              uout->atype = ALLOC_LEPDF;
891              uout->pc = uin->pc;
892              uout->pd = uin->pd;
893 @@ -2015,7 +2165,7 @@
894          if (i > 0 && i <= len) {
895              uout = new_Object_userdata(L);
896              uout->d = new Object();
897 -            ((Object *) uin->d)->dictGetValNF(i - 1, (Object *) uout->d);
898 +            *((Object *) uout->d) = ((Object *) uin->d)->dictGetValNF(i - 1);
899              uout->atype = ALLOC_LEPDF;
900              uout->pc = uin->pc;
901              uout->pd = uin->pd;
902 @@ -2243,7 +2393,7 @@
903  m_poppler_get_poppler(Page, Dict, getPieceInfo);
904  m_poppler_get_poppler(Page, Dict, getSeparationInfo);
905  m_poppler_get_poppler(Page, Dict, getResourceDict);
906 -m_poppler_get_OBJECT(Page, getAnnots);
907 +m_poppler_get_OBJECT(Page, getAnnotsObject);
908  
909  m_poppler_get_OBJECT(Page, getContents);
910  
911 @@ -2270,7 +2420,7 @@
912      {"getPieceInfo", m_Page_getPieceInfo},
913      {"getSeparationInfo", m_Page_getSeparationInfo},
914      {"getResourceDict", m_Page_getResourceDict},
915 -    {"getAnnots", m_Page_getAnnots},
916 +    {"getAnnotsObject", m_Page_getAnnotsObject},
917      {"getContents", m_Page_getContents},
918      {"__tostring", m_Page__tostring},
919      {NULL, NULL}                // sentinel
920 @@ -2520,7 +2670,7 @@
921      if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
922          uout = new_Object_userdata(L);
923          uout->d = new Object();
924 -        ((PdfDocument *) uin->d)->doc->getDocInfo((Object *) uout->d);
925 +        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfo();
926          uout->atype = ALLOC_LEPDF;
927          uout->pc = uin->pc;
928          uout->pd = uin->pd;
929 @@ -2538,7 +2688,7 @@
930      if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
931          uout = new_Object_userdata(L);
932          uout->d = new Object();
933 -        ((PdfDocument *) uin->d)->doc->getDocInfoNF((Object *) uout->d);
934 +        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfoNF();
935          uout->atype = ALLOC_LEPDF;
936          uout->pc = uin->pc;
937          uout->pd = uin->pd;
938 @@ -2841,7 +2991,7 @@
939      uout = new_Object_userdata(L);
940      uout->d = new Object();
941      origin = (Object *) (((Attribute *) uin->d)->getValue());
942 -    origin->copy ( ((Object *)uout->d) );
943 +    *((Object *) uout->d) = origin->copy();
944      uout->atype = ALLOC_LEPDF;
945      uout->pc = uin->pc;
946      uout->pd = uin->pd;
947 @@ -3320,7 +3470,8 @@
948      parent = root->findParentElement(i-1);
949      if (parent != NULL) {
950         uout = new_StructElement_userdata(L);
951 -       uout->d = new StructElement( *parent );
952 +       // see https://isocpp.org/wiki/faq/const-correctness#aliasing-and-const
953 +       uout->d = (StructElement *) parent;
954         uout->atype = ALLOC_LEPDF;
955         uout->pc = uin->pc;
956         uout->pd = uin->pd;
957 @@ -3331,7 +3482,6 @@
958  
959  
960  static const struct luaL_Reg StructTreeRoot_m[] = {
961 -  {"findParentElement", m_StructTreeRoot_findParentElement},
962    {"getDoc",m_StructTreeRoot_getDoc},
963    {"getRoleMap",m_StructTreeRoot_getRoleMap},
964    {"getClassMap",m_StructTreeRoot_getClassMap},
965 @@ -3370,7 +3520,7 @@
966      gen = luaL_checkint(L, 3);
967      uout = new_Object_userdata(L);
968      uout->d = new Object();
969 -    ((XRef *) uin->d)->fetch(num, gen, (Object *) uout->d);
970 +    *((Object *) uout->d) = ((XRef *) uin->d)->fetch(num, gen);
971      uout->atype = ALLOC_LEPDF;
972      uout->pc = uin->pc;
973      uout->pd = uin->pd;
974 @@ -3449,7 +3599,7 @@
975      lua_setfield(L, -2, "__index");         \
976      lua_pushstring(L, "no user access");    \
977      lua_setfield(L, -2, "__metatable");     \
978 -    luaL_register(L, NULL, type##_m)
979 +    luaL_openlib(L, NULL, type##_m, 0)
980  #else
981  #define setfuncs_meta(type)                 \
982      luaL_newmetatable(L, M_##type);         \
983 @@ -3484,6 +3634,6 @@
984      setfuncs_meta(TextSpan);
985      setfuncs_meta(XRef);
986      setfuncs_meta(XRefEntry);
987 -    luaL_register(L, "epdf", epdflib_f);
988 +    luaL_openlib(L, "epdf", epdflib_f, 0);
989      return 1;
990  }
991 --- ./texk/web2c/luatexdir/lua/lpdfscannerlib.cc        2016-11-25 18:09:15.000000000 +0000
992 +++ ../lpdfscannerlib.cc        2018-01-23 08:07:59.790233165 +0000
993 @@ -634,7 +634,7 @@
994        int i;
995        for (i=0;i<count;i++) {
996         Object *val = new Object();
997 -       arrayref->get(i, val);
998 +       *val = arrayref->get(i);
999         if (val->isStream()) {
1000           ObjectList *rover = self->_streams;
1001           ObjectList *item = (ObjectList *)priv_xmalloc (sizeof(ObjectList));
1002 @@ -944,8 +944,8 @@
1003      luaL_openlib(L, 0, scannerlib_meta, 0);
1004      lua_pushvalue(L, -1);
1005      lua_setfield(L, -2, "__index");
1006 -    luaL_register(L, NULL, scannerlib_m);
1007 -    luaL_register(L, "pdfscanner", scannerlib);
1008 +    luaL_openlib(L, NULL, scannerlib_m, 0);
1009 +    luaL_openlib(L, "pdfscanner", scannerlib, 0);
1010      return 1;
1011  }
1012  
1013 --- ./texk/web2c/luatexdir/image/image.h        2017-02-04 01:04:04.000000000 +0000
1014 +++ ../image.h  2018-01-23 09:09:10.241949055 +0000
1015 @@ -126,6 +126,7 @@
1016      int luaref ;
1017      boolean keepopen;
1018      int errorlevel;
1019 +    int pdfmajorversion;
1020      int pdfminorversion;
1021      union {
1022          pdf_stream_struct *pdfstream;
1023 @@ -171,6 +172,7 @@
1024  #  define img_luaref(N)           ((N)->luaref)
1025  #  define img_keepopen(N)         ((N)->keepopen)
1026  #  define img_errorlevel(N)       ((N)->errorlevel)
1027 +#  define img_pdfmajorversion(N)  ((N)->pdfmajorversion)
1028  #  define img_pdfminorversion(N)  ((N)->pdfminorversion)
1029  
1030  #  define img_pdfstream_ptr(N)    ((N)->img_struct.pdfstream)