From patchwork Thu Aug 6 13:52:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 30850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 9DF7DB6EDE for ; Thu, 6 Aug 2009 23:57:26 +1000 (EST) Received: from localhost ([127.0.0.1]:37302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZ3T5-00017l-AA for incoming@patchwork.ozlabs.org; Thu, 06 Aug 2009 09:57:19 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MZ3Oc-0008HL-1z for qemu-devel@nongnu.org; Thu, 06 Aug 2009 09:52:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MZ3OX-0008Ba-A0 for qemu-devel@nongnu.org; Thu, 06 Aug 2009 09:52:41 -0400 Received: from [199.232.76.173] (port=42902 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZ3OX-0008BR-2z for qemu-devel@nongnu.org; Thu, 06 Aug 2009 09:52:37 -0400 Received: from mx2.redhat.com ([66.187.237.31]:50410) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MZ3OW-0003so-ID for qemu-devel@nongnu.org; Thu, 06 Aug 2009 09:52:36 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n76DqYaE027979; Thu, 6 Aug 2009 09:52:34 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n76DqXGB020210; Thu, 6 Aug 2009 09:52:33 -0400 Received: from localhost (vpn-10-64.bos.redhat.com [10.16.10.64]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n76DqVF4016999; Thu, 6 Aug 2009 09:52:32 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 6 Aug 2009 10:52:16 -0300 Message-Id: <1249566736-5020-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1249566736-5020-1-git-send-email-lcapitulino@redhat.com> References: <1249566736-5020-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: aliguori@us.ibm.com, filip.navara@gmail.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 3/3] Introduce QNumber data type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Luiz Capitulino --- Makefile | 2 +- qnumber.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qnumber.h | 20 +++++++++++ qobject.h | 1 + 4 files changed, 130 insertions(+), 1 deletions(-) create mode 100644 qnumber.c create mode 100644 qnumber.h diff --git a/Makefile b/Makefile index 9e3faec..c4cbbaf 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ obj-y += buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.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 ssi.o -obj-y += qdict.o qstring.o +obj-y += qdict.o qstring.o qnumber.o obj-$(CONFIG_BRLAPI) += baum.o diff --git a/qnumber.c b/qnumber.c new file mode 100644 index 0000000..cd30150 --- /dev/null +++ b/qnumber.c @@ -0,0 +1,108 @@ +/* + * QNumber data type. + * + * Copyright (C) 2009 Red Hat Inc. + * + * Authors: + * Luiz Capitulino + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ +#include "qobject.h" +#include "qnumber.h" +#include "qemu-common.h" + +static QType qnumber_type; + + +/** + * qnumber_alloc(): Allocate a new QNumber + */ +static QNumber *qnumber_alloc(void) +{ + QNumber *qnum; + + qnum = qemu_mallocz(sizeof(*qnum)); + qnum->base.type = &qnumber_type; + + return qnum; +} + +/** + * qnumber_from_int(): Create a new QNumber from an int + * + * return new QNumber. + */ +QNumber *qnumber_from_int(int value) +{ + QNumber *qnum; + + qnum = qnumber_alloc(); + qnum->number.n_int = value; + + return qnum; +} + +/** + * qnumber_from_int64(): Create a new QNumber from an int64_t + * + * return new QNumber. + */ +QNumber *qnumber_from_int64(int64_t value) +{ + QNumber *qnum; + + qnum = qnumber_alloc(); + qnum->number.n_int64 = value; + + return qnum; +} + +/** + * qnumber_destroy(): Free all memory allocated by a QNumber + * object + */ +void qnumber_destroy(QNumber *qnum) +{ + qemu_free(qnum); +} + +/** + * qnumber_to_int(): Export QNumber to int type + */ +int qnumber_to_int(const QNumber *qnum) +{ + return qnum->number.n_int; +} + +/** + * qnumber_destroy_obj(): Destroy a QNumber object + */ +static void qnumber_destroy_obj(QObject *obj) +{ + QNumber *qnum = container_of(obj, QNumber, base); + qnumber_destroy(qnum); +} + +/** + * qnumber_clone_obj(): Clone a QNumber object + * + * return a copy of the provided QNumber object. + */ +static QObject *qnumber_clone_obj(const QObject *obj) +{ + QNumber *old, *new; + + new = qemu_malloc(sizeof(*new)); + old = container_of(obj, QNumber, base); + memcpy(new, old, sizeof(*new)); + + return &new->base; +} + +static QType qnumber_type = { + .code = QTYPE_QNUMBER, + .clone = qnumber_clone_obj, + .destroy = qnumber_destroy_obj, +}; diff --git a/qnumber.h b/qnumber.h new file mode 100644 index 0000000..918637d --- /dev/null +++ b/qnumber.h @@ -0,0 +1,20 @@ +#ifndef QNUMBER_H +#define QNUMBER_H + +#include "qobject.h" +#include + +typedef struct QNumber { + QObject base; + union { + int n_int; + int64_t n_int64; + } number; +} QNumber; + +QNumber *qnumber_from_int(int value); +QNumber *qnumber_from_int64(int64_t value); +void qnumber_destroy(QNumber *qnum); +int qnumber_to_int(const QNumber *qnum); + +#endif /* QNUMBER_H */ diff --git a/qobject.h b/qobject.h index d3378b1..20b9a99 100644 --- a/qobject.h +++ b/qobject.h @@ -17,6 +17,7 @@ typedef enum { QTYPE_NONE, QTYPE_QSTRING, + QTYPE_QNUMBER, } qtype_t; struct QObject;