GNOME Bugzilla – Bug 624287
Question about assertion in gtk_source_language_manager_guess_language.
Last modified: 2010-07-16 11:20:49 UTC
In the function mentioned in title there is an assertion: g_return_val_if_fail ((filename == NULL || *filename != 0) && (content_type == NULL || *content_type != 0), NULL); Shouldn't it be rewritten to allow passing empty strings? With current assertion the call below fails: lang = gtk_source_language_manager_guess_language(lm, "test.cpp", ""); The current assertion now stated that if any passed pointer (filename or content_type) is not NULL then it cannot be empty, while it should (in my opinion of course) be tolerable to have nonNULL empty strings - they would be treated like NULL strings. Just asking because in C++ bindings a c_str() is passed to C function - in case of empty Glib::ustring (or std::string) c_str() returns "" instead of NULL. If above assertion is correct, then I'll have to add two overloads for both NULL parameters. Proposed rewrite of assertion could be: g_return_val_if_fail ((filename != NULL && *filename != 0) || (content_type != NULL && *content_type != 0), NULL); Such assertion will fail when: 1. Both parameters are NULL. 2. Both parameters are empty strings (""). 3. One of parameter is empty string ("") and another is NULL. and will pass when at least one parameter is not NULL and not empty.
The response is in bug 624284.