qemu_vmalloc: align properly for transparent hugepages and KVM
[qemu.git] / qbool.c
blob590cd716eadde40749aadcacc72ddc54efed68c4
1 /*
2 * QBool Module
4 * Copyright IBM, Corp. 2009
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
14 #include "qbool.h"
15 #include "qobject.h"
16 #include "qemu-common.h"
18 static void qbool_destroy_obj(QObject *obj);
20 static const QType qbool_type = {
21 .code = QTYPE_QBOOL,
22 .destroy = qbool_destroy_obj,
25 /**
26 * qbool_from_int(): Create a new QBool from an int
28 * Return strong reference.
30 QBool *qbool_from_int(int value)
32 QBool *qb;
34 qb = g_malloc(sizeof(*qb));
35 qb->value = value;
36 QOBJECT_INIT(qb, &qbool_type);
38 return qb;
41 /**
42 * qbool_get_int(): Get the stored int
44 int qbool_get_int(const QBool *qb)
46 return qb->value;
49 /**
50 * qobject_to_qbool(): Convert a QObject into a QBool
52 QBool *qobject_to_qbool(const QObject *obj)
54 if (qobject_type(obj) != QTYPE_QBOOL)
55 return NULL;
57 return container_of(obj, QBool, base);
60 /**
61 * qbool_destroy_obj(): Free all memory allocated by a
62 * QBool object
64 static void qbool_destroy_obj(QObject *obj)
66 assert(obj != NULL);
67 g_free(qobject_to_qbool(obj));