diff mbox

[02/11] Add support for qfloat

Message ID 1255786571-3528-3-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori Oct. 17, 2009, 1:36 p.m. UTC
qfloat is a qobject wrapper for double precision floating points

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 Makefile  |    3 +-
 qfloat.c  |   76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qfloat.h  |   29 +++++++++++++++++++++++
 qobject.h |    1 +
 4 files changed, 108 insertions(+), 1 deletions(-)
 create mode 100644 qfloat.c
 create mode 100644 qfloat.h

Comments

Luiz Capitulino Oct. 18, 2009, 10:21 p.m. UTC | #1
On Sat, 17 Oct 2009 08:36:02 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> qfloat is a qobject wrapper for double precision floating points
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  Makefile  |    3 +-
>  qfloat.c  |   76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  qfloat.h  |   29 +++++++++++++++++++++++
>  qobject.h |    1 +
>  4 files changed, 108 insertions(+), 1 deletions(-)
>  create mode 100644 qfloat.c
>  create mode 100644 qfloat.h
> 
> diff --git a/Makefile b/Makefile
> index e78a3d0..9294638 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -125,7 +125,8 @@ obj-y += net.o net-queue.o
>  obj-y += qemu-char.o aio.o net-checksum.o savevm.o
>  obj-y += msmouse.o ps2.o
>  obj-y += qdev.o qdev-properties.o
> -obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
> +obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o
> +obj-y += qemu-config.o
>  
>  obj-$(CONFIG_BRLAPI) += baum.o
>  obj-$(CONFIG_WIN32) += tap-win32.o
> diff --git a/qfloat.c b/qfloat.c
> new file mode 100644
> index 0000000..05215f5
> --- /dev/null
> +++ b/qfloat.c
> @@ -0,0 +1,76 @@
> +/*
> + * QFloat Module
> + *
> + * Copyright (C) 2009 Red Hat Inc.
> + *
> + * Authors:
> + *  Luiz Capitulino <lcapitulino@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + *
> + * Copyright IBM, Corp. 2009
> + *
> + * Authors:
> + *  Anthony Liguori   <aliguori@us.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */

 I see you're double licensing it to respect my initial choice, but you
can leave only LGPL for this new code.

 I will send patches changing the ones written by me.
Anthony Liguori Oct. 19, 2009, 2:18 p.m. UTC | #2
Luiz Capitulino wrote:
> On Sat, 17 Oct 2009 08:36:02 -0500
> Anthony Liguori <aliguori@us.ibm.com> wrote:
>
>   
>> qfloat is a qobject wrapper for double precision floating points
>>
>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>> ---
>>  Makefile  |    3 +-
>>  qfloat.c  |   76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  qfloat.h  |   29 +++++++++++++++++++++++
>>  qobject.h |    1 +
>>  4 files changed, 108 insertions(+), 1 deletions(-)
>>  create mode 100644 qfloat.c
>>  create mode 100644 qfloat.h
>>
>> diff --git a/Makefile b/Makefile
>> index e78a3d0..9294638 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -125,7 +125,8 @@ obj-y += net.o net-queue.o
>>  obj-y += qemu-char.o aio.o net-checksum.o savevm.o
>>  obj-y += msmouse.o ps2.o
>>  obj-y += qdev.o qdev-properties.o
>> -obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
>> +obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o
>> +obj-y += qemu-config.o
>>  
>>  obj-$(CONFIG_BRLAPI) += baum.o
>>  obj-$(CONFIG_WIN32) += tap-win32.o
>> diff --git a/qfloat.c b/qfloat.c
>> new file mode 100644
>> index 0000000..05215f5
>> --- /dev/null
>> +++ b/qfloat.c
>> @@ -0,0 +1,76 @@
>> +/*
>> + * QFloat Module
>> + *
>> + * Copyright (C) 2009 Red Hat Inc.
>> + *
>> + * Authors:
>> + *  Luiz Capitulino <lcapitulino@redhat.com>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
>> + * the COPYING file in the top-level directory.
>> + *
>> + * Copyright IBM, Corp. 2009
>> + *
>> + * Authors:
>> + *  Anthony Liguori   <aliguori@us.ibm.com>
>> + *
>> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
>> + * See the COPYING.LIB file in the top-level directory.
>> + *
>> + */
>>     
>
>  I see you're double licensing it to respect my initial choice, but you
> can leave only LGPL for this new code.
>
>  I will send patches changing the ones written by me.
>   
Great, I'm hoping we can make the whole thing LGPL 2.1+ so that we can 
allow libraries like libvirt to use it.

