Den 2018-02-23 kl. 15:36, skrev Pavlo Solntsev:
>>> Your concern is justified. The Glib::ustring must be returned by
value. The _MEMBER_GET should be
It is interesting. getter must return by value....
>>> Your _MEMBER_SET macro doesn't seem to fit the generated code that
you show. I would think that
>>> _MEMBER_SET(name, name, const Glib::ustring&, gchar*)
My understanding that the generated type will be const T& if T is
provided to the macros.
dnl Creates accessors for simple types:
void set_$1(const $3`'& value);
void __CPPNAME__::set_$1(const $3`'& value)
gobj()->$2 = _CONVERT($3,$4,`value');
Sorry, I was wrong. _MEMBER_SET(name, name, Glib::ustring, gchar*)
does generate the code you showed.
>> would generate that code. In this case a reference is OK, but it
looks like the generated code can cause a memory leak. Who owns the
duplicated string? Who deallocates it? What if gobj()->name contains a
pointer to a string when set_name() is called?
In Glib::OptionEntry, _MEMBER_SET is not used for strings. Those methods
are hand-coded to avoid a memory leak. Example:
Basically once again, return by value. What would be the correct wrap
for the simple struct? Wrap struct and manually wrap set/get method?
I will investigate how private members are stored and how they related
to the original C struct. Thanks
void OptionEntry::set_long_name(const Glib::ustring& value)
gobject_->long_name = nullptr;
gobj()->long_name = (value).c_str() ? g_strdup((value).c_str()) :
Don't ask me why value.c_str() is tested for nullptr. I don't
understand. I don't think it can ever be a nullptr. And even if it is,
g_strdup() can handle that.
gtkmm-list mailing list