<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2014-12-20 19:48 GMT+01:00 Dmitry Kazakov <span dir="ltr"><<a href="mailto:dimula73@gmail.com" target="_blank">dimula73@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">> Hi, Stefano!<br></div></blockquote><div> </div><div>Hello again to you ;).</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>1) Krita is really large, so the interfaces should be unified. E.g. the function should be callable by both owner of the object and not-owner. With raw pointers it won't work as you can see in example I showed.<br></div></div></div></div></div></blockquote><div> </div><div>Well to be fair you can have it since you can access the pointer inside a shared pointer and pass it, it just would need the rule of "don't delete raw pointer by hand"</div><div>And having less functions with a shared pointer as an argument lets you understand which ones do do really need to manage that memory.</div><div>But weak pointers are fine.</div><div><br></div><div>For the other points, well i agree, those are the places where they have to be used :).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div>Probably, this should be fixed in KisWeakSharedPtr. Or we should implement a method KisWeakSharedPtr::toSharedPtr(). I'm open for suggestions :)</div></span></div></div></div></blockquote><div><br></div><div>Well as Cyrille was saying it has to be fixed making a check, but since there's already a copy constructor for weak -> shared, shouldn't we use that and just put the check before referencing (and if the weak pointer is invalid setting the shared pointer to NULL)?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Can you fix it in KisWeakSharedPtr? I guess if we copy an invalid weak shared pointer, the copy should successfully happen, but the resulting pointer should also become invalid.<br><br></div><div>You can also write a unittest like this:<br></div><div><br>KisWeakSharedPtr<int> a;<br><br>{<br>    KisSharedPtr<int> b(new int(1));<br></div><div>    a = b;<br>}<br><br></div><div>QVERIFY(!a.isValid());<br><br>KisWeakSharedPtr<int> c;<br></div><div>c = a;<br>QVERIFY(!c.isValid());<br><br>KisSharedPtr<int> d;<br>d = a;<br>QVERIFY(!d.isValid());<br></div></div></div></div></blockquote><div> </div><div>Sure, later i'll try, it's quite easy.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Just check the interface of QWeakSharedPointer. You cannot use it directly, you always need to convert it into QSharedPointer before any usage. I'm not sure we really need this in Krita or, more precisely, we can rewrite this amount of code to follow new design. But at least the general idea should be used somehow.<br></div></div></div></div></blockquote><div><br></div><div>Got it right then, well... if you acquire an already dead weak pointer and make it a shared pointer you would have to check if it's null (after the fixes above are done), so would be basicly the same as checking isValid(), unless the code is multithreaded, in which acquiring it as a shared pointer is a must, otherwise after having checked its validity may die just after.</div></div><br></div></div>