Regards,

Anthony Liguori
Amit Shah Oct. 22, 2009, 8:49 a.m. UTC | #3
On (Mon) Oct 19 2009 [09:18:19], Anthony Liguori wrote:
>>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
>>> + * the COPYING file in the top-level directory.
>>> + *
>>> + * Copyright IBM, Corp. 2009
>>> + *
>>> + * Authors:
>>> + *  Anthony Liguori   <aliguori@us.ibm.com>
>>> + *
>>> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
>>> + * See the COPYING.LIB file in the top-level directory.
>>> + *
>>> + */
>>>     
>>
>>  I see you're double licensing it to respect my initial choice, but you
>> can leave only LGPL for this new code.
>>
>>  I will send patches changing the ones written by me.
>>   
> Great, I'm hoping we can make the whole thing LGPL 2.1+ so that we can  
> allow libraries like libvirt to use it.

Why 'or later'? Let's just stick to a version that we know and accept.
If you end up later liking version 3, you can change the text then.

		Amit
Anthony Liguori Oct. 22, 2009, 2:01 p.m. UTC | #4
Amit Shah wrote:
> On (Mon) Oct 19 2009 [09:18:19], Anthony Liguori wrote:
>   
>>>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
>>>> + * the COPYING file in the top-level directory.
>>>> + *
>>>> + * Copyright IBM, Corp. 2009
>>>> + *
>>>> + * Authors:
>>>> + *  Anthony Liguori   <aliguori@us.ibm.com>
>>>> + *
>>>> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
>>>> + * See the COPYING.LIB file in the top-level directory.
>>>> + *
>>>> + */
>>>>     
>>>>         
>>>  I see you're double licensing it to respect my initial choice, but you
>>> can leave only LGPL for this new code.
>>>
>>>  I will send patches changing the ones written by me.
>>>   
>>>       
>> Great, I'm hoping we can make the whole thing LGPL 2.1+ so that we can  
>> allow libraries like libvirt to use it.
>>     
>
> Why 'or later'? Let's just stick to a version that we know and accept.
> If you end up later liking version 3, you can change the text then.
>   

It really doesn't matter in the context of LGPL so I don't mind if we do 
2.1 only.
Amit Shah Oct. 22, 2009, 2:05 p.m. UTC | #5
On (Thu) Oct 22 2009 [09:01:48], Anthony Liguori wrote:
> Amit Shah wrote:
>> On (Mon) Oct 19 2009 [09:18:19], Anthony Liguori wrote:
>>   
>>>>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
>>>>> + * the COPYING file in the top-level directory.
>>>>> + *
>>>>> + * Copyright IBM, Corp. 2009
>>>>> + *
>>>>> + * Authors:
>>>>> + *  Anthony Liguori   <aliguori@us.ibm.com>
>>>>> + *
>>>>> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
>>>>> + * See the COPYING.LIB file in the top-level directory.
>>>>> + *
>>>>> + */
>>>>>             
>>>>  I see you're double licensing it to respect my initial choice, but you
>>>> can leave only LGPL for this new code.
>>>>
>>>>  I will send patches changing the ones written by me.
>>>>         
>>> Great, I'm hoping we can make the whole thing LGPL 2.1+ so that we 
>>> can  allow libraries like libvirt to use it.
>>>     
>>
>> Why 'or later'? Let's just stick to a version that we know and accept.
>> If you end up later liking version 3, you can change the text then.
>>   
>
> It really doesn't matter in the context of LGPL so I don't mind if we do  
> 2.1 only.

Yeah; better a known evil than an unknown one :-)

		Amit
Jamie Lokier Oct. 23, 2009, 7:25 p.m. UTC | #6
Anthony Liguori wrote:
> It really doesn't matter in the context of LGPL so I don't mind if we do 
> 2.1 only.

Is LGPL 2.1 compatible with LGPL 3 or GPL 3?

It would be a shame if it's compatible enough to use in libvirt but
can't be used in a GPL 3 project.

