[poppler] Branch 'better_object' - 2 commits - glib/poppler-action.cc glib/poppler-attachment.cc glib/poppler-media.cc poppler/Annot.cc poppler/FileSpec.h poppler/Rendition.cc poppler/Rendition.h poppler/Stream.cc poppler/Stream.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Fri May 12 21:04:03 UTC 2017
glib/poppler-action.cc | 2 -
glib/poppler-attachment.cc | 15 +++---------
glib/poppler-media.cc | 19 ++++++----------
poppler/Annot.cc | 5 ----
poppler/FileSpec.h | 1
poppler/Rendition.cc | 53 ++++++++++++++++++++++-----------------------
poppler/Rendition.h | 6 +++--
poppler/Stream.cc | 1
poppler/Stream.h | 18 +++++----------
9 files changed, 51 insertions(+), 69 deletions(-)
New commits:
commit b1f4e35fa2da8909dee07529ce1dd9445639793b
Author: Albert Astals Cid <aacid at kde.org>
Date: Fri May 12 23:03:28 2017 +0200
Make Stream incRef/decRef private
Object handles it for us
Also remove incRef/decRef from OutStream
diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index e74d822d..ad8ed18d 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -476,7 +476,7 @@ find_annot_movie_for_action (PopplerDocument *document,
if (annotObj.isDict ()) {
Object tmp;
- annot = new AnnotMovie (document->doc, annotObj.getDict(), &tmp);
+ annot = new AnnotMovie (document->doc, &annotObj, &tmp);
if (!annot->isOk ()) {
delete annot;
annot = NULL;
diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc
index 55936e78..5d84595a 100644
--- a/glib/poppler-attachment.cc
+++ b/glib/poppler-attachment.cc
@@ -35,7 +35,7 @@
typedef struct _PopplerAttachmentPrivate PopplerAttachmentPrivate;
struct _PopplerAttachmentPrivate
{
- Object *obj_stream;
+ Object obj_stream;
};
#define POPPLER_ATTACHMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), POPPLER_TYPE_ATTACHMENT, PopplerAttachmentPrivate))
@@ -64,12 +64,7 @@ poppler_attachment_dispose (GObject *obj)
PopplerAttachmentPrivate *priv;
priv = POPPLER_ATTACHMENT_GET_PRIVATE (obj);
-
- if (priv->obj_stream)
- {
- delete priv->obj_stream;
- priv->obj_stream = NULL;
- }
+ priv->obj_stream = Object();
G_OBJECT_CLASS (poppler_attachment_parent_class)->dispose (obj);
}
@@ -126,9 +121,7 @@ _poppler_attachment_new (FileSpec *emb_file)
if (embFile->checksum () && embFile->checksum ()->getLength () > 0)
attachment->checksum = g_string_new_len (embFile->checksum ()->getCString (),
embFile->checksum ()->getLength ());
- priv->obj_stream = new Object(embFile->stream());
- // Copy the stream
- embFile->stream()->incRef();
+ priv->obj_stream = embFile->streamObject()->copy();
return attachment;
}
@@ -241,7 +234,7 @@ poppler_attachment_save_to_callback (PopplerAttachment *attachment,
g_return_val_if_fail (POPPLER_IS_ATTACHMENT (attachment), FALSE);
- stream = POPPLER_ATTACHMENT_GET_PRIVATE (attachment)->obj_stream->getStream();
+ stream = POPPLER_ATTACHMENT_GET_PRIVATE (attachment)->obj_stream.getStream();
stream->reset();
do
diff --git a/glib/poppler-media.cc b/glib/poppler-media.cc
index 57123719..8634af43 100644
--- a/glib/poppler-media.cc
+++ b/glib/poppler-media.cc
@@ -40,7 +40,7 @@ struct _PopplerMedia
gchar *filename;
gchar *mime_type;
- Stream *stream;
+ Object stream;
};
struct _PopplerMediaClass
@@ -65,10 +65,7 @@ poppler_media_finalize (GObject *object)
media->mime_type = NULL;
}
- if (media->stream) {
- media->stream->decRef();
- media->stream = NULL;
- }
+ media->stream = Object();
G_OBJECT_CLASS (poppler_media_parent_class)->finalize (object);
}
@@ -98,7 +95,7 @@ _poppler_media_new (MediaRendition *poppler_media)
if (poppler_media->getIsEmbedded()) {
GooString* mime_type;
- media->stream = poppler_media->getEmbbededStream();
+ media->stream = poppler_media->getEmbbededStreamObject()->copy();
mime_type = poppler_media->getContentType();
if (mime_type)
media->mime_type = g_strdup (mime_type->getCString());
@@ -124,7 +121,7 @@ const gchar *
poppler_media_get_filename (PopplerMedia *poppler_media)
{
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), NULL);
- g_return_val_if_fail (poppler_media->stream == NULL, NULL);
+ g_return_val_if_fail (!poppler_media->stream.isStream(), NULL);
return poppler_media->filename;
}
@@ -147,7 +144,7 @@ poppler_media_is_embedded (PopplerMedia *poppler_media)
{
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
- return poppler_media->stream != NULL;
+ return poppler_media->stream.isStream();
}
/**
@@ -215,7 +212,7 @@ poppler_media_save (PopplerMedia *poppler_media,
FILE *f;
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
- g_return_val_if_fail (poppler_media->stream != NULL, FALSE);
+ g_return_val_if_fail (poppler_media->stream.isStream(), FALSE);
f = g_fopen (filename, "wb");
@@ -281,9 +278,9 @@ poppler_media_save_to_callback (PopplerMedia *poppler_media,
gboolean eof_reached = FALSE;
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
- g_return_val_if_fail (poppler_media->stream != NULL, FALSE);
+ g_return_val_if_fail (poppler_media->stream.isStream(), FALSE);
- stream = poppler_media->stream;
+ stream = poppler_media->stream.getStream();
stream->reset();
do
diff --git a/poppler/FileSpec.h b/poppler/FileSpec.h
index 8cdd73c1..6133117b 100644
--- a/poppler/FileSpec.h
+++ b/poppler/FileSpec.h
@@ -32,6 +32,7 @@ public:
GooString *createDate() { return m_createDate; }
GooString *checksum() { return m_checksum; }
GooString *mimeType() { return m_mimetype; }
+ Object *streamObject() { return &m_objStr; }
Stream *stream() { return isOk() ? m_objStr.getStream() : NULL; }
GBool isOk() { return m_objStr.isStream(); }
GBool save(const char *path);
diff --git a/poppler/Rendition.cc b/poppler/Rendition.cc
index 4e7727e8..89bf1a50 100644
--- a/poppler/Rendition.cc
+++ b/poppler/Rendition.cc
@@ -246,14 +246,8 @@ void MediaParameters::parseMediaScreenParameters(Object* obj) {
}
MediaRendition::~MediaRendition() {
- if (fileName)
- delete fileName;
- if (contentType)
- delete contentType;
-
- if (embeddedStream && (!embeddedStream->decRef())) {
- delete embeddedStream;
- }
+ delete fileName;
+ delete contentType;
}
MediaRendition::MediaRendition(Object* obj) {
@@ -263,7 +257,6 @@ MediaRendition::MediaRendition(Object* obj) {
fileName = NULL;
contentType = NULL;
isEmbedded = gFalse;
- embeddedStream = NULL;
//
// Parse media clip data
@@ -285,9 +278,7 @@ MediaRendition::MediaRendition(Object* obj) {
Object embedded = obj2.dictLookup("F");
if (embedded.isStream()) {
isEmbedded = gTrue;
- embeddedStream = embedded.getStream();
- // "copy" stream
- embeddedStream->incRef();
+ embeddedStreamObject = embedded.copy();
}
}
@@ -346,14 +337,32 @@ MediaRendition::MediaRendition(Object* obj) {
}
}
+MediaRendition::MediaRendition(const MediaRendition &other) {
+ ok = other.ok;
+ MH = other.MH;
+ BE = other.BE;
+ isEmbedded = other.isEmbedded;
+ embeddedStreamObject = other.embeddedStreamObject.copy();
+
+ if (other.contentType)
+ contentType = other.contentType->copy();
+ else
+ contentType = nullptr;
+
+ if (other.fileName)
+ fileName = other.fileName->copy();
+ else
+ fileName = nullptr;
+}
+
void MediaRendition::outputToFile(FILE* fp) {
if (!isEmbedded)
return;
- embeddedStream->reset();
+ embeddedStreamObject.streamReset();
while (1) {
- int c = embeddedStream->getChar();
+ int c = embeddedStreamObject.streamGetChar();
if (c == EOF)
break;
@@ -362,19 +371,9 @@ void MediaRendition::outputToFile(FILE* fp) {
}
-MediaRendition *MediaRendition::copy() {
- // call default copy constructor
- MediaRendition* new_media = new MediaRendition(*this);
-
- if (contentType)
- new_media->contentType = contentType->copy();
- if (fileName)
- new_media->fileName = fileName->copy();
-
- if (new_media->embeddedStream)
- new_media->embeddedStream->incRef();
-
- return new_media;
+MediaRendition* MediaRendition::copy()
+{
+ return new MediaRendition(*this);
}
// TODO: SelectorRendition
diff --git a/poppler/Rendition.h b/poppler/Rendition.h
index 75bfeff3..3b26cea7 100644
--- a/poppler/Rendition.h
+++ b/poppler/Rendition.h
@@ -118,6 +118,7 @@ struct MediaParameters {
class MediaRendition {
public:
MediaRendition(Object *obj);
+ MediaRendition(const MediaRendition &other);
~MediaRendition();
GBool isOk () { return ok; }
@@ -129,7 +130,8 @@ class MediaRendition {
GooString* getFileName() { return fileName; }
GBool getIsEmbedded() { return isEmbedded; }
- Stream* getEmbbededStream() { return embeddedStream; }
+ Stream* getEmbbededStream() { return isEmbedded ? embeddedStreamObject.getStream() : nullptr; }
+ Object* getEmbbededStreamObject() { return isEmbedded ? &embeddedStreamObject : nullptr; }
// write embedded stream to file
void outputToFile(FILE*);
@@ -148,7 +150,7 @@ class MediaRendition {
GooString* contentType;
// if it's embedded
- Stream* embeddedStream;
+ Object embeddedStreamObject;
// if it's not embedded
GooString* fileName;
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 7b87912b..03d15de3 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -343,7 +343,6 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursio
//------------------------------------------------------------------------
OutStream::OutStream ()
{
- ref = 1;
}
OutStream::~OutStream ()
diff --git a/poppler/Stream.h b/poppler/Stream.h
index 12f23dd6..9c53ea39 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -105,10 +105,6 @@ public:
// Destructor.
virtual ~Stream();
- // Reference counting.
- int incRef();
- int decRef();
-
// Get kind of stream.
virtual StreamKind getKind() = 0;
@@ -230,6 +226,12 @@ public:
Stream *addFilters(Dict *dict, int recursion = 0);
private:
+ friend class Object; // for incRef/decRef
+
+ // Reference counting.
+ int incRef();
+ int decRef();
+
virtual GBool hasGetChars() { return false; }
virtual int getChars(int nChars, Guchar *buffer);
@@ -255,10 +257,6 @@ public:
// Desctructor.
virtual ~OutStream ();
- // Reference counting.
- int incRef() { return ++ref; }
- int decRef() { return --ref; }
-
// Close the stream
virtual void close() = 0;
@@ -269,10 +267,6 @@ public:
virtual void put (char c) = 0;
virtual void printf (const char *format, ...) GCC_PRINTF_FORMAT(2,3) = 0;
-
-private:
- int ref; // reference count
-
};
//------------------------------------------------------------------------
commit d34e5304a9094d505ffce8ec4069d4ddf2ee5950
Author: Albert Astals Cid <aacid at kde.org>
Date: Fri May 12 22:41:03 2017 +0200
Get rid of another incRef() call
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5d52b51a..7e1941c3 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -6157,10 +6157,7 @@ AnnotSound::AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA) :
type = typeSound;
annotObj.dictSet ("Subtype", Object(objName, "Sound"));
-
- Stream *str = soundA->getStream();
- str->incRef();
- annotObj.dictSet ("Sound", Object(str));
+ annotObj.dictSet ("Sound", soundA->getObject()->copy());
initialize(docA, annotObj.getDict());
}
More information about the poppler
mailing list