Commit cfaae47dc6704a54e3e84decbfbe8840c33f2fc4
1 parent
3e98fe46
Add getBufferSharedPointer() to Pl_Buffer and QPDFWriter
Showing
6 changed files
with
32 additions
and
5 deletions
ChangeLog
| 1 | 2022-02-06 Jay Berkenbilt <ejb@ql.org> | 1 | 2022-02-06 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Pl_Buffer and QPDFWriter: add getBufferSharedPointer(), which | ||
| 4 | + turns a PointerHolder<Buffer> but will return a | ||
| 5 | + std::shared_ptr<Buffer> in qpdf 11. | ||
| 6 | + | ||
| 3 | * From m-holger: add getKeyIfDict(), which calls getKey for | 7 | * From m-holger: add getKeyIfDict(), which calls getKey for |
| 4 | dictionaries and returns null if called on null. This is for | 8 | dictionaries and returns null if called on null. This is for |
| 5 | easier access to optional, lower-level dictionaries. | 9 | easier access to optional, lower-level dictionaries. |
TODO
| @@ -420,6 +420,8 @@ auto x = std::make_unique<T[]>(5) | @@ -420,6 +420,8 @@ auto x = std::make_unique<T[]>(5) | ||
| 420 | 420 | ||
| 421 | PointerHolder in public API: | 421 | PointerHolder in public API: |
| 422 | 422 | ||
| 423 | + PointerHolder<Buffer> Pl_Buffer::getBufferSharedPointer(); | ||
| 424 | + PointerHolder<Buffer> QPDFWriter::getBufferSharedPointer(); | ||
| 423 | QUtil::read_file_into_memory( | 425 | QUtil::read_file_into_memory( |
| 424 | char const*, PointerHolder<char>&, unsigned long&) | 426 | char const*, PointerHolder<char>&, unsigned long&) |
| 425 | QPDFObjectHandle::addContentTokenFilter( | 427 | QPDFObjectHandle::addContentTokenFilter( |
include/qpdf/Pl_Buffer.hh
| @@ -51,10 +51,14 @@ class Pl_Buffer: public Pipeline | @@ -51,10 +51,14 @@ class Pl_Buffer: public Pipeline | ||
| 51 | 51 | ||
| 52 | // Each call to getBuffer() resets this object -- see notes above. | 52 | // Each call to getBuffer() resets this object -- see notes above. |
| 53 | // The caller is responsible for deleting the returned Buffer | 53 | // The caller is responsible for deleting the returned Buffer |
| 54 | - // object. | 54 | + // object. See also getBufferSharedPointer() and getMallocBuffer(). |
| 55 | QPDF_DLL | 55 | QPDF_DLL |
| 56 | Buffer* getBuffer(); | 56 | Buffer* getBuffer(); |
| 57 | 57 | ||
| 58 | + // Same as getBuffer but wraps the result in a shared pointer. | ||
| 59 | + QPDF_DLL | ||
| 60 | + PointerHolder<Buffer> getBufferSharedPointer(); | ||
| 61 | + | ||
| 58 | // getMallocBuffer behaves in the same was as getBuffer except the | 62 | // getMallocBuffer behaves in the same was as getBuffer except the |
| 59 | // buffer is allocated with malloc(), making it suitable for use | 63 | // buffer is allocated with malloc(), making it suitable for use |
| 60 | // when calling from other languages. If there is no data, *buf is | 64 | // when calling from other languages. If there is no data, *buf is |
include/qpdf/QPDFWriter.hh
| @@ -118,13 +118,18 @@ class QPDFWriter | @@ -118,13 +118,18 @@ class QPDFWriter | ||
| 118 | QPDF_DLL | 118 | QPDF_DLL |
| 119 | void setOutputMemory(); | 119 | void setOutputMemory(); |
| 120 | 120 | ||
| 121 | - // Return the buffer object containing the PDF file. If | 121 | + // Return the buffer object containing the PDF file. If |
| 122 | // setOutputMemory() has been called, this method may be called | 122 | // setOutputMemory() has been called, this method may be called |
| 123 | - // exactly one time after write() has returned. The caller is | ||
| 124 | - // responsible for deleting the buffer when done. | 123 | + // exactly one time after write() has returned. The caller is |
| 124 | + // responsible for deleting the buffer when done. See also | ||
| 125 | + // getBufferSharedPointer(). | ||
| 125 | QPDF_DLL | 126 | QPDF_DLL |
| 126 | Buffer* getBuffer(); | 127 | Buffer* getBuffer(); |
| 127 | 128 | ||
| 129 | + // Return getBuffer() in a shared pointer. | ||
| 130 | + QPDF_DLL | ||
| 131 | + PointerHolder<Buffer> getBufferSharedPointer(); | ||
| 132 | + | ||
| 128 | // Supply your own pipeline object. Output will be written to | 133 | // Supply your own pipeline object. Output will be written to |
| 129 | // this pipeline, and QPDFWriter will call finish() on the | 134 | // this pipeline, and QPDFWriter will call finish() on the |
| 130 | // pipeline. It is the caller's responsibility to manage the | 135 | // pipeline. It is the caller's responsibility to manage the |
libqpdf/Pl_Buffer.cc
| @@ -79,10 +79,16 @@ Pl_Buffer::getBuffer() | @@ -79,10 +79,16 @@ Pl_Buffer::getBuffer() | ||
| 79 | unsigned char* p = b->getBuffer(); | 79 | unsigned char* p = b->getBuffer(); |
| 80 | memcpy(p, this->m->data->getBuffer(), this->m->total_size); | 80 | memcpy(p, this->m->data->getBuffer(), this->m->total_size); |
| 81 | } | 81 | } |
| 82 | - this->m = new Members(); | 82 | + this->m = PointerHolder<Members>(new Members()); |
| 83 | return b; | 83 | return b; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | +PointerHolder<Buffer> | ||
| 87 | +Pl_Buffer::getBufferSharedPointer() | ||
| 88 | +{ | ||
| 89 | + return PointerHolder<Buffer>(getBuffer()); | ||
| 90 | +} | ||
| 91 | + | ||
| 86 | void | 92 | void |
| 87 | Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) | 93 | Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) |
| 88 | { | 94 | { |
libqpdf/QPDFWriter.cc
| @@ -157,6 +157,12 @@ QPDFWriter::getBuffer() | @@ -157,6 +157,12 @@ QPDFWriter::getBuffer() | ||
| 157 | return result; | 157 | return result; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | +PointerHolder<Buffer> | ||
| 161 | +QPDFWriter::getBufferSharedPointer() | ||
| 162 | +{ | ||
| 163 | + return PointerHolder<Buffer>(getBuffer()); | ||
| 164 | +} | ||
| 165 | + | ||
| 160 | void | 166 | void |
| 161 | QPDFWriter::setOutputPipeline(Pipeline* p) | 167 | QPDFWriter::setOutputPipeline(Pipeline* p) |
| 162 | { | 168 | { |