Manage enumerations at the library level
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 30 Sep 2010 19:57:54 +0000 (15:57 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 30 Sep 2010 19:57:54 +0000 (15:57 -0400)
.. rather than keeping a table individually for each format.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/types/enum.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
types/bitfield.c
types/enum.c [new file with mode: 0644]
types/float.c
types/integer.c

index 0f0d69211964175aee368a6ce1f50d00282b3daf..017d0e058b97a5a8b06c82c14b04ea2dfdd5ec11 100644 (file)
@@ -38,10 +38,8 @@ static const struct format ctf_format = {
        .double_write = ctf_double_write,
        .float_copy = ctf_float_copy,
        .string_copy = ctf_string_copy,
-       .enum_uint_to_quark = ctf_enum_uint_to_quark,
-       .enum_int_to_quark = ctf_enum_int_to_quark,
-       .enum_quark_to_uint = ctf_enum_quark_to_uint,
-       .enum_quark_to_int = ctf_enum_quark_to_int,
+       .enum_read = ctf_enum_read,
+       .enum_write = ctf_enum_write,
 };
 
 void ctf_init(void)
index 5e0fda7dc25d5eb310c5c33c15af49a76f40bc7c..256807a7f0e2c30e0ba60980494f6e9aad905167 100644 (file)
 #include <stdint.h>
 #include <glib.h>
 
-struct enum_table {
-       GHashTable *value_to_quark;     /* Tuples (value, GQuark) */
-       GHashTable *quark_to_value;     /* Tuples (GQuark, value) */
-};
-
-#if (__WORDSIZE == 32)
-GQuark enum_uint_to_quark(const struct enum_table *table, uint64_t v)
-{
-       gconstpointer q = g_hash_table_lookup(table->value_to_quark, &v);
-       return (GQuark) (unsigned long) q;
-}
-
-GQuark enum_int_to_quark(const struct enum_table *table, uint64_t v)
-{
-       gconstpointer q = g_hash_table_lookup(table->value_to_quark, &v);
-       return (GQuark) (unsigned long) q;
-}
-
-uint64_t enum_quark_to_uint(size_t len, int byte_order, GQuark q)
-{
-       gconstpointer v = g_hash_table_lookup(table->quark_to_value,
-                                             (gconstpointer) q);
-       return *(const uint64_t *) v;
-}
-
-int64_t enum_quark_to_int(size_t len, int byte_order, GQuark q)
-{
-       gconstpointer v = g_hash_table_lookup(table->quark_to_value,
-                                             (gconstpointer) q);
-       return *(const int64_t *) v;
-}
-
-guint enum_val_hash(gconstpointer key)
-{
-       int64_t ukey = *(const int64_t *)key;
-
-       return (guint)ukey ^ (guint)(ukey >> 32);
-}
-
-gboolean enum_val_equal(gconstpointer a, gconstpointer b)
-{
-       int64_t ua = *(const int64_t *)a;
-       int64_t ub = *(const int64_t *)b;
-
-       return ua == ub;
-}
-
-void enum_val_free(void *ptr)
-{
-       g_free(ptr);
-}
-
-void enum_signed_insert(struct enum_table *table, int64_t v, GQuark q)
-{
-       int64_t *valuep = g_new(int64_t, 1);
-
-       g_hash_table_insert(table->value_to_quark, valuep,
-                           (gpointer) (unsigned long) q);
-       g_hash_table_insert(table->quark_to_value, (gpointer) (unsigned long) q,
-                           valuep);
-}
-
-void enum_unsigned_insert(struct enum_table *table, uint64_t v, GQuark q)
-{
-       uint64_t *valuep = g_new(uint64_t, 1);
-
-       g_hash_table_insert(table->value_to_quark, valuep,
-                           (gpointer) (unsigned long) q);
-       g_hash_table_insert(table->quark_to_value, (gpointer) (unsigned long) q,
-                           valuep);
-}
-#else  /* __WORDSIZE != 32 */
-GQuark enum_uint_to_quark(const struct enum_table *table, uint64_t v)
-{
-       gconstpointer q = g_hash_table_lookup(table->value_to_quark,
-                                             (gconstpointer) v);
-       return (GQuark) (unsigned long) q;
-}
-
-GQuark enum_int_to_quark(const struct enum_table *table, uint64_t v)
-{
-       gconstpointer q = g_hash_table_lookup(table->value_to_quark,
-                                             (gconstpointer) v);
-       return (GQuark) (unsigned long) q;
-}
-
-uint64_t enum_quark_to_uint(size_t len, int byte_order, GQuark q)
-{
-       gconstpointer v = g_hash_table_lookup(table->quark_to_value,
-                                             (gconstpointer) (unsigned long) q);
-       return *(const uint64_t *) v;
-}
-
-int64_t enum_quark_to_int(size_t len, int byte_order, GQuark q)
-{
-       gconstpointer v = g_hash_table_lookup(table->quark_to_value,
-                                             (gconstpointer) (unsigned long) q);
-       return *(const int64_t *) v;
-}
-
-guint enum_val_hash(gconstpointer key)
-{
-       return g_direct_hash(key);
-}
-
-gboolean enum_val_equal(gconstpointer a, gconstpointer b)
-{
-       return g_direct_equal(a, b);
-}
-
-void enum_val_free(void *ptr)
-{
-}
-
-void enum_signed_insert(struct enum_table *table, int64_t v, GQuark q)
-{
-       g_hash_table_insert(table->value_to_quark, (gpointer) v,
-                           (gpointer) (unsigned long) q);
-       g_hash_table_insert(table->quark_to_value, (gpointer) (unsigned long) q,
-                           valuep);
-}
-
-void enum_unsigned_insert(struct enum_table *table, uint64_t v, GQuark q)
-{
-       g_hash_table_insert(table->value_to_quark, (gpointer) v,
-                           (gpointer) (unsigned long) q);
-       g_hash_table_insert(table->quark_to_value, (gpointer) (unsigned long) q,
-                           valuep);
-}
-#endif /* __WORDSIZE != 32 */
-
-struct enum_table *enum_new(void)
-{
-       struct enum_table *table;
-
-       table = g_new(struct enum_table, 1);
-       table->value_to_quark = g_hash_table(enum_val_hash, enum_val_equal);
-       table->quark_to_value = g_hash_table_new_full(g_direct_hash,
-                                                     g_direct_equal,
-                                                     NULL, enum_val_free);
-}
-
-void enum_destroy(struct enum_table *table)
-{
-       g_hash_table_destroy(table->value_to_quark);
-       g_hash_table_destroy(table->quark_to_value);
-       g_free(table);
+GQuark ctf_enum_read(const unsigned char *ptr,
+                    const struct type_class_enum *src)
+{
+       struct type_class_bitfield *bitfield_class = &src->p;
+       struct type_class_integer *int_class = &bitfield_class->p;
+
+       if (!int_class->signedness) {
+               uint64_t v;
+
+               v = ctf_bitfield_unsigned_read(src,
+                                       bitfield_class->start_offset,
+                                       int_class->len,
+                                       int_class->byte_order);
+               return enum_uint_to_quark(src, v);
+       } else {
+               int64_t v;
+
+               v = fsrc->bitfield_signed_read(src,
+                                       bitfield_class->start_offset,
+                                       int_class->len,
+                                       int_class->byte_order);
+               return enum_int_to_quark(src, v);
+       }
+}
+
+size_t ctf_enum_write(unsigned char *ptr, const struct type_class_enum *dest,
+                     GQuark q)
+{
+       struct type_class_bitfield *bitfield_class = &dest->p;
+       struct type_class_integer *int_class = &bitfield_class->p;
+
+       if (!int_class->signedness) {
+               uint64_t v;
+
+               v = enum_quark_to_uint(dest, q);
+               return ctf_bitfield_unsigned_write(src,
+                                       bitfield_class->start_offset,
+                                       int_class->len,
+                                       int_class->byte_order, v);
+       } else {
+               int64_t v;
+
+               v = enum_quark_to_int(dest, q);
+               return ctf_bitfield_signed_write(src,
+                                       bitfield_class->start_offset,
+                                       int_class->len,
+                                       int_class->byte_order, v);
+       }
 }
index 2d06d6a58bde0ae7551bbd0618bc87364f2c38ac..0f0615f49902614612ddc6045d34d6755a0f76e7 100644 (file)
@@ -65,17 +65,9 @@ void ctf_float_copy(unsigned char *destp, const struct type_class_float *dest,
 
 size_t ctf_string_copy(unsigned char *dest, const unsigned char *src);
 
-/*
- * A GQuark can be translated to/from strings with g_quark_from_string() and
- * g_quark_to_string().
- */
-GQuark ctf_enum_uint_to_quark(const struct enum_table *table, uint64_t v);
-GQuark ctf_enum_int_to_quark(const struct enum_table *table, uint64_t v);
-uint64_t ctf_enum_quark_to_uint(size_t len, int byte_order, GQuark q);
-int64_t ctf_enum_quark_to_int(size_t len, int byte_order, GQuark q);
-void ctf_enum_signed_insert(struct enum_table *table, int64_t v, GQuark q);
-void ctf_enum_unsigned_insert(struct enum_table *table, uint64_t v, GQuark q);
-struct enum_table *ctf_enum_new(void);
-void ctf_enum_destroy(struct enum_table *table);
+GQuark ctf_enum_read(const unsigned char *ptr,
+                    const struct type_class_enum *src);
+size_t ctf_enum_write(unsigned char *ptr, const struct type_class_enum *dest,
+                     GQuark q);
 
 #endif /* _BABELTRACE_CTF_TYPES_H */
index d31ee831bf15198cd1a2d21efb19d7bda9cd14f3..ac03dba78f48ab798c23e05f3e1196de83ca2ac9 100644 (file)
@@ -31,36 +31,45 @@ struct format {
 
        uint64_t (*uint_read)(const uint8_t *ptr, size_t len, int byte_order);
        int64_t (*int_read)(const uint8_t *ptr, size_t len, int byte_order);
-       size_t (*uint_write)(uint8_t *ptr, size_t len, int byte_order, uint64_t v);
-       size_t (*int_write)(uint8_t *ptr, size_t len, int byte_order, int64_t v);
+       size_t (*uint_write)(uint8_t *ptr, size_t len, int byte_order,
+                            uint64_t v);
+       size_t (*int_write)(uint8_t *ptr, size_t len, int byte_order,
+                           int64_t v);
 
        uint64_t (*bitfield_unsigned_read)(const unsigned char *ptr,
-                                           unsigned long start, unsigned long len,
-                                           int byte_order);
+                                          unsigned long start,
+                                          unsigned long len,
+                                          int byte_order);
        int64_t (*bitfield_signed_read)(const unsigned char *ptr,
-                                        unsigned long start, unsigned long len,
-                                        int byte_order);
+                                       unsigned long start, unsigned long len,
+                                       int byte_order);
        size_t (*bitfield_unsigned_write)(unsigned char *ptr,
-                                          unsigned long start, unsigned long len,
-                                          int byte_order, uint64_t v);
+                                         unsigned long start,
+                                         unsigned long len,
+                                         int byte_order, uint64_t v);
        size_t (*bitfield_signed_write)(unsigned char *ptr,
-                                        unsigned long start, unsigned long len,
-                                        int byte_order, int64_t v);
-
-
-       void (*float_copy)(unsigned char *destp, const struct type_class_float *dest,
-                   const unsigned char *srcp, const struct type_class_float *src);
-       double (*double_read)(const unsigned char *ptr, const struct type_class_float *src);
-       size_t (*double_write)(unsigned char *ptr, const struct type_class_float *dest,
-                       double v);
+                                       unsigned long start,
+                                       unsigned long len,
+                                       int byte_order, int64_t v);
 
