How to use Glib::Value?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use Glib::Value?

Gtkmm mailing list
Hi,

Have this code
```
Glib::Value<int> datai;
datai.init(G_TYPE_INT);
datai.set(8);
std::cout << "Value = " << datai.get() << std::endl;
```
I see in stdout:
Value = 8

Works good. Now I would like to use another type: Glib::DateTime
```
Glib::Value<Glib::DateTime> data;

data.init(G_TYPE_DATE_TIME);
Glib::DateTime ctime = Glib::DateTime::create_now_utc();
data.set(ctime);
```

This compiles ok, but generates
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src=...) at
/home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
89  if(gobject_)

Part from dbg:
```
26  Glib::Value<Glib::DateTime> data;
(gdb)
28  data.init(G_TYPE_DATE_TIME);
(gdb) p data
$1 = {<Glib::ValueBase_Boxed> = {<Glib::ValueBase> = {gobject_ =
{g_type = 0, data = {{v_int = 0, v_uint = 0, v_long = 0, v_ulong = 0,
v_int64 = 0,
            v_uint64 = 0, v_float = 0, v_double = 0, v_pointer = 0x0},
{v_int = 0, v_uint = 0, v_long = 0, v_ulong = 0, v_int64 = 0, v_uint64
= 0,
            v_float = 0, v_double = 0, v_pointer = 0x0}}}}, <No data
fields>}, static custom_type_ = <optimized out>}
(gdb) n
29  Glib::DateTime ctime = Glib::DateTime::create_now_utc();
(gdb) p data
$2 = {<Glib::ValueBase_Boxed> = {<Glib::ValueBase> = {gobject_ =
{g_type = 93824992400576, data = {{v_int = 0, v_uint = 0, v_long = 0,
v_ulong = 0,
            v_int64 = 0, v_uint64 = 0, v_float = 0, v_double = 0,
v_pointer = 0x0}, {v_int = 0, v_uint = 0, v_long = 0, v_ulong = 0,
v_int64 = 0,
            v_uint64 = 0, v_float = 0, v_double = 0, v_pointer =
0x0}}}}, <No data fields>}, static custom_type_ = <optimized out>}
(gdb) n
30  data.set(ctime);
(gdb) p data
$3 = {<Glib::ValueBase_Boxed> = {<Glib::ValueBase> = {gobject_ =
{g_type = 93824992400576, data = {{v_int = 0, v_uint = 0, v_long = 0,
v_ulong = 0,
            v_int64 = 0, v_uint64 = 0, v_float = 0, v_double = 0,
v_pointer = 0x0}, {v_int = 0, v_uint = 0, v_long = 0, v_ulong = 0,
v_int64 = 0,
            v_uint64 = 0, v_float = 0, v_double = 0, v_pointer =
0x0}}}}, <No data fields>}, static custom_type_ = <optimized out>}
(gdb) p ctime
$4 = {gobject_ = 0x55555557c4a0}
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src=...) at
/home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
89  if(gobject_)
(gdb)
```

Could you please help me to understand how to use Glib::Value<T> with
types such as Glib::DateTime?

Thanks.


--
- Pavlo Solntsev
---------------------------------------------
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

Sent from Evolution on GNU/Debian <www.debian.org>


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list

Replace
   data.init(G_TYPE_DATE_TIME);
by
   data.init(data.value_type());
or

   data.init(Glib::Value<Glib::DateTime>::value_type());

You don't store a GDateTime, you store a Glib::DateTime. That's not the same thing.

This is not well described in the documentation, but there is an example at
https://gitlab.gnome.org/GNOME/glibmm/blob/master/tests/glibmm_value/main.cc

On 2019-03-04 14:05, Pavlo Solntsev via gtkmm-list wrote:
Hi,

Have this code 
```
Glib::Value<int> datai;
datai.init(G_TYPE_INT);
datai.set(8);
std::cout << "Value = " << datai.get() << std::endl;
```
I see in stdout:
Value = 8

Works good. Now I would like to use another type: Glib::DateTime
```
Glib::Value<Glib::DateTime> data;

data.init(G_TYPE_DATE_TIME);
Glib::DateTime ctime = Glib::DateTime::create_now_utc();
data.set(ctime);
```

