GNOME Bugzilla – Bug 686909
Pass 0 (NULL) instead of "" to C functions
Last modified: 2013-09-09 19:57:52 UTC
Created attachment 227322 [details] [review] 0001-gmmproc-Pass-0-NULL-instead-of-to-C-functions.patch I'm not sure whether this is particularly useful yet, and it's probably risky, but I'm storing the patch here in the meantime.
Created attachment 227358 [details] [review] 0001-Pass-0-NULL-instead-of-for-C-properties.patch And this one does the same for properties. It seems to be OK when using it with Glom and avoids one warning in GTK+ caused by a "" stock_id. Maybe we should push it soon for testing in unstable releases.
To me it's logical to pass NULL from C++ to C when dealing with an empty ("") string because there's really nothing in it. I don't see much risk in dealing with strings that way (though I should really look a little more into what that implies). I don't really oppose pushing the patches for testing. Maybe they will reaveal what possible problems there might be in dealing with strings this way.
I plan to commit this to master soon.
Pushed to master.
Unfortunately, it looks like some GTK+ API rejects NULL instead of accepting it as an equivalent of "". For instance gtk_entry_set_text() and gtk_entry_buffer_set_text(). Maybe we need some gmmproc syntax to mark when "" should _not_ be converted to NULL.
gtk_font_button_set_font_name() is another one.
Maybe, we can just make sure that all string parameters that may be NUll (in the C API) have the {?} syntax in _WRAP_METHOD(). That usually just means that we should add a method overload without that parameter. But maybe it could also mean that we pass NULL for "" in the main method overload. Eventually, we would get that {?} from the introspection data, but we are quite far from using that in gmmproc.
Created attachment 254124 [details] [review] gmmproc: Pass NULL to C function calls for optional empty strings. I don't have that much time because of a project that I'm working on, but I think this patch would do just what you suggest. When converting C++ arguments to be passed to C function calls, if the argument is optional and it is a std::string or a Glib::ustring, it prepends a check for the empty string to the conversion passing NULL to the C function if the string is empty. The commit that changes the string conversions would have to be reverted.
My problem is that I've been working opensource for quite a while. I started with a project and expected to develop it enough to earn income from it. But because I wanted to use GStreamer with it and wanted to program in C++, I put it aside and began working on gstreamermm. I wasn't tight on money so that was no problem. But now I am tight so I *have to* work on things that will provide me income. I've found some work so I have to sadly inform that I will not be working on these projects to dedicate my time to the newly found work. I'll probably be unsubscribing from receiving e-mails, etc. so I wont be distracted. I'm sorry.
Review of attachment 254124 [details] [review]: Thanks. I've pushed that, after reverting my other commits.