I think the recent JSON + QObject stuff is nice enough it may be
useful in other projects that have nothing to do with QEMU.

-- Jamie
Daniel P. Berrangé Oct. 23, 2009, 7:36 p.m. UTC | #7
On Fri, Oct 23, 2009 at 08:25:49PM +0100, Jamie Lokier wrote:
> Anthony Liguori wrote:
> > It really doesn't matter in the context of LGPL so I don't mind if we do 
> > 2.1 only.
> 
> Is LGPL 2.1 compatible with LGPL 3 or GPL 3?
> 
> It would be a shame if it's compatible enough to use in libvirt but
> can't be used in a GPL 3 project.

"LGPL 2.1  only" is not suitable for libvirt actually. Our license is 
explicitly using "LGPL v2.1 or later" so that we can be compatible
with apps using (L)GPL3 too. So yeah I'd really recommend using 2.1+
too

Regards,
Daniel
diff mbox

Patch

diff --git a/Makefile b/Makefile
index e78a3d0..9294638 100644
--- a/Makefile
+++ b/Makefile
@@ -125,7 +125,8 @@  obj-y += net.o net-queue.o
 obj-y += qemu-char.o aio.o net-checksum.o savevm.o
 obj-y += msmouse.o ps2.o
 obj-y += qdev.o qdev-properties.o
-obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
+obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o
+obj-y += qemu-config.o
 
 obj-$(CONFIG_BRLAPI) += baum.o
 obj-$(CONFIG_WIN32) += tap-win32.o
diff --git a/qfloat.c b/qfloat.c
new file mode 100644
index 0000000..05215f5
--- /dev/null
+++ b/qfloat.c
@@ -0,0 +1,76 @@ 
+/*
+ * QFloat Module
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ *  Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qfloat.h"
+#include "qobject.h"
+#include "qemu-common.h"
+
+static void qfloat_destroy_obj(QObject *obj);
+
+static const QType qfloat_type = {
+    .code = QTYPE_QFLOAT,
+    .destroy = qfloat_destroy_obj,
+};
+
+/**
+ * qfloat_from_int(): Create a new QFloat from a float
+ *
+ * Return strong reference.
+ */
+QFloat *qfloat_from_double(double value)
+{
+    QFloat *qf;
+
+    qf = qemu_malloc(sizeof(*qf));
+    qf->value = value;
+    QOBJECT_INIT(qf, &qfloat_type);
+
+    return qf;
+}
+
+/**
+ * qfloat_get_double(): Get the stored float
+ */
+double qfloat_get_double(const QFloat *qf)
+{
+    return qf->value;
+}
+
+/**
+ * qobject_to_qfloat(): Convert a QObject into a QFloat
+ */
+QFloat *qobject_to_qfloat(const QObject *obj)
+{
+    if (qobject_type(obj) != QTYPE_QFLOAT)
+        return NULL;
+
+    return container_of(obj, QFloat, base);
+}
+
+/**
+ * qfloat_destroy_obj(): Free all memory allocated by a
+ * QFloat object
+ */
+static void qfloat_destroy_obj(QObject *obj)
+{
+    assert(obj != NULL);
+    qemu_free(qobject_to_qfloat(obj));
+}
diff --git a/qfloat.h b/qfloat.h
new file mode 100644
index 0000000..9d67876
--- /dev/null
+++ b/qfloat.h
@@ -0,0 +1,29 @@ 
+/*
+ * QFloat Module
+ *
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QFLOAT_H
+#define QFLOAT_H
+
+#include <stdint.h>
+#include "qobject.h"
+
+typedef struct QFloat {
+    QObject_HEAD;
+    double value;
+} QFloat;
+
+QFloat *qfloat_from_double(double value);
+double qfloat_get_double(const QFloat *qi);
+QFloat *qobject_to_qfloat(const QObject *obj);
+
+#endif /* QFLOAT_H */
diff --git a/qobject.h b/qobject.h
index 4cc9287..da03a5e 100644
--- a/qobject.h
+++ b/qobject.h
@@ -41,6 +41,7 @@  typedef enum {
     QTYPE_QSTRING,
     QTYPE_QDICT,
     QTYPE_QLIST,
+    QTYPE_QFLOAT,
 } qtype_code;
 
 struct QObject;