Annotation of qemu/qint.c, revision 1.1.1.3

1.1       root        1: /*
1.1.1.2   root        2:  * QInt Module
1.1       root        3:  *
                      4:  * Copyright (C) 2009 Red Hat Inc.
                      5:  *
                      6:  * Authors:
                      7:  *  Luiz Capitulino <lcapitulino@redhat.com>
                      8:  *
1.1.1.2   root        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.
1.1       root       11:  */
1.1.1.2   root       12: 
1.1       root       13: #include "qint.h"
                     14: #include "qobject.h"
                     15: #include "qemu-common.h"
                     16: 
                     17: static void qint_destroy_obj(QObject *obj);
                     18: 
                     19: static const QType qint_type = {
                     20:     .code = QTYPE_QINT,
                     21:     .destroy = qint_destroy_obj,
                     22: };
                     23: 
                     24: /**
                     25:  * qint_from_int(): Create a new QInt from an int64_t
                     26:  *
                     27:  * Return strong reference.
                     28:  */
                     29: QInt *qint_from_int(int64_t value)
                     30: {
                     31:     QInt *qi;
                     32: 
1.1.1.3 ! root       33:     qi = g_malloc(sizeof(*qi));
1.1       root       34:     qi->value = value;
                     35:     QOBJECT_INIT(qi, &qint_type);
                     36: 
                     37:     return qi;
                     38: }
                     39: 
                     40: /**
                     41:  * qint_get_int(): Get the stored integer
                     42:  */
                     43: int64_t qint_get_int(const QInt *qi)
                     44: {
                     45:     return qi->value;
                     46: }
                     47: 
                     48: /**
                     49:  * qobject_to_qint(): Convert a QObject into a QInt
                     50:  */
                     51: QInt *qobject_to_qint(const QObject *obj)
                     52: {
                     53:     if (qobject_type(obj) != QTYPE_QINT)
                     54:         return NULL;
                     55: 
                     56:     return container_of(obj, QInt, base);
                     57: }
                     58: 
                     59: /**
                     60:  * qint_destroy_obj(): Free all memory allocated by a
                     61:  * QInt object
                     62:  */
                     63: static void qint_destroy_obj(QObject *obj)
                     64: {
                     65:     assert(obj != NULL);
1.1.1.3 ! root       66:     g_free(qobject_to_qint(obj));
1.1       root       67: }

unix.superglobalmegacorp.com