This compiles ok, but generates 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src=...) at
/home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
89	  if(gobject_)


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list
Thanks, that works. Out of curiosity, why not to call init() in the
constructor?


On Tue, 2019-03-05 at 11:00 +0100, Kjell Ahlstedt wrote:

> Replace
>    data.init(G_TYPE_DATE_TIME);
> by
>    data.init(data.value_type());
> or
>    data.init(Glib::Value<Glib::DateTime>::value_type());
> You don't store a GDateTime, you store a Glib::DateTime. That's not
> the same thing.
> This is not well described in the documentation, but there is an
> example at
> https://gitlab.gnome.org/GNOME/glibmm/blob/master/tests/glibmm_value/main.cc
> On 2019-03-04 14:05, Pavlo Solntsev via gtkmm-list wrote:
> > Hi,
> >
> > Have this code
> > ```
> > Glib::Value<int> datai;
> > datai.init(G_TYPE_INT);
> > datai.set(8);
> > std::cout << "Value = " << datai.get() << std::endl;
> > ```
> > I see in stdout:
> > Value = 8
> >
> > Works good. Now I would like to use another type: Glib::DateTime
> > ```
> > Glib::Value<Glib::DateTime> data;
> >
> > data.init(G_TYPE_DATE_TIME);
> > Glib::DateTime ctime = Glib::DateTime::create_now_utc();
> > data.set(ctime);
> > ```
> >
> > This compiles ok, but generates
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src=...)
> > at
> > /home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
> > 89  if(gobject_)
> >

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list

init() is a method in Glib::ValueBase, base class of all Glib::Value<> specializations. The documentation says
    init() is not implemented as constructor, to avoid the necessity
    to implement a forward constructor in each derived class.
There are many subclasses of Glib::ValueBase. Most of these subclasses (perhaps even all of them) has just compiler-generated constructors. I suppose someone found it tedious to write constructors with a call to init() in all those subclasses. It's not obvious to me that it was a wise decision not to do that.

On 2019-03-05 14:37, Pavlo Solntsev via gtkmm-list wrote:
Thanks, that works. Out of curiosity, why not to call init() in the
constructor? 


On Tue, 2019-03-05 at 11:00 +0100, Kjell Ahlstedt wrote:
Replace
   data.init(G_TYPE_DATE_TIME);
by
   data.init(data.value_type());
or
   data.init(Glib::Value<Glib::DateTime>::value_type());
You don't store a GDateTime, you store a Glib::DateTime. That's not
the same thing.
This is not well described in the documentation, but there is an
example at
https://gitlab.gnome.org/GNOME/glibmm/blob/master/tests/glibmm_value/main.cc
On 2019-03-04 14:05, Pavlo Solntsev via gtkmm-list wrote:
Hi,

Have this code 
```
Glib::Value<int> datai;
datai.init(G_TYPE_INT);
datai.set(8);
std::cout << "Value = " << datai.get() << std::endl;
```
I see in stdout:
Value = 8

Works good. Now I would like to use another type: Glib::DateTime
```
Glib::Value<Glib::DateTime> data;

data.init(G_TYPE_DATE_TIME);
Glib::DateTime ctime = Glib::DateTime::create_now_utc();
data.set(ctime);
```

This compiles ok, but generates 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src=...)
at
_______________________________________________ gtkmm-list mailing list [hidden email] https://mail.gnome.org/mailman/listinfo/gtkmm-list
/home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
89	  if(gobject_)



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list
Thank you for clarification.

This is what I did for my code.

template<class T>
class Column {
        Glib::Value<T> data

public:
        Column(){
                data.init(data.get_value_type());
        }
        Column(const T &val):Column(){
                data.set(val);
        }

        void set_value(const T &val){
                data.set(val);
        }

        T get_value(void){
                return data.get();
        }

};

Usage is very convenient:
Column<Glib::ustring> mColumn;

mColumn.get(); // get value
mColumn.set("New string"); // Set value

This is just a general idea and some parts are missed. Do you think the
similar code can be incorporated to Glib::Value? For example. If we
rename the current class Glib::Value to Glib::Value_t and remove from
the public API, we can define a new class Glib::Value which will
include Glib::Value_t in the way I showed above. This will remove extra
step such as call Glib::Value<T>::init(...) method.

Just a suggestion. I can prepare MR if the idea is valuable.

Thanks.



