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
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.
13 extern void md5(Guchar *msg, int msgLen, Guchar *digest);
15 ck = (char *) malloc(PDF_CHECKSUM_SIZE);
17 formatted_error("pdf inclusion","out of memory while processing '%s'", a);
18 - snprintf(ck, PDF_CHECKSUM_SIZE, "%"
24 + snprintf(ck, PDF_CHECKSUM_SIZE, "%"@= @>PRIu64@= @>"_%"@= @>PRIu64, (uint64_t) size,(uint64_t) mtime);
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 */
36 if (!doc->isOk() || !doc->okToPrint()) {
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);
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);
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);
66 pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
68 pdf_begin_obj(pdf, r->num, 2);
69 copyObject(pdf, pdf_doc, &obj1);
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");
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));
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));
99 img_totalpages(idict) = catalog->getNumPages();
101 unrefPdfDocument(img_filepath(idict));
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.
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));
121 if ((suppress_optional_info & 8) == 0) {
122 - doc->getDocInfoNF(&obj1);
123 + obj1 = doc->getDocInfoNF();
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()));
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).
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");
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);
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.)
158 - pageDict->lookupNF("Resources", &obj1);
159 + obj1 = pageDict->lookupNF("Resources");
163 - pageDict->lookup("Parent", op1);
164 + *op1 = pageDict->lookup("Parent");
165 while (op1->isDict()) {
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);
174 - op1->dictLookup("Parent", op2);
175 + *op2 = op1->dictLookup("Parent");
182 formatted_warning("pdf inclusion","Page /Resources missing");
186 /* Write the Page contents. */
187 - page->getContents(&contents);
188 + contents = page->getContents();
189 if (contents.isStream()) {
191 Variant A: get stream and recompress under control of \pdfcompresslevel
192 @@ -849,27 +838,23 @@
194 Variant B: copy stream without recompressing
196 - contents.streamGetDict()->lookup("F", &obj1);
197 + obj1 = contents.streamGetDict()->lookup("F");
198 if (!obj1.isNull()) {
199 normal_error("pdf inclusion","unsupported external stream");
202 - contents.streamGetDict()->lookup("Length", &obj1);
203 + obj1 = contents.streamGetDict()->lookup("Length");
204 pdf_add_name(pdf, "Length");
205 copyObject(pdf, pdf_doc, &obj1);
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);
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);
222 pdf_begin_stream(pdf);
223 copyStreamStream(pdf, contents.getStream()->getUndecodedStream());
226 pdf_begin_stream(pdf);
227 for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
228 - copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream());
230 + obj1 = contents.arrayGet(i);
231 + copyStreamStream(pdf, obj1.getStream());
234 Put a space between streams to be on the safe side (streams
235 @@ -902,14 +887,18 @@
237 /* write out all indirect objects */
238 writeRefs(pdf, pdf_doc);
242 unrefPdfDocument() must come after contents.free() and pageobj.free()!
243 TH: The next line makes repeated pdf inclusion unacceptably slow
245 unrefPdfDocument(img_filepath(idict));
248 +if (! img_keepopen(idict)) {
249 + unrefPdfDocument(img_filepath(idict));
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
260 #include "image/epdf.h"
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.
273 +#define OBJECT_TYPE(name) \
274 + lua_pushstring(L, #name); \
275 + lua_pushinteger(L, (int)name); \
279 #define STRUCTELEMENT_TYPE_ENTRY(name) \
280 lua_pushstring(L, #name); \
281 lua_pushinteger(L, StructElement::name); \
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);
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)
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;
320 - uout->pd = NULL; // not connected to any PDFDoc
323 + uout->d = new Object(); // automatic init to type "none"
324 + uout->atype = ALLOC_LEPDF;
326 + uout->pd = NULL; // not connected to any PDFDoc
329 + if (lua_isboolean (L,1)) {
330 + uout->d = new Object(lua_toboolean(L, 1)? gTrue : gFalse);
331 + uout->atype = ALLOC_LEPDF;
334 + } else if (lua_isnumber (L,1)) {
335 + double d = lua_tonumber(L,1);
336 + // Missed :Object(long long int64gA)
338 + uout->d = new Object((int)d);
340 + uout->d = new Object(d);
342 + uout->atype = ALLOC_LEPDF;
345 + } else if (lua_isstring (L,1)){
349 + s = luaL_checklstring(L, 2, &len);
350 + gs = new GooString(s, len);
351 + uout->d = new Object(gs);
352 + uout->atype = ALLOC_LEPDF;
355 + } else if (luaL_testudata(L,1,M_Array)){
358 + u = (udstruct *) luaL_checkudata(L, 1, M_Array);
360 + uout->d = new Object(a);
361 + uout->atype = ALLOC_LEPDF;
364 + } else if (luaL_testudata(L,1,M_Dict)){
367 + u = (udstruct *) luaL_checkudata(L, 1, M_Dict);
369 + uout->d = new Object(d);
370 + uout->atype = ALLOC_LEPDF;
373 + } else if (luaL_testudata(L,1,M_Stream)){
376 + u = (udstruct *) luaL_checkudata(L, 1, M_Stream);
377 + s = (Stream *)u->d;
378 + *((Object *) uout->d) = Object(s);
380 + luaL_error(L, "Invalid/unsupported value for Object constructor");
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;
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)) {
413 + if (lua_isstring(L,2))
414 + uout->d = new Object((ObjType)(typeA), luaL_checkstring(L, 2));
416 + uout->d = new Object((ObjType)(typeA));
417 + uout->atype = ALLOC_LEPDF;
423 + luaL_error(L, "Invalid values for Object constructor");
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)))
431 + luaL_error(L, "Invalid specification for Object constructor");
437 +// static int l_new_Object(lua_State * L)
440 +// uout = new_Object_userdata(L);
441 +// uout->d = new Object(); // automatic init to type "none"
442 +// uout->atype = ALLOC_LEPDF;
444 +// uout->pd = NULL; // not connected to any PDFDoc
449 // PDFRectangle see Page.h
451 static int l_new_PDFRectangle(lua_State * L)
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
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 @@
471 //**********************************************************************
474 -static int m_Array_incRef(lua_State * L)
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);
486 -static int m_Array_decRef(lua_State * L)
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);
498 +// static int m_Array_incRef(lua_State * L)
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);
508 +// static int m_Array_decRef(lua_State * L)
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);
519 m_poppler_get_INT(Array, getLength);
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)));
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;
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;
549 m_poppler__tostring(Array);
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 @@
561 //**********************************************************************
564 -static int m_Dict_incRef(lua_State * L)
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);
576 -static int m_Dict_decRef(lua_State * L)
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);
588 +// static int m_Dict_incRef(lua_State * L)
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);
598 +// static int m_Dict_decRef(lua_State * L)
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);
608 m_poppler_get_INT(Dict, getLength);
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)));
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)));
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;
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;
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;
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;
664 @@ -1131,8 +1277,8 @@
665 m_poppler__tostring(Dict);
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},
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);
682 - ((Object *) uin->d)->initBool(gFalse);
683 + *((Object *) uin->d) = Object(gFalse);
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);
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);
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);
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);
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);
732 static int m_Object_initArray(lua_State * L)
734 udstruct *uin, *uxref;
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);
749 @@ -1469,6 +1617,7 @@
750 static int m_Object_initDict(lua_State * L)
752 udstruct *uin, *uxref;
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);
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);
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);
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);
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);
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);
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;
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)));
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;
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;
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)));
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)));
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;
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;
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;
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;
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);
909 m_poppler_get_OBJECT(Page, getContents);
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;
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;
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;
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;
957 @@ -3331,7 +3482,6 @@
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;
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)
981 #define setfuncs_meta(type) \
982 luaL_newmetatable(L, M_##type); \
983 @@ -3484,6 +3634,6 @@
984 setfuncs_meta(TextSpan);
986 setfuncs_meta(XRefEntry);
987 - luaL_register(L, "epdf", epdflib_f);
988 + luaL_openlib(L, "epdf", epdflib_f, 0);
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
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));
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);
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
1019 + int pdfmajorversion;
1020 int pdfminorversion;
1022 pdf_stream_struct *pdfstream;
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)
1030 # define img_pdfstream_ptr(N) ((N)->img_struct.pdfstream)