+       void (*float_copy)(unsigned char *destp,
+                          const struct type_class_float *dest,
+                          const unsigned char *srcp,
+                           const struct type_class_float *src);
+       double (*double_read)(const unsigned char *ptr,
+                             const struct type_class_float *src);
+       size_t (*double_write)(unsigned char *ptr,
+                              const struct type_class_float *dest,
+                              double v);
 
        size_t (*string_copy)(unsigned char *dest, const unsigned char *src);
 
-       GQuark (*enum_uint_to_quark)(const struct enum_table *table, uint64_t v);
-       GQuark (*enum_int_to_quark)(const struct enum_table *table, uint64_t v);
-       uint64_t (*enum_quark_to_uint)(size_t len, int byte_order, GQuark q);
-       int64_t (*enum_quark_to_int)(size_t len, int byte_order, GQuark q);
+       GQuark (*enum_read)(const unsigned char *ptr,
+                           const struct type_class_enum *src);
+       size_t (*enum_write)(unsigned char *ptr,
+                            const struct type_class_enum *dest,
+                            GQuark q);
+
 };
 
 struct format *bt_lookup_format(GQuark qname);
index b77ac4002017dbb3a7ed0c50fa00b374fbfe23f2..3dea99e54b012d7fffc68640af8705f28249b1b8 100644 (file)
@@ -57,9 +57,14 @@ struct type_class_float {
        /* TODO: we might want to express more info about NaN, +inf and -inf */
 };
 