On Tue, 2019-03-05 at 19:28 +0100, Kjell Ahlstedt wrote:

> init() is a method in Glib::ValueBase, base class of all
> Glib::Value<> specializations. The documentation says
>     init() is not implemented as constructor, to avoid the necessity
>     to implement a forward constructor in each derived class.
> There are many subclasses of Glib::ValueBase. Most of these
> subclasses (perhaps even all of them) has just compiler-generated
> constructors. I suppose someone found it tedious to write
> constructors with a call to init() in all those subclasses. It's not
> obvious to me that it was a wise decision not to do that.
> On 2019-03-05 14:37, Pavlo Solntsev via gtkmm-list wrote:
> > Thanks, that works. Out of curiosity, why not to call init() in the
> > constructor?
> >
> >
> > On Tue, 2019-03-05 at 11:00 +0100, Kjell Ahlstedt wrote:
> > > Replace
> > >    data.init(G_TYPE_DATE_TIME);
> > > by
> > >    data.init(data.value_type());
> > > or
> > >    data.init(Glib::Value<Glib::DateTime>::value_type());
> > > You don't store a GDateTime, you store a Glib::DateTime. That's
> > > not
> > > the same thing.
> > > This is not well described in the documentation, but there is an
> > > example at
> > > https://gitlab.gnome.org/GNOME/glibmm/blob/master/tests/glibmm_value/main.cc
> > > On 2019-03-04 14:05, Pavlo Solntsev via gtkmm-list wrote:
> > > > Hi,
> > > >
> > > > Have this code
> > > > ```
> > > > Glib::Value<int> datai;
> > > > datai.init(G_TYPE_INT);
> > > > datai.set(8);
> > > > std::cout << "Value = " << datai.get() << std::endl;
> > > > ```
> > > > I see in stdout:
> > > > Value = 8
> > > >
> > > > Works good. Now I would like to use another type:
> > > > Glib::DateTime
> > > > ```
> > > > Glib::Value<Glib::DateTime> data;
> > > >
> > > > data.init(G_TYPE_DATE_TIME);
> > > > Glib::DateTime ctime = Glib::DateTime::create_now_utc();
> > > > data.set(ctime);
> > > > ```
> > > >
> > > > This compiles ok, but generates
> > > > Program received signal SIGSEGV, Segmentation fault.
> > > > 0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0,
> > > > src=...)
> > > > at
> > > > _______________________________________________ gtkmm-list
> > > > mailing list [hidden email]
> > > > https://mail.gnome.org/mailman/listinfo/gtkmm-list
> > > > /home/pavlo/jhbuild/checkout/glibmm-
> > > > 2.4/glib/glibmm/datetime.cc:89
> > > > 89  if(gobject_)
> > > >
> >  

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list
Right now we're maintaining two parallel-installable versions of glibmm,
the stable glibmm-2.4 ABI series with the latest release glibmm 2.58.0
(git branch glibmm-2-58), and the new and very unstable glibmm-2.60 ABI
with the latest release 2.59.1 (git branch master).

In the master branch we can change both API and ABI until the first
stable release of gtk-4 and gtkmm-4.
In the glibmm-2-58 branch the usual restrictions apply: No API or ABI
must be changed or removed. New API and ABI can be added only when (if)
we release a glibmm 2.60.x version in the glibmm-2.4 ABI series.

Yes, I know these API and ABI version numbers are confusing. It's just
the way it is right now in glibmm.
It means that in the master branch you can suggest just about anything
you like. In the glibmm-2-58 branch we can't do very much, basically fix
obvious bugs and improve documentation. If there will be a glibmm-2-60
branch, branched from glibmm-2-58, API and ABI can be added there, but
not changed or removed.

You're welcome to write one or two MRs if you like. An MR for the master
branch is probably the easiest one. In the master branch there is no
requirement that all code that uses glibmm must continue to work without
modification and without recompilation.

I don't understand the point of renaming the present Glib::Value classes
to Glib::Value_t and then write new Glib::Value classes that use
Glib::Value_t. In the master branch Glib::Value_t seems unnecessary. All
code can be put in modified Glib::Value classes. In glibmm-2-60 it would
not be allowed, if the new Glib::Value classes break ABI or API, which
they probably will.

On 2019-03-08 14:35, Pavlo Solntsev via gtkmm-list wrote:

