aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2011-08-11 17:56:37 +0200
committerJay Berkenbilt <ejb@ql.org>2011-08-11 17:57:37 +0200
commit76b1659177327a64037bf36d7f3e15a73d86bbed (patch)
tree22623001bb99a6fe33943416877a3d5836b550d8 /include
parent14fe2e6de3ae3b91436ccb4948fca75c29565440 (diff)
downloadqpdf-76b1659177327a64037bf36d7f3e15a73d86bbed.tar.zst
enhance PointerHolder so that it can explicitly be told to use delete [] instead of delete, thus making it useful to run valgrind over qpdf during its test suite
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/PointerHolder.hh46
-rw-r--r--include/qpdf/qpdf-c.h19
2 files changed, 34 insertions, 31 deletions
diff --git a/include/qpdf/PointerHolder.hh b/include/qpdf/PointerHolder.hh
index b9bce8ee..b161c100 100644
--- a/include/qpdf/PointerHolder.hh
+++ b/include/qpdf/PointerHolder.hh
@@ -8,8 +8,6 @@
#ifndef __POINTERHOLDER_HH__
#define __POINTERHOLDER_HH__
-#include <iostream>
-
// This class is basically boost::shared_pointer but predates that by
// several years.
@@ -45,43 +43,42 @@ class PointerHolder
class Data
{
public:
- Data(T* pointer, bool tracing) :
+ Data(T* pointer, bool array) :
pointer(pointer),
- tracing(tracing),
+ array(array),
refcount(0)
{
- static int next_id = 0;
- this->unique_id = ++next_id;
}
~Data()
{
- if (this->tracing)
+ if (array)
{
- std::cerr << "PointerHolder deleting pointer "
- << (void*)pointer
- << std::endl;
+ delete [] this->pointer;
}
- delete this->pointer;
- if (this->tracing)
+ else
{
- std::cerr << "PointerHolder done deleting pointer "
- << (void*)pointer
- << std::endl;
+ delete this->pointer;
}
}
T* pointer;
- bool tracing;
+ bool array;
int refcount;
- int unique_id;
private:
Data(Data const&);
Data& operator=(Data const&);
};
public:
+ // "tracing" is not used but is kept for interface backward compatbility
PointerHolder(T* pointer = 0, bool tracing = false)
{
- this->init(new Data(pointer, tracing));
+ this->init(new Data(pointer, false));
+ }
+ // Special constructor indicating to free memory with delete []
+ // instead of delete
+ PointerHolder(bool, T* pointer)
+ {
+ this->init(new Data(pointer, true));
}
PointerHolder(PointerHolder const& rhs)
{
@@ -148,12 +145,6 @@ class PointerHolder
this->data = data;
{
++this->data->refcount;
- if (this->data->tracing)
- {
- std::cerr << "PointerHolder " << this->data->unique_id
- << " refcount increased to " << this->data->refcount
- << std::endl;
- }
}
}
void copy(PointerHolder const& rhs)
@@ -168,13 +159,6 @@ class PointerHolder
{
gone = true;
}
- if (this->data->tracing)
- {
- std::cerr << "PointerHolder " << this->data->unique_id
- << " refcount decreased to "
- << this->data->refcount
- << std::endl;
- }
}
if (gone)
{
diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h
index 98a6f07b..168da154 100644
--- a/include/qpdf/qpdf-c.h
+++ b/include/qpdf/qpdf-c.h
@@ -285,6 +285,25 @@ extern "C" {
QPDF_DLL
QPDF_ERROR_CODE qpdf_init_write(qpdf_data qpdf, char const* filename);
+ /* Initialize for writing but indicate that the PDF file should be
+ * written to memory. Call qpdf_get_buffer_length and
+ * qpdf_get_buffer to retrieve the resulting buffer. The memory
+ * containing the PDF file will be destroyed when qpdf_cleanup is
+ * called.
+ */
+ QPDF_DLL
+ QPDF_ERROR_CODE qpdf_init_write_memory(qpdf_data qpdf);
+
+ /* Retrieve the buffer used if the file was written to memory.
+ * qpdf_get_buffer returns a null pointer if data was not written
+ * to memory. The memory is freed when qpdf_cleanup is called or
+ * if a subsequent call to qpdf_init_write or
+ * qpdf_init_write_memory is called. */
+ QPDF_DLL
+ unsigned long qpdf_get_buffer_length(qpdf_data qpdf);
+ QPDF_DLL
+ unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
+
QPDF_DLL
void qpdf_set_object_stream_mode(qpdf_data qpdf,
enum qpdf_object_stream_e mode);