+struct enum_table {
+       GHashTable *value_to_quark;     /* Tuples (value, GQuark) */
+       GHashTable *quark_to_value;     /* Tuples (GQuark, value) */
+};
+
 struct type_class_enum {
-       struct type_class_bitfield;     /* inherit from bitfield */
-       struct enum_table *table;
+       struct type_class_bitfield p;   /* inherit from bitfield */
+       struct enum_table table;
 };
 
 struct type_class_struct {
@@ -90,4 +95,26 @@ struct type_class_float *float_type_new(const char *name,
                                        size_t alignment);
 void float_type_free(struct type_class_float *float_class);
 
+/*
+ * A GQuark can be translated to/from strings with g_quark_from_string() and
+ * g_quark_to_string().
+ */
+GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v);
+GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v);
+uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
+                           size_t len, int byte_order, GQuark q);
+int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
+                         size_t len, int byte_order, GQuark q);
+void enum_signed_insert(struct type_class_enum *enum_class,
+                       int64_t v, GQuark q);
+void enum_unsigned_insert(struct type_class_enum *enum_class,
+                         uint64_t v, GQuark q);
+
+struct type_class_enum *enum_type_new(const char *name,
+                                     size_t start_offset,
+                                     size_t len, int byte_order,
+                                     int signedness,
+                                     size_t alignment);
+void enum_type_free(struct type_class_enum *enum_class);
+
 #endif /* _BABELTRACE_TYPES_H */