> Thank you for clarification.
>
> This is what I did for my code.
>
> template<class T>
> class Column {
> Glib::Value<T> data
>
> public:
> Column(){
> data.init(data.get_value_type());
> }
> Column(const T &val):Column(){
> data.set(val);
> }
>
> void set_value(const T &val){
> data.set(val);
> }
>
> T get_value(void){
> return data.get();
> }
>
> };
>
> Usage is very convenient:
> Column<Glib::ustring> mColumn;
>
> mColumn.get(); // get value
> mColumn.set("New string"); // Set value
>
> This is just a general idea and some parts are missed. Do you think the
> similar code can be incorporated to Glib::Value? For example. If we
> rename the current class Glib::Value to Glib::Value_t and remove from
> the public API, we can define a new class Glib::Value which will
> include Glib::Value_t in the way I showed above. This will remove extra
> step such as call Glib::Value<T>::init(...) method.
>
> Just a suggestion. I can prepare MR if the idea is valuable.
>
> Thanks.
>
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: How to use Glib::Value?

Gtkmm mailing list
Thanks for the clarification. I didn't check the implementation of
Glib::Value<T> class when proposed the idea. I checked and I see that
default constructor can be defined and init() call can be done there. I
will try to submit MR to the master and we can discuss further.

On Sat, 2019-03-09 at 13:04 +0100, Kjell Ahlstedt wrote:

> Right now we're maintaining two parallel-installable versions of
> glibmm,
> the stable glibmm-2.4 ABI series with the latest release glibmm
> 2.58.0
> (git branch glibmm-2-58), and the new and very unstable glibmm-2.60
> ABI
> with the latest release 2.59.1 (git branch master).
>
> In the master branch we can change both API and ABI until the first
> stable release of gtk-4 and gtkmm-4.
> In the glibmm-2-58 branch the usual restrictions apply: No API or
> ABI
> must be changed or removed. New API and ABI can be added only when
> (if)
> we release a glibmm 2.60.x version in the glibmm-2.4 ABI series.
>
> Yes, I know these API and ABI version numbers are confusing. It's
> just
> the way it is right now in glibmm.
> It means that in the master branch you can suggest just about
> anything
> you like. In the glibmm-2-58 branch we can't do very much, basically
> fix
> obvious bugs and improve documentation. If there will be a glibmm-2-
> 60
> branch, branched from glibmm-2-58, API and ABI can be added there,
> but
> not changed or removed.
>
> You're welcome to write one or two MRs if you like. An MR for the
> master
> branch is probably the easiest one. In the master branch there is no
> requirement that all code that uses glibmm must continue to work
> without
> modification and without recompilation.
>
> I don't understand the point of renaming the present Glib::Value
> classes
> to Glib::Value_t and then write new Glib::Value classes that use
> Glib::Value_t. In the master branch Glib::Value_t seems unnecessary.
> All
> code can be put in modified Glib::Value classes. In glibmm-2-60 it
> would
> not be allowed, if the new Glib::Value classes break ABI or API,
> which
> they probably will.
>
> On 2019-03-08 14:35, Pavlo Solntsev via gtkmm-list wrote:
> > Thank you for clarification.
> >
> > This is what I did for my code.
> >
> > template<class T>
> > class Column {
> > Glib::Value<T> data
> >
> > public:
> > Column(){
> > data.init(data.get_value_type());
> > }
> > Column(const T &val):Column(){
> > data.set(val);
> > }
> >
> > void set_value(const T &val){
> > data.set(val);
> > }
> >
> > T get_value(void){
> > return data.get();
> > }
> >
> > };
> >
> > Usage is very convenient:
> > Column<Glib::ustring> mColumn;
> >
> > mColumn.get(); // get value
> > mColumn.set("New string"); // Set value
> >
> > This is just a general idea and some parts are missed. Do you think
> > the
> > similar code can be incorporated to Glib::Value? For example. If we
> > rename the current class Glib::Value to Glib::Value_t and remove
> > from
> > the public API, we can define a new class Glib::Value which will
> > include Glib::Value_t in the way I showed above. This will remove
> > extra
> > step such as call Glib::Value<T>::init(...) method.
> >
> > Just a suggestion. I can prepare MR if the idea is valuable.
> >
> > Thanks.
> >

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list