See: http://www.geany.org/manual/reference/document_8h.html#aa14a04c6596cd3261b32...
Real-world example when clicking a Messages item: https://github.com/geany/geany/commit/18181c2e9043add8b13c1fc94c66db2ca5b885...
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Regards, Nick
On 28/08/2014 16:21, Nick Treleaven wrote:
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Additional: if there is no chance of another document having been opened since, but there is a chance a document was closed, it should be fine to check doc->is_valid.
Am 29.08.2014 um 12:58 schrieb Nick Treleaven:
On 28/08/2014 16:21, Nick Treleaven wrote:
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Additional: if there is no chance of another document having been opened since, but there is a chance a document was closed, it should be fine to check doc->is_valid.
Do I understand you correct, that it would make sense to recheck every plugin and in most cases replace(update the document-checks there?
Cheers, Frank
On 4 September 2014 08:41, Frank Lanitz frank@frank.uvena.de wrote:
Am 29.08.2014 um 12:58 schrieb Nick Treleaven:
On 28/08/2014 16:21, Nick Treleaven wrote:
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Additional: if there is no chance of another document having been opened since, but there is a chance a document was closed, it should be fine to check doc->is_valid.
Do I understand you correct, that it would make sense to recheck every plugin and in most cases replace(update the document-checks there?
Hi Frank,
Yes, anywhere Geany or a plugin releases control (eg returns from a callback, opens a dialog) and then gets control back (eg another callback, returns from the dialog) there can be any amount of unknown changes to documents in between. They can be closed, new ones opened etc.
This may re-use document memory, so the doc pointer may point to a completely different document.
To ensure that the same *document* continues to be accessed the id should be used and re-converted to a doc pointer each time control is returned.
Cheers Lex
PS Beware of losses of control buried in functions you call :)
Cheers, Frank
Devel mailing list Devel@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/devel
Am 04.09.2014 um 01:00 schrieb Lex Trotman:
On 4 September 2014 08:41, Frank Lanitz frank@frank.uvena.de wrote:
Am 29.08.2014 um 12:58 schrieb Nick Treleaven:
On 28/08/2014 16:21, Nick Treleaven wrote:
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Additional: if there is no chance of another document having been opened since, but there is a chance a document was closed, it should be fine to check doc->is_valid.
Do I understand you correct, that it would make sense to recheck every plugin and in most cases replace(update the document-checks there?
Hi Frank,
Yes, anywhere Geany or a plugin releases control (eg returns from a callback, opens a dialog) and then gets control back (eg another callback, returns from the dialog) there can be any amount of unknown changes to documents in between. They can be closed, new ones opened etc.
This may re-use document memory, so the doc pointer may point to a completely different document.
To ensure that the same *document* continues to be accessed the id should be used and re-converted to a doc pointer each time control is returned.
Got it. Will need to check the plugins. At least in mine I've got a log of ->is_valid calls ...
cheers, Frank