After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 624284 - Improve check in guess_language function.
Improve check in guess_language function.
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
2.11.x
Other Linux
: Normal minor
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-13 21:13 UTC by Krzesimir Nowak
Modified: 2010-07-16 11:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Improves check in guess_language. (848 bytes, patch)
2010-07-13 21:13 UTC, Krzesimir Nowak
needs-work Details | Review
Reworked patch improving a check. (851 bytes, patch)
2010-07-13 21:47 UTC, Krzesimir Nowak
none Details | Review
Updated patch, now with tests. (3.29 KB, patch)
2010-07-15 21:06 UTC, Krzesimir Nowak
committed Details | Review

Description Krzesimir Nowak 2010-07-13 21:13:59 UTC
Created attachment 165833 [details] [review]
Improves check in guess_language.

Now gtksourceview check if filename is not NULL before it tries to guess language from it. It should also check if filename is not empty string (*filename != 0), because it won't deduce anything useful from empty string and will waste time on getting all language ids and so on.

Attached patch add the check for filename as empty string.
Comment 1 Ignacio Casal Quinteiro (nacho) 2010-07-13 21:36:50 UTC
Review of attachment 165833 [details] [review]:

Commented

::: gtksourceview/gtksourcelanguagemanager.c
@@ +639,3 @@
 	*/
 
+	if (filename != NULL && *filename != 0)

Good catch though, I'd prefer *filename != '\0'
Comment 2 Ignacio Casal Quinteiro (nacho) 2010-07-13 21:36:50 UTC
Review of attachment 165833 [details] [review]:

Commented

::: gtksourceview/gtksourcelanguagemanager.c
@@ +639,3 @@
 	*/
 
+	if (filename != NULL && *filename != 0)

Good catch though, I'd prefer *filename != '\0'
Comment 3 Krzesimir Nowak 2010-07-13 21:47:10 UTC
Created attachment 165834 [details] [review]
Reworked patch improving a check.

The version with '\0' was my first one, but I changed it to 0, because I saw such check in assertion above. :)
Comment 4 Krzesimir Nowak 2010-07-14 04:45:26 UTC
Now I have noticed that because of one assertion an addition in my patch is never executed - please see https://bugzilla.gnome.org/show_bug.cgi?id=624287
Comment 5 Ignacio Casal Quinteiro (nacho) 2010-07-14 09:41:48 UTC
I'm now starting to wonder if this is ok. Is it ok having an empty name? I think that the assertion is ok and the new check is not really needed. Paolo any thoughts about this?
Comment 6 Krzesimir Nowak 2010-07-14 10:39:07 UTC
Currently passing empty strings causes assertion fail (as written bug mentioned in comment 4). So the only accepted parameters are non empty strings and NULL strings. I just thought that empty strings should be treated like NULL strings. So, if you pass two empty strings or two NULL strings or one empty string and one NULL string, then this is programming error. But passing an empty and non empty should be ok - if filename is an empty string then it is not taken into consideration (with my patch merged). In that case language is guessed on content_type which, at this point we know, is neither NULL nor empty string.
Comment 7 Ignacio Casal Quinteiro (nacho) 2010-07-14 12:44:59 UTC
After talking in paolo we are ok by allowing empty strings and the check should be definetly '\0' instead of 0. Also can you provide a unit test? You can find the unit test for the guess language in the test directory.
Comment 8 Krzesimir Nowak 2010-07-15 05:27:14 UTC
I'll do it today evening.
Comment 9 Krzesimir Nowak 2010-07-15 21:06:21 UTC
Created attachment 165999 [details] [review]
Updated patch, now with tests.

I'm attaching a patch containing an assertion replacing two old ones, said additional check in `if' statement and additional tests.
Comment 10 Ignacio Casal Quinteiro (nacho) 2010-07-15 21:49:01 UTC
Review of attachment 165999 [details] [review]:

It looks good to me. Paolo can you give it a second review?
Comment 11 Paolo Borelli 2010-07-16 07:03:29 UTC
Review of attachment 165999 [details] [review]:

Yep, looks good
Comment 12 Krzesimir Nowak 2010-07-16 11:21:25 UTC
Ignacio, could you commit this patch for me? I won't have access to my computer this weekend. Thanks.
Comment 13 Ignacio Casal Quinteiro (nacho) 2010-07-16 11:31:41 UTC
Pushed the patch. Thanks a lot.