Hi all,
I have now implemented my proposed fix, which is
attached to this e-mail. Please review it (I'm
sorry it's untested, I haven't got back to my dev env
yet), test it, (if you are a committer and it tested
OK) please commit it when the doc fix is committed,
I've prepared the patch to apply cleanly (only) then.
Best regards, mabri
----- Original Message -----
From: Matthew Brincke <mabr...@ymail.com>
To: "podofo-users@lists.sourceforge.net" <podofo-users@lists.sourceforge.net>
Sent: Wednesday, 8 June, 2016, 12:34 UTC
Subject: Re: [Podofo-users] BUG: Erase method from PdfOutlineItem sometimes
segfaults
Hi zyx, hi Dominik,
yes, I see you're right with the method name to stay
intuitive, the behaviour proposed by you is better.
Could you please wait with the release until I've
implemented that? I had proposed moving because I
didn't dare suggest another exception to be thrown ...
There are also some other little things I'd like to
still get into the release, and the documentation fix ...
I hope I can get it done today (except of course for
the reported bugs, e.g. in podofoimpose ...).
Best regards, mabri
----- Original Message -----
From: zyx <z...@litepdf.cz>
To: podofo-users@lists.sourceforge.net
Sent: Wednesday, 8 June 2016, 07:01 UTC
Subject: Re: [Podofo-users] BUG: Erase method from PdfOutlineItem sometimes
segfaults
On Wed, 2016-06-08 at 00:01 +0000, Matthew Brincke wrote:
> I intend to fix PdfOutlineItem::InsertChild() in time for the
> impending release, so that it moves an item already present in
> the tree it's to inserted in, instead of adding it twice and
> violating the tree property (which led to the crash on Erase()
> AFAIK). Currently I'm still busy with an assignment for studies,
> sorry.
Hi,
I would not do that. A better approach might be (from my point of view)
to document that the InsertChild() requires a fresh new item to be used
as the child, and it not being assigned in any tree yet, then verify
that in the runtime and throw an exception when any of this
prerequisite is violated.
After that introduce a new method Move(), which will move (or reparent)
some part of the tree to elsewhere in the same tree. There should be
also done some runtime checks to not cause cycles in the tree and so
on.
Eventually a Copy() method to copy a subtree to a different part could
be added too, then the user would call it, instead of the current
InsertChild() and then will be able to erase the previous subtree as
well.
That way, there will be no side-effect of the InsertChild() and the
method name itself will clearly state what it does.
> Could you please wait for me? I'll try to get the fix done
> on 8th June.
I do not expect it being included in the 0.9.4, there exists a
workaround (manual copy of the subtree), if you meant to wait for you
due this. Just my opinion.
Bye,
zyx
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users
Index: src/base/PdfError.h
===================================================================
--- src/base/PdfError.h (revision 1767)
+++ src/base/PdfError.h (working copy)
@@ -119,11 +119,13 @@
ePdfError_NotImplemented, /**< This feature is currently not implemented. */
- ePdfError_DestinationAlreadyPresent,/**< An destination was already present when trying to add an Action */
+ ePdfError_DestinationAlreadyPresent,/**< A destination was already present when trying to add an Action */
ePdfError_ChangeOnImmutable, /**< Changing values on immutable objects is not allowed. */
ePdfError_NotCompiled, /**< This feature was disabled during compile time. */
+ ePdfError_OutlineItemAlreadyPresent,/**< An outline item to be inserted was already in that outlines tree */
+
ePdfError_Unknown = 0xffff /**< Unknown error */
};
Index: src/doc/PdfOutlines.cpp
===================================================================
--- src/doc/PdfOutlines.cpp (revision 1767)
+++ src/doc/PdfOutlines.cpp (working copy)
@@ -121,6 +121,39 @@
void PdfOutlineItem::InsertChild( PdfOutlineItem* pItem )
{
+ PdfOutlineItem* pItemToCheckParent = pItem;
+ PdfOutlineItem* pRoot = NULL;
+ PdfOutlineItem* pRootOfThis = NULL;
+
+ if ( !pItemToCheckParent )
+ return;
+
+ while ( pItemToCheckParent )
+ {
+ while ( pItemToCheckParent->GetParentOutline() )
+ pItemToCheckParent = pItemToCheckParent->GetParentOutline();
+
+ if ( pItemToCheckParent == pItem ) // item can't have a parent
+ {
+ pRoot = pItem; // needed later, "root" can mean "standalone" here
+ break; // for performance in standalone or doc-merge case
+ }
+
+ if ( !pRoot )
+ {
+ pRoot = pItemToCheckParent;
+ pItemToCheckParent = this;
+ }
+ else
+ {
+ pRootOfThis = pItemToCheckParent;
+ pItemToCheckParent = NULL;
+ }
+ }
+
+ if ( pRoot == pRootOfThis ) // latter NULL if check skipped for performance
+ PODOFO_RAISE_ERROR( ePdfError_OutlineItemAlreadyPresent );
+
if( m_pLast )
{
m_pLast->SetNext( pItem );
Index: src/doc/PdfOutlines.h
===================================================================
--- src/doc/PdfOutlines.h (revision 1767)
+++ src/doc/PdfOutlines.h (working copy)
@@ -90,8 +90,12 @@
*/
PdfOutlineItem* CreateNext ( const PdfString & sTitle, const PdfAction & rAction );
- /** Inserts an existing PdfOutlineItem as a child
- * of this outline item.
+ /** Inserts an existing PdfOutlineItem as a child of this outline item.
+ * The former can't be in the same tree as this one, as the tree property
+ * would be broken. If this prerequisite is violated, a PdfError
+ * exception (code ePdfError_OutlineItemAlreadyPresent) is thrown and
+ * nothing is changed.
+ * The item inserted is not copied, i.e. Erase() calls affect the original!
*
* \param pItem an existing outline item
*/
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users