<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 26 October 2013 23:17, Nick Treleaven <span dir="ltr"><<a href="mailto:nick.treleaven@btinternet.com" target="_blank">nick.treleaven@btinternet.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 26/10/2013 00:22, Lex Trotman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 26 October 2013 00:01, Nick Treleaven <<a href="mailto:nick.treleaven@btinternet.com" target="_blank">nick.treleaven@btinternet.com</a><u></u>>wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 24/10/2013 10:24, Lex Trotman wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Okay, but you still agree that doc->is_valid should be removed eventually?<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That's a step forward:)<br>
</blockquote>
<br>
</blockquote>
<br>
Of course I agree.  So its not a terribly big step:)<br>
<br>
</blockquote>
<br></div>
I only skimmed the discussion, but how can we remove that?<br>
<br>
</blockquote>
<br>
Given your experience it would be good if you could read the discussion and<br>
give your perspective on what the previous posters have discussed regarding<br>
handling doc pointers properly.<br>
</blockquote>
<br>
I read the discussion.<br>
<br>
In summary, I think there are 3 issues:<br>
* forgetting to check is_valid when iterating documents<br>
* freeing memory<br>
* code that uses is_valid to check if a document still exists, which is bad practice<br></blockquote><div><br></div><div>Not just bad practice, but wrong, it does not guarantee its the same document.  Its unlikely, but possible, if the holder of the pointer does not correctly handle document close.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I think freeing memory is a non-issue, I think you (Lex) agree with me on that. It's not a memory leak, it may be reused later.<br></blockquote><div><br></div><div>Yes agree, the memory is not technically "lost" and the amount does not grow over time, although its re-use depends on the users usage pattern, which I think was what Thomas was concerned about.  But if you had enough memory to open that many documents with all the scintilla overhead, then keeping the GeanyDocument struct isn't material.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The first point needs to be handled before the last one (assuming each are worth fixing). I think we can:<br></blockquote><div><br></div><div>If Geany or any plugin keeps a pointer (or an index) to a document they have to properly handle document close, even with the current implementation, to ensure that their pointer (or index) points to the same document, and if they handle that properly they won't have an invalid pointer or index.  That requirement is independent of how the document list is implemented, and it should remove all need to use is_valid outside iteration.</div>
<div><br></div><div>Then the issue of forgetting during iteration can be fixed.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
* remove GeanyDocument::index and fix any code that uses it<br>
* review all code indexing documents_array and fix any code retaining an index (I expect that is rarer than code using GeanyDocument::index).<br>
* change documents_array to only contain valid documents, i.e. on close we swap the last valid document pointer with the pointer being removed, and decrement the length by 1.<br>
* use a free list for invalid documents<br>
<br>
The last point is important to ensure no memory corruption bugs are introduced. I think it is harder to find the code that retains document pointers (and there is some), so I recommend we don't free document memory. At least, we would need a better reason to do so IMO than just memory usage, which is insignificant.<br>
</blockquote><div><br></div><div>Yes, the memory is not an issue, but the real problem (not handling close) needs to be fixed wherever it occurs, and changing the implementation won't help.  In fact, as I said in the PS that started this thread, the current implementation at least ensures that the pointer/index will always reference something that is a GeanyDocument object, if the document structs were de-allocated in the normal way the pointer could point to anything.</div>
<div><br></div><div>Although the chances of the wrong document being referenced because of a retained pointer are slim, any fault that can happen, will happen (and at the worst moment according to Murphy).</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Now, once we've done that it's no longer needed to check is_valid when iterating documents. Possibly we could remove is_valid, but I think that is less important to do. Note that if we do all the steps above, we don't need to break the API, only the ABI. I can't guarantee that bugs won't be introduced due to these changes, but it seems fairly reliable.</blockquote>
<div><br></div><div>An API break doesn't matter really if we are going to break the ABI, that requires all plugins to be recompiled anyway.  So that says we should only do this when something forces an ABI break anyway.</div>
<div><br></div><div>Cheers</div><div>Lex</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
Devel mailing list<br>
<a href="mailto:Devel@lists.geany.org" target="_blank">Devel@lists.geany.org</a><br>
<a href="https://lists.geany.org/cgi-bin/mailman/listinfo/devel" target="_blank">https://lists.geany.org/cgi-<u></u>bin/mailman/listinfo/devel</a><br>
</div></div></blockquote></div><br></div></div>