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 686909 - Pass 0 (NULL) instead of "" to C functions
Pass 0 (NULL) instead of "" to C functions
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks: 702456
 
 
Reported: 2012-10-26 04:37 UTC by Murray Cumming
Modified: 2013-09-09 19:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-gmmproc-Pass-0-NULL-instead-of-to-C-functions.patch (2.24 KB, patch)
2012-10-26 04:37 UTC, Murray Cumming
none Details | Review
0001-Pass-0-NULL-instead-of-for-C-properties.patch (3.13 KB, patch)
2012-10-26 13:47 UTC, Murray Cumming
none Details | Review
gmmproc: Pass NULL to C function calls for optional empty strings. (1.64 KB, patch)
2013-09-04 20:22 UTC, José Alburquerque
committed Details | Review

Description Murray Cumming 2012-10-26 04:37:47 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.
Comment 1 Murray Cumming 2012-10-26 13:47:06 UTC
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.
Comment 2 José Alburquerque 2012-10-26 15:34:35 UTC
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.
Comment 3 Murray Cumming 2013-09-02 14:30:07 UTC
I plan to commit this to master soon.
Comment 4 Murray Cumming 2013-09-03 19:41:53 UTC
Pushed to master.
Comment 5 Murray Cumming 2013-09-04 08:14:49 UTC
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.
Comment 6 Murray Cumming 2013-09-04 10:09:25 UTC
gtk_font_button_set_font_name() is another one.
Comment 7 Murray Cumming 2013-09-04 12:15:47 UTC
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.
Comment 8 José Alburquerque 2013-09-04 20:22:41 UTC
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.
Comment 9 José Alburquerque 2013-09-06 16:49:31 UTC
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.
Comment 10 Murray Cumming 2013-09-08 18:05:57 UTC
Review of attachment 254124 [details] [review]:

Thanks. I've pushed that, after reverting my other commits.