2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-10-31 19:02:30 +00:00

Replace containers of PointerHolder with containers of std::shared_ptr

None of these are in the public API.
This commit is contained in:
Jay Berkenbilt 2022-02-04 11:03:52 -05:00
parent f0c2e0ef1e
commit abc300f05c
7 changed files with 45 additions and 31 deletions

View File

@ -16,6 +16,7 @@
#include <qpdf/Pl_DCT.hh> #include <qpdf/Pl_DCT.hh>
#include <qpdf/QIntC.hh> #include <qpdf/QIntC.hh>
#include <iostream> #include <iostream>
#include <memory>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -105,22 +106,25 @@ void
ImageProvider::provideStreamData(int objid, int generation, ImageProvider::provideStreamData(int objid, int generation,
Pipeline* pipeline) Pipeline* pipeline)
{ {
std::vector<PointerHolder<Pipeline> > to_delete; std::vector<std::shared_ptr<Pipeline>> to_delete;
Pipeline* p = pipeline; Pipeline* p = pipeline;
std::shared_ptr<Pipeline> p_new;
if (filter == "/DCTDecode") if (filter == "/DCTDecode")
{ {
p = new Pl_DCT( p_new = std::make_shared<Pl_DCT>(
"image encoder", pipeline, "image encoder", pipeline,
QIntC::to_uint(width), QIntC::to_uint(getHeight()), QIntC::to_uint(width), QIntC::to_uint(getHeight()),
QIntC::to_int(stripes[0].length()), j_color_space); QIntC::to_int(stripes[0].length()), j_color_space);
to_delete.push_back(p); to_delete.push_back(p_new);
p = p_new.get();
} }
else if (filter == "/RunLengthDecode") else if (filter == "/RunLengthDecode")
{ {
p = new Pl_RunLength( p_new = std::make_shared<Pl_RunLength>(
"image encoder", pipeline, Pl_RunLength::a_encode); "image encoder", pipeline, Pl_RunLength::a_encode);
to_delete.push_back(p); to_delete.push_back(p_new);
p = p_new.get();
} }
for (size_t i = 0; i < n_stripes; ++i) for (size_t i = 0; i < n_stripes; ++i)

View File

@ -1024,7 +1024,7 @@ class QPDF
QPDF& qpdf_for_warning, Pipeline*& pipeline, QPDF& qpdf_for_warning, Pipeline*& pipeline,
int objid, int generation, int objid, int generation,
QPDFObjectHandle& stream_dict, QPDFObjectHandle& stream_dict,
std::vector<PointerHolder<Pipeline> >& heap); std::vector<std::shared_ptr<Pipeline>>& heap);
// Methods to support object copying // Methods to support object copying
void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier,

View File

@ -35,6 +35,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <map> #include <map>
#include <memory>
#include <qpdf/Constants.h> #include <qpdf/Constants.h>
@ -684,7 +685,7 @@ class QPDFWriter
std::string extra_header_text; std::string extra_header_text;
int encryption_dict_objid; int encryption_dict_objid;
std::string cur_data_key; std::string cur_data_key;
std::list<PointerHolder<Pipeline> > to_delete; std::list<std::shared_ptr<Pipeline>> to_delete;
Pl_Count* pipeline; Pl_Count* pipeline;
std::list<QPDFObjectHandle> object_queue; std::list<QPDFObjectHandle> object_queue;
std::map<QPDFObjGen, int> obj_renumber; std::map<QPDFObjGen, int> obj_renumber;

View File

