patch to fix iterators in khomeview (for kde4 version)

View: New views
8 Messages — Rating Filter:   Alert me  

patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from onet.cristian@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

This is a patch for the KDE4 version of kmymoney (from the KDE repository) but
I think that it could also be applied to the KDE3 development version. It fixes
an invalid iterator, a problem that does not seem to manifests itself on qt3.
Not at least the KDE4 version starts and loads my kmymoney file.
By the way what is the status of the sources in the KDE repository? Could I
help porting? If yes is this the right place to send patches? I would really
like kmymoney to be ported on KDE4 and I am willing to help to make it happen.

--
Regards,

Cristian Oneţ

[fix_iterator_in_home_view.patch]

Index: kmymoney2/views/khomeview.cpp
===================================================================
--- kmymoney2/views/khomeview.cpp (revision 989181)
+++ kmymoney2/views/khomeview.cpp (working copy)
@@ -681,7 +681,7 @@
   // get list of all accounts
   file->accountList(accounts);
   for(it = accounts.begin(); it != accounts.end();) {
-    prevIt = it;
+    bool bRemoveAccount = false;
     if(!(*it).isClosed() || showClosedAccounts) {
       switch((*it).accountType()) {
         case MyMoneyAccount::Expense:
@@ -689,7 +689,7 @@
           // never show a category account
           // Note: This might be different in a future version when
           //       the homepage also shows category based information
-          it = accounts.erase(it);
+          bRemoveAccount = true;
           break;
 
         // Asset and Liability accounts are only shown if they
@@ -700,7 +700,7 @@
           // if preferred accounts are requested, then keep in list
           if((*it).value("PreferredAccount") != "Yes"
           || (type & Preferred) == 0) {
-            it = accounts.erase(it);
+            bRemoveAccount = true;
           }
           break;
 
@@ -714,36 +714,37 @@
           switch(type & (Payment | Preferred)) {
             case Payment:
               if((*it).value("PreferredAccount") == "Yes")
-                it = accounts.erase(it);
+                bRemoveAccount = true;
               break;
 
             case Preferred:
               if((*it).value("PreferredAccount") != "Yes")
-                it = accounts.erase(it);
+                bRemoveAccount = true;
               break;
 
             case Payment | Preferred:
               break;
 
             default:
-              it = accounts.erase(it);
+              bRemoveAccount = true;
               break;
           }
           break;
 
         // filter all accounts that are not used on homepage views
         default:
-          it = accounts.erase(it);
+          bRemoveAccount = true;
           break;
       }
 
     } else if((*it).isClosed() || (*it).isInvest()) {
       // don't show if closed or a stock account
-      it = accounts.erase(it);
+      bRemoveAccount = true;
     }
 
-    // if we still point to the same account we keep it in the list and move on ;-)
-    if(prevIt == it) {
+    if (bRemoveAccount)
+      it = accounts.erase(it);
+    else {
       QString key = (*it).name();
       if(!nameIdx.contains(key)) {
         nameIdx[key] = *it;



------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

signature.asc (205 bytes) Download Attachment

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from asoliverez@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Cristian,
the status of the port is that it is ongoing and we need as much help as we can. You are very welcome to join the team.
I'm kind of coordinating the effort, and you can send the patches to me, or you can apply for a KDE svn account and add me as contact reference. There is a lot of work to do, so sending patches may not be the best way to go, and you already have experience developing on KMyMoney.

I will check the patch and apply it or get back to you if it needs any fix.

Regards,
Alvaro

On Mon, Jun 29, 2009 at 7:55 PM, Cristian Oneţ <onet.cristian@...> wrote:
Hi,

This is a patch for the KDE4 version of kmymoney (from the KDE repository) but
I think that it could also be applied to the KDE3 development version. It fixes
an invalid iterator, a problem that does not seem to manifests itself on qt3.
Not at least the KDE4 version starts and loads my kmymoney file.
By the way what is the status of the sources in the KDE repository? Could I
help porting? If yes is this the right place to send patches? I would really
like kmymoney to be ported on KDE4 and I am willing to help to make it happen.

--
Regards,

Cristian Oneţ

------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer



------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from asoliverez@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok. I checked the patch. I had noticed the error but I had not figured out why it was happening. Nice catch!
We will have to check other similar iterators for the same problems. Perhaps that's a problem in the Qt iterator template?

The only comment I have about the patch is that the boolean should be called removeAccount, we don't use Hungarian notation in KMM. The rest is fine.

Thanks!

Regards,
Alvaro

2009/6/29 Alvaro Soliverez <asoliverez@...>
Hello Cristian,
the status of the port is that it is ongoing and we need as much help as we can. You are very welcome to join the team.
I'm kind of coordinating the effort, and you can send the patches to me, or you can apply for a KDE svn account and add me as contact reference. There is a lot of work to do, so sending patches may not be the best way to go, and you already have experience developing on KMyMoney.

I will check the patch and apply it or get back to you if it needs any fix.

Regards,
Alvaro

On Mon, Jun 29, 2009 at 7:55 PM, Cristian Oneţ <onet.cristian@...> wrote:
Hi,

This is a patch for the KDE4 version of kmymoney (from the KDE repository) but
I think that it could also be applied to the KDE3 development version. It fixes
an invalid iterator, a problem that does not seem to manifests itself on qt3.
Not at least the KDE4 version starts and loads my kmymoney file.
By the way what is the status of the sources in the KDE repository? Could I
help porting? If yes is this the right place to send patches? I would really
like kmymoney to be ported on KDE4 and I am willing to help to make it happen.

--
Regards,

Cristian Oneţ

------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer




------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

Re: patch to fix iterators in khomeview (for kde4 version)

by Thomas Baumgart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 30 June 2009 03:33:47 Alvaro Soliverez wrote:

> Ok. I checked the patch. I had noticed the error but I had not figured out
> why it was happening. Nice catch!

Does this also apply for the Qt3 version? I am not sure, why it should fail on
Qt3. Can someone literate explain?

> We will have to check other similar iterators for the same problems.
> Perhaps that's a problem in the Qt iterator template?
>
> The only comment I have about the patch is that the boolean should be
> called removeAccount, we don't use Hungarian notation in KMM. The rest is
> fine.

--

Regards

Thomas Baumgart

GPG-FP: E55E D592 F45F 116B 8429   4F99 9C59 DB40 B75D D3BA
-------------------------------------------------------------
C makes it easy for you to shoot yourself in the foot. C++ makes that
harder, but when you do, it blows away your whole leg.
 -- Bjarne Stroustrup
-------------------------------------------------------------



------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

signature.asc (232 bytes) Download Attachment

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from onet.cristian@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

În data de Marți 30 Iunie 2009 04:27:22 Alvaro Soliverez a scris:
> Hello Cristian,
> the status of the port is that it is ongoing and we need as much help as we
> can. You are very welcome to join the team.
> I'm kind of coordinating the effort, and you can send the patches to me, or
> you can apply for a KDE svn account and add me as contact reference. There
> is a lot of work to do, so sending patches may not be the best way to go,
> and you already have experience developing on KMyMoney.
I applied for a SVN account.

> I will check the patch and apply it or get back to you if it needs any fix.
>
> Regards,
> Alvaro
>
> On Mon, Jun 29, 2009 at 7:55 PM, Cristian Oneţ
<onet.cristian@...>wrote:

> > Hi,
> >
> > This is a patch for the KDE4 version of kmymoney (from the KDE
> > repository) but
> > I think that it could also be applied to the KDE3 development version. It
> > fixes
> > an invalid iterator, a problem that does not seem to manifests itself on
> > qt3.
> > Not at least the KDE4 version starts and loads my kmymoney file.
> > By the way what is the status of the sources in the KDE repository? Could
> > I help porting? If yes is this the right place to send patches? I would
> > really
> > like kmymoney to be ported on KDE4 and I am willing to help to make it
> > happen.
> >
> > --
> > Regards,
> >
> > Cristian Oneţ
> >
> >
> > -------------------------------------------------------------------------
> >-----
> >
> > _______________________________________________
> > KMyMoney2-developer mailing list
> > KMyMoney2-developer@...
> > https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer
--
Regards,

Cristian Oneţ


------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

signature.asc (205 bytes) Download Attachment

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from onet.cristian@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

În data de Marți 30 Iunie 2009 08:09:42 Thomas Baumgart a scris:
> On Tuesday 30 June 2009 03:33:47 Alvaro Soliverez wrote:
> > Ok. I checked the patch. I had noticed the error but I had not figured
> > out why it was happening. Nice catch!
>
> Does this also apply for the Qt3 version? I am not sure, why it should fail
> on Qt3. Can someone literate explain?
Maybe it does not apply to Qt3 because of the implementation of QList::erase
on Qt3. But AFAIK iterators become invalid after changing the content of a
collection, unless specified otherwise. So "prevIt" became invalid after the
erase operation thus it could not be used to compare it to "it" (they become
incompatible).

> > We will have to check other similar iterators for the same problems.
> > Perhaps that's a problem in the Qt iterator template?
I don't think that it's a problem. I think that the collections assertions
were not respected. Maybe we can catch this at if we enable "iterator
debugging" (like in STL on win) on Debug if Qt4 has something like this.

> > The only comment I have about the patch is that the boolean should be
> > called removeAccount, we don't use Hungarian notation in KMM. The rest is
> > fine.
I'll note that

--
Regards,

Cristian Oneţ


------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

signature.asc (205 bytes) Download Attachment

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from onet.cristian@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jun 30, 2009 at 8:09 AM, Thomas Baumgart<thb@...> wrote:
> Does this also apply for the Qt3 version? I am not sure, why it should fail on
> Qt3. Can someone literate explain?
After investigating a bit it seems that on the Qt3 version there is no
problem since QValueList is used and QValueList::erase(it) has the
following behavior (quote from the API doc): "No iterators other than
'it' or other iterators pointing at the same item as 'it' are
invalidated". But on Qt4 version QList is used and "iterators to a
QList can become invalid after any insertion or removal". According to
http://doc.trolltech.com/4.3/containers.html#container-classes we need
QLinked list in Qt4 if we are to keep the code the way it is.

Sorry for the false alarm.

------------------------------------------------------------------------------
_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer

Re: patch to fix iterators in khomeview (for kde4 version)

by Bugzilla from asoliverez@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Tue, Jun 30, 2009 at 3:58 AM, Cristian Oneţ <onet.cristian@...> wrote:
On Tue, Jun 30, 2009 at 8:09 AM, Thomas Baumgart<thb@...> wrote:
> Does this also apply for the Qt3 version? I am not sure, why it should fail on
> Qt3. Can someone literate explain?
After investigating a bit it seems that on the Qt3 version there is no
problem since QValueList is used and QValueList::erase(it) has the
following behavior (quote from the API doc): "No iterators other than
'it' or other iterators pointing at the same item as 'it' are
invalidated". But on Qt4 version QList is used and "iterators to a
QList can become invalid after any insertion or removal". According to
http://doc.trolltech.com/4.3/containers.html#container-classes we need
QLinked list in Qt4 if we are to keep the code the way it is.

Sorry for the false alarm.

Ok, then make the change. It is better to use QList than QLinkedList.
We will have to go through similar cases in the code where we erase using the iterator.

Regards,
Alvaro

------------------------------------------------------------------------------

_______________________________________________
KMyMoney2-developer mailing list
KMyMoney2-developer@...
https://lists.sourceforge.net/lists/listinfo/kmymoney2-developer