index b21fdc917355fc675d05e856cba8906b5d1b6583..03d3bbcbafd31aca219ea988289b3f6e6f84517c 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <babeltrace/compiler.h>
+#include <babeltrace/types.h>
 #include <stdint.h>
 
 /*
@@ -83,9 +84,6 @@ struct type_class_bitfield *bitfield_type_new(const char *name,
        struct type_class_integer *int_class;
        int ret;
 
-       /*
-        * Freed when type is unregistered.
-        */
        bitfield_class = g_new(struct type_class_bitfield, 1);
        int_class = &bitfield_class->p;
        int_class->p.name = g_quark_from_string(name);
@@ -106,6 +104,5 @@ struct type_class_bitfield *bitfield_type_new(const char *name,
 
 void bitfield_type_free(struct type_class_bitfield *bitfield_class)
 {
-       if (!bitfield_class->name)
-               g_free(bitfield_class);
+       g_free(bitfield_class);
 }
diff --git a/types/enum.c b/types/enum.c
new file mode 100644 (file)
index 0000000..21af948
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * BabelTrace - Enumeration Type
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <babeltrace/compiler.h>
+#include <babeltrace/types.h>
+#include <stdint.h>
+#include <glib.h>
+
+struct enum_table {
+       GHashTable *value_to_quark;     /* Tuples (value, GQuark) */
+       GHashTable *quark_to_value;     /* Tuples (GQuark, value) */
+};
+
+#if (__WORDSIZE == 32)
+GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v)
+{
+       gconstpointer q = g_hash_table_lookup(enum_class->table.value_to_quark,
+                                             &v);
+       return (GQuark) (unsigned long) q;
+}
+
+GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v)
+{
+       gconstpointer q = g_hash_table_lookup(enum_class->table.value_to_quark,
+                                             &v);
+       return (GQuark) (unsigned long) q;
+}
+
+uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
+                           size_t len, int byte_order, GQuark q)
+{
+       gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
+                                             (gconstpointer) q);
+       return *(const uint64_t *) v;
+}
+
+int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
+                         size_t len, int byte_order, GQuark q)
+{
+       gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
+                                             (gconstpointer) q);
+       return *(const int64_t *) v;
+}
+
+guint enum_val_hash(gconstpointer key)
+{
+       int64_t ukey = *(const int64_t *)key;
+
+       return (guint)ukey ^ (guint)(ukey >> 32);
+}
+
+gboolean enum_val_equal(gconstpointer a, gconstpointer b)
+{
+       int64_t ua = *(const int64_t *)a;
+       int64_t ub = *(const int64_t *)b;
+
+       return ua == ub;
+}
+
+void enum_val_free(void *ptr)
+{
+       g_free(ptr);
+}
+
+void enum_signed_insert(struct type_class_enum *enum_class, int64_t v, GQuark q)
+{
+       int64_t *valuep = g_new(int64_t, 1);
+
+       g_hash_table_insert(enum_class->table>value_to_quark, valuep,
+                           (gpointer) (unsigned long) q);
+       g_hash_table_insert(enum_class->table.quark_to_value,
+                           (gpointer) (unsigned long) q,
+                           valuep);
+}
+
+void enum_unsigned_insert(struct type_class_enum *enum_class, uint64_t v, GQuark q)
+{
+       uint64_t *valuep = g_new(uint64_t, 1);
+
+       g_hash_table_insert(enum_class->table.value_to_quark, valuep,
+                           (gpointer) (unsigned long) q);
+       g_hash_table_insert(enum_class->table.quark_to_value,
+                           (gpointer) (unsigned long) q,
+                           valuep);
+}
+#else  /* __WORDSIZE != 32 */
+GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v)
+{
+       gconstpointer q = g_hash_table_lookup(enum_class->table.value_to_quark,
+                                             (gconstpointer) v);
+       return (GQuark) (unsigned long) q;
+}
+
+GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v)
+{
+       gconstpointer q = g_hash_table_lookup(enum_class->table.value_to_quark,
+                                             (gconstpointer) v);
+       return (GQuark) (unsigned long) q;
+}
+
+uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
+                           size_t len, int byte_order, GQuark q)
+{
+       gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
+                                             (gconstpointer) (unsigned long) q);
+       return *(const uint64_t *) v;
+}
+
+int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
+                         size_t len, int byte_order, GQuark q)
+{
+       gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
+                                             (gconstpointer) (unsigned long) q);
+       return *(const int64_t *) v;
+}
+
+guint enum_val_hash(gconstpointer key)
+{
+       return g_direct_hash(key);
+}
+
+gboolean enum_val_equal(gconstpointer a, gconstpointer b)
+{
+       return g_direct_equal(a, b);
+}
+
+void enum_val_free(void *ptr)
+{
+}
+
+void enum_signed_insert(struct type_class_enum *enum_class,
+                        int64_t v, GQuark q)
+{
+       g_hash_table_insert(enum_class->table.value_to_quark, (gpointer) v,
+                           (gpointer) (unsigned long) q);
+       g_hash_table_insert(enum_class->table.quark_to_value,
+                           (gpointer) (unsigned long) q,
+                           valuep);
+}
+
+void enum_unsigned_insert(struct type_class_enum *enum_class,
+                         uint64_t v, GQuark q)
+{
+       g_hash_table_insert(enum_class->table.value_to_quark, (gpointer) v,
+                           (gpointer) (unsigned long) q);
+       g_hash_table_insert(enum_class->table.quark_to_value,
+                           (gpointer) (unsigned long) q,
+                           valuep);
+}
+#endif /* __WORDSIZE != 32 */
+
+size_t enum_copy(unsigned char *dest, const struct format *fdest, 
+                const unsigned char *src, const struct format *fsrc,
+                const struct type_class *type_class)
+{
+       struct type_class_enum *enum_class =
+               container_of(type_class, struct type_class_enum, p);
+       struct type_class_bitfield *bitfield_class = &enum_class->p;
+       struct type_class_integer *int_class = &bitfield_class->p;
+       GQuark v;
+
+       v = fsrc->enum_read(src, enum_class)
+       return fdest->enum_write(dest, enum_class, v);
+}
+
+struct type_class_enum *enum_type_new(const char *name,
+                                     size_t start_offset,
+                                     size_t len, int byte_order,
+                                     int signedness,
+                                     size_t alignment)
+{
+       struct type_class_bitfield *bitfield_class;
+       struct type_class_integer *int_class;
+       int ret;
+
+       enum_class = g_new(struct type_class_bitfield, 1);
+       enum_class->table.value_to_quark = g_hash_table(enum_val_hash,
+                                                       enum_val_equal);
+       enum_class->table.quark_to_value = g_hash_table_new_full(g_direct_hash,
+                                                       g_direct_equal,
+                                                       NULL, enum_val_free);
+       bitfield_class = &enum_class->p;
+       bitfield_class->start_offset = start_offset;
+       int_class = &bitfield_class->p;
+       int_class->p.name = g_quark_from_string(name);
+       int_class->p.alignment = alignment;
+       int_class->len = len;
+       int_class->byte_order = byte_order;
+       int_class->signedness = signedness;
+       bitfield_class->start_offset = start_offset;
+       if (int_class->p.name) {
+               ret = register_type(&int_class->p);
+               if (ret) {
+                       g_hash_table_destroy(enum_class->table.value_to_quark);
+                       g_hash_table_destroy(enum_class->table.quark_to_value);
+                       g_free(enum_class);
+                       return NULL;
+               }
+       }
+       return enum_class;
+}
+
+void enum_type_free(struct type_class_enum *enum_class)
+{
+       g_hash_table_destroy(enum_class->table.value_to_quark);
+       g_hash_table_destroy(enum_class->table.quark_to_value);
+       g_free(enum_class);
+}
index ac1525595bc99c82a95f9cd2bc62321c6480be54..78499c8f14ea6205d732bf3a68b426d0a25221c3 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <babeltrace/compiler.h>
+#include <babeltrace/types.h>
 
 size_t float_copy(unsigned char *dest, const struct format *fdest, 
                  const unsigned char *src, const struct format *fsrc,
@@ -46,9 +47,6 @@ struct type_class_float *float_type_new(const char *name,
        struct type_class_float *float_class;
        int ret;
 
-       /*
-        * Freed when type is unregistered.
-        */
        float_class = g_new(struct type_class_float, 1);
        float_class->p.name = g_quark_from_string(name);
        float_class->p.alignment = alignment;
@@ -67,6 +65,5 @@ struct type_class_float *float_type_new(const char *name,
 
 void float_type_free(struct type_class_float *float_class)
 {
-       if (!float_class->name)
-               g_free(float_class);
+       g_free(float_class);
 }
index b338a5913971f86f7787c6a9d4d3a2db4b6778e9..cf01f07a70fea8b45d0cdffcce9f45244ebcb5a2 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
+#include <babeltrace/types.h>
 #include <stdint.h>
 
 size_t integer_copy(unsigned char *dest, const struct format *fdest, 
@@ -56,9 +57,6 @@ struct type_class_integer *integer_type_new(const char *name,
        struct type_class_integer *int_class;
        int ret;
 
-       /*
-        * Freed when type is unregistered.
-        */
        int_class = g_new(struct type_class_integer, 1);
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
@@ -78,6 +76,5 @@ struct type_class_integer *integer_type_new(const char *name,
 
 void integer_type_free(struct type_class_integer *int_class)
 {
-       if (!int_class->name)
-               g_free(int_class);
+       g_free(int_class);
 }
This page took 0.049422 seconds and 4 git commands to generate.