@ -2910,7 +2910,7 @@ QPDF::pipeStreamData(PointerHolder<EncryptionParameters> encp,
bool suppress_warnings, bool suppress_warnings,
bool will_retry) bool will_retry)
{ {
std::vector<PointerHolder<Pipeline> > to_delete; std::vector<std::shared_ptr<Pipeline>> to_delete;
if (encp->encrypted) if (encp->encrypted)
{ {
decryptStream(encp, file, qpdf_for_warning, decryptStream(encp, file, qpdf_for_warning,

View File

@ -132,9 +132,10 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file)
this->m->filename = description; this->m->filename = description;
this->m->file = file; this->m->file = file;
this->m->close_file = close_file; this->m->close_file = close_file;
Pipeline* p = new Pl_StdioFile("qpdf output", file); std::shared_ptr<Pipeline> p = std::make_shared<Pl_StdioFile>(
"qpdf output", file);
this->m->to_delete.push_back(p); this->m->to_delete.push_back(p);
initializePipelineStack(p); initializePipelineStack(p.get());
} }
void void
@ -142,7 +143,8 @@ QPDFWriter::setOutputMemory()
{ {
this->m->filename = "memory buffer"; this->m->filename = "memory buffer";
this->m->buffer_pipeline = new Pl_Buffer("qpdf output"); this->m->buffer_pipeline = new Pl_Buffer("qpdf output");
this->m->to_delete.push_back(this->m->buffer_pipeline); this->m->to_delete.push_back(
std::shared_ptr<Pipeline>(this->m->buffer_pipeline));
initializePipelineStack(this->m->buffer_pipeline); initializePipelineStack(this->m->buffer_pipeline);
} }
@ -1051,7 +1053,8 @@ void
QPDFWriter::initializePipelineStack(Pipeline *p) QPDFWriter::initializePipelineStack(Pipeline *p)
{ {
this->m->pipeline = new Pl_Count("pipeline stack base", p); this->m->pipeline = new Pl_Count("pipeline stack base", p);
this->m->to_delete.push_back(this->m->pipeline); this->m->to_delete.push_back(
std::shared_ptr<Pipeline>(this->m->pipeline));
this->m->pipeline_stack.push_back(this->m->pipeline); this->m->pipeline_stack.push_back(this->m->pipeline);
} }

View File

@ -463,34 +463,36 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
// create to be deleted when this function finishes. Pipelines // create to be deleted when this function finishes. Pipelines
// created by QPDFStreamFilter objects will be deleted by those // created by QPDFStreamFilter objects will be deleted by those
// objects. // objects.
std::vector<PointerHolder<Pipeline>> to_delete; std::vector<std::shared_ptr<Pipeline>> to_delete;
PointerHolder<ContentNormalizer> normalizer; PointerHolder<ContentNormalizer> normalizer;
std::shared_ptr<Pipeline> new_pipeline;
if (filter) if (filter)
{ {
if (encode_flags & qpdf_ef_compress) if (encode_flags & qpdf_ef_compress)
{ {
pipeline = new Pl_Flate("compress stream", pipeline, new_pipeline = std::make_shared<Pl_Flate>(
Pl_Flate::a_deflate); "compress stream", pipeline, Pl_Flate::a_deflate);
to_delete.push_back(pipeline); to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
} }
if (encode_flags & qpdf_ef_normalize) if (encode_flags & qpdf_ef_normalize)
{ {
normalizer = new ContentNormalizer(); normalizer = new ContentNormalizer();
pipeline = new Pl_QPDFTokenizer( new_pipeline = std::make_shared<Pl_QPDFTokenizer>(
"normalizer", normalizer.get(), pipeline); "normalizer", normalizer.get(), pipeline);
to_delete.push_back(pipeline); to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
} }
for (std::vector<PointerHolder< for (auto iter = this->token_filters.rbegin();
QPDFObjectHandle::TokenFilter> >::reverse_iterator iter =
this->token_filters.rbegin();
iter != this->token_filters.rend(); ++iter) iter != this->token_filters.rend(); ++iter)
{ {
pipeline = new Pl_QPDFTokenizer( new_pipeline = std::make_shared<Pl_QPDFTokenizer>(
"token filter", (*iter).get(), pipeline); "token filter", (*iter).get(), pipeline);
to_delete.push_back(pipeline); to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
} }
for (auto f_iter = filters.rbegin(); for (auto f_iter = filters.rbegin();

View File

@ -1238,7 +1238,7 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
QPDF& qpdf_for_warning, Pipeline*& pipeline, QPDF& qpdf_for_warning, Pipeline*& pipeline,
int objid, int generation, int objid, int generation,
QPDFObjectHandle& stream_dict, QPDFObjectHandle& stream_dict,
std::vector<PointerHolder<Pipeline> >& heap) std::vector<std::shared_ptr<Pipeline>>& heap)
{ {
std::string type; std::string type;
if (stream_dict.getKey("/Type").isName()) if (stream_dict.getKey("/Type").isName())
@ -1343,21 +1343,25 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
} }
} }
std::string key = getKeyForObject(encp, objid, generation, use_aes); std::string key = getKeyForObject(encp, objid, generation, use_aes);
std::shared_ptr<Pipeline> new_pipeline;
if (use_aes) if (use_aes)
{ {
QTC::TC("qpdf", "QPDF_encryption aes decode stream"); QTC::TC("qpdf", "QPDF_encryption aes decode stream");
pipeline = new Pl_AES_PDF("AES stream decryption", pipeline, new_pipeline = std::make_shared<Pl_AES_PDF>(
false, QUtil::unsigned_char_pointer(key), "AES stream decryption", pipeline,
key.length()); false, QUtil::unsigned_char_pointer(key),
key.length());
} }
else else
{ {
QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
pipeline = new Pl_RC4("RC4 stream decryption", pipeline, new_pipeline = std::make_shared<Pl_RC4>(
QUtil::unsigned_char_pointer(key), "RC4 stream decryption", pipeline,
toI(key.length())); QUtil::unsigned_char_pointer(key),
toI(key.length()));
} }
heap.push_back(pipeline); pipeline = new_pipeline.get();
heap.push_back(new_pipeline);
} }
void void