Build fix
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 29 Dec 2010 00:36:14 +0000 (19:36 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 29 Dec 2010 00:36:14 +0000 (19:36 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
23 files changed:
.gitignore
Makefile.am
configure.ac
converter/Makefile.am [new file with mode: 0644]
converter/babeltrace.c [new file with mode: 0644]
formats/ctf/ctf.c
formats/ctf/types/enum.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
formats/ctf/types/string.c
formats/registry.c
include/babeltrace/align.h
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
types/array.c
types/enum.c
types/float.c
types/integer.c
types/sequence.c
types/string.c
types/struct.c
types/types.c

index 3a3eeffa3648bb8656a11af1f6f70b0a098d1abe..5fb74219871814cb4ac444586d046e159386e4fc 100644 (file)
@@ -1 +1,5 @@
 tests/test-bitfield
+*.o
+*.a
+Makefile
+Makefile.in
index f88b548ee33251952246b2c06828463a7b1052d7..073dfc6d52d95d5443c17eafb58f58991157761b 100644 (file)
@@ -2,12 +2,4 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = types . tests
-
-bin_PROGRAMS = babeltrace
-
-babeltrace_LDADD = \
-       types/types.a \
-       formats/registry.a
-
-# converter/
+SUBDIRS = types formats converter tests
index d1d4feab6ba5b063e0674835486b1336adaa6ccf..2a153583add1adec979fa80df14b6422d8092c79 100644 (file)
@@ -44,6 +44,7 @@ AC_CONFIG_FILES([
        formats/Makefile
        formats/ctf/Makefile
        formats/ctf/types/Makefile
+       converter/Makefile
        tests/Makefile
 ])
 AC_OUTPUT
diff --git a/converter/Makefile.am b/converter/Makefile.am
new file mode 100644 (file)
index 0000000..3ecca8c
--- /dev/null
@@ -0,0 +1,12 @@
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+bin_PROGRAMS = babeltrace
+
+babeltrace_SOURCES = \
+       babeltrace.c
+
+babeltrace_LDADD = \
+       $(top_srcdir)/types/libtypes.a \
+       $(top_srcdir)/formats/libregistry.a
+
+
diff --git a/converter/babeltrace.c b/converter/babeltrace.c
new file mode 100644 (file)
index 0000000..9007688
--- /dev/null
@@ -0,0 +1,6 @@
+
+
+int main(int argv, char **argc)
+{
+       return 0;
+}
index 156e39db09233c327f3d6d168d3db0c027e28381..c8a3712235ae749215e906f342921a926605f7a8 100644 (file)
@@ -21,7 +21,7 @@
 
 void __attribute__((constructor)) ctf_init(void);
 
-static const struct format ctf_format = {
+static struct format ctf_format = {
        .uint_read = ctf_uint_read,
        .int_read = ctf_int_read,
        .uint_write = ctf_uint_write,
@@ -47,7 +47,7 @@ void ctf_init(void)
 {
        int ret;
 
-       ctf_format->name = g_quark_from_static_string("ctf");
+       ctf_format.name = g_quark_from_static_string("ctf");
        ret = bt_register_format(&ctf_format);
        assert(!ret);
 }
index a1d034c38b79f39903e2a593e9aed3e1e68b31ee..a62d84e712ef6104802f3301197cdc85c859b3c8 100644 (file)
@@ -23,7 +23,7 @@
 GQuark ctf_enum_read(struct stream_pos *pos,
                     const struct type_class_enum *src)
 {
-       struct type_class_integer *int_class = &src->p;
+       const struct type_class_integer *int_class = &src->p;
 
        if (!int_class->signedness) {
                uint64_t v;
@@ -33,26 +33,26 @@ GQuark ctf_enum_read(struct stream_pos *pos,
        } else {
                int64_t v;
 
-               v = fsrc->ctf_int_read(pos, int_class);
+               v = ctf_int_read(pos, int_class);
                return enum_int_to_quark(src, v);
        }
 }
 
-size_t ctf_enum_write(struct stream_pos *pos,
+void ctf_enum_write(struct stream_pos *pos,
                      const struct type_class_enum *dest,
                      GQuark q)
 {
-       struct type_class_integer *int_class = &dest->p;
+       const struct type_class_integer *int_class = &dest->p;
 
        if (!int_class->signedness) {
                uint64_t v;
 
                v = enum_quark_to_uint(dest, q);
-               return ctf_uint_write(pos, int_class, v);
+               ctf_uint_write(pos, int_class, v);
        } else {
                int64_t v;
 
                v = enum_quark_to_int(dest, q);
-               return ctf_int_write(pos, int_class, v);
+               ctf_int_write(pos, int_class, v);
        }
 }
index 04f2071da0613e0b6e12673dfd9143f1975bc4f3..be068316eb9241084abd4b0e662d6f2acd1880a9 100644 (file)
@@ -78,7 +78,7 @@ void _ctf_float_copy(struct stream_pos *destp,
        uint64_t mantissa;
 
        /* Read */
-       if (src->byte_order == LITTLE_ENDIAN) {
+       if (src_class->byte_order == LITTLE_ENDIAN) {
                mantissa = ctf_uint_read(srcp, src_class->mantissa);
                exp = ctf_int_read(srcp, src_class->exp);
                sign = ctf_uint_read(srcp, src_class->sign);
@@ -88,7 +88,7 @@ void _ctf_float_copy(struct stream_pos *destp,
                mantissa = ctf_uint_read(srcp, src_class->mantissa);
        }
        /* Write */
-       if (dest->byte_order == LITTLE_ENDIAN) {
+       if (dest_class->byte_order == LITTLE_ENDIAN) {
                ctf_uint_write(destp, dest_class->mantissa, mantissa);
                ctf_int_write(destp, dest_class->exp, exp);
                ctf_uint_write(destp, dest_class->sign, sign);
@@ -111,7 +111,7 @@ double ctf_double_read(struct stream_pos *srcp,
                       const struct type_class_float *float_class)
 {
        union doubleIEEE754 u;
-       struct ctf_float *dest_class = float_type_new(NULL,
+       struct type_class_float *dest_class = float_type_new(NULL,
                                DBL_MANT_DIG,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
@@ -119,7 +119,7 @@ double ctf_double_read(struct stream_pos *srcp,
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
-       init_pos(&destp, &u.bits);
+       init_pos(&destp, (unsigned char *) u.bits);
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
@@ -130,7 +130,7 @@ void ctf_double_write(struct stream_pos *destp,
                      double v)
 {
        union doubleIEEE754 u;
-       struct ctf_float *src_class = float_type_new(NULL,
+       struct type_class_float *src_class = float_type_new(NULL,
                                DBL_MANT_DIG,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
@@ -139,7 +139,7 @@ void ctf_double_write(struct stream_pos *destp,
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
-       init_pos(&srcp, &u.bits);
+       init_pos(&srcp, (unsigned char *) u.bits);
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
@@ -148,7 +148,7 @@ long double ctf_ldouble_read(struct stream_pos *srcp,
                             const struct type_class_float *float_class)
 {
        union ldoubleIEEE754 u;
-       struct ctf_float *dest_class = float_type_new(NULL,
+       struct type_class_float *dest_class = float_type_new(NULL,
                                LDBL_MANT_DIG,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
@@ -156,7 +156,7 @@ long double ctf_ldouble_read(struct stream_pos *srcp,
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
-       init_pos(&destp, &u.bits);
+       init_pos(&destp, (unsigned char *) u.bits);
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
@@ -167,7 +167,7 @@ void ctf_ldouble_write(struct stream_pos *destp,
                       long double v)
 {
        union ldoubleIEEE754 u;
-       struct ctf_float *src_class = float_type_new(NULL,
+       struct type_class_float *src_class = float_type_new(NULL,
                                LDBL_MANT_DIG,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
@@ -176,7 +176,7 @@ void ctf_ldouble_write(struct stream_pos *destp,
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
-       init_pos(&srcp, &u.bits);
+       init_pos(&srcp, (unsigned char *) u.bits);
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
index 003584f1a78fe54492cc34c08fc306fe548e8c38..e0de8052940349dbd5d1ff565b8badee08890b1b 100644 (file)
@@ -16,8 +16,8 @@
  * all copies or substantial portions of the Software.
  */
 
-#include <ctf/ctf-types.h>
-#include <ctf/bitfield.h>
+#include <babeltrace/ctf/types.h>
+#include <babeltrace/bitfield.h>
 #include <stdint.h>
 #include <glib.h>
 #include <endian.h>
@@ -188,7 +188,7 @@ end:
 }
 
 uint64_t ctf_uint_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *int_class)
+                       const struct type_class_integer *int_class)
 {
        uint64_t v;
 
@@ -204,7 +204,7 @@ uint64_t ctf_uint_read(struct stream_pos *pos,
 }
 
 int64_t ctf_int_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *int_class)
+                       const struct type_class_integer *int_class)
 {
        int64_t v;
 
@@ -220,7 +220,7 @@ int64_t ctf_int_read(struct stream_pos *pos,
 }
 
 void ctf_uint_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *int_class,
+                       const struct type_class_integer *int_class,
                        uint64_t v)
 {
        align_pos(pos, int_class->p.alignment);
@@ -231,13 +231,13 @@ void ctf_uint_write(struct stream_pos *pos,
                                      int_class->len, v);
        else
                ctf_bitfield_write_be(pos->base, pos->offset,
-                                     int_class->len,, v);
+                                     int_class->len, v);
 end:
        move_pos(pos, int_class->len);
 }
 
 void ctf_int_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *int_class,
+                       const struct type_class_integer *int_class,
                        int64_t v)
 {
        align_pos(pos, int_class->p.alignment);
index 2e6a25ec005d433713ec89cfcef6d19cd435502d..fab69c4fa8833208c2f95d5d971a7764e9029ad9 100644 (file)
@@ -48,10 +48,8 @@ void ctf_string_read(unsigned char **dest, struct stream_pos *src,
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
-       if (dest->dummy)
-               goto end;
        *dest = g_realloc(*dest, len);
-       strcpy(dest, srcaddr);
+       strcpy(*dest, srcaddr);
 end:
        move_pos(src, len);
 }
index 6b28cbeb0b1cad5354fd64bb688bbf5e1b2aa750..4f9dc244a3618451c54e0f4265563d0a7a0bc739 100644 (file)
@@ -16,6 +16,7 @@
  * all copies or substantial portions of the Software.
  */
 
+#include <babeltrace/format.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -35,19 +36,19 @@ struct format *bt_lookup_format(GQuark qname)
        if (!init_done)
                return NULL;
        return g_hash_table_lookup(format_registry,
-                                  (gconstpointer) (unsigned long) qname)
+                                  (gconstpointer) (unsigned long) qname);
 }
 
-int bt_register_format(const struct format *format)
+int bt_register_format(struct format *format)
 {
        if (!init_done)
                format_init();
 
-       if (bt_lookup_format(qname))
+       if (bt_lookup_format(format->name))
                return -EEXIST;
 
        g_hash_table_insert(format_registry,
-                           (gconstpointer) (unsigned long) format->name,
+                           (gpointer) (unsigned long) format->name,
                            format);
        return 0;
 }
@@ -59,7 +60,7 @@ void format_init(void)
        init_done = 1;
 }
 
-int format_finalize(void)
+void format_finalize(void)
 {
        g_hash_table_destroy(format_registry);
 }
index 00bd4cb3b6d84dca0ec61666d4834756bcf43301..d5197cb42f5e6bb6b7d0ce991bb7088eff65749b 100644 (file)
@@ -17,7 +17,7 @@
  * all copies or substantial portions of the Software.
  */
 
-#include <ctf/compiler.h>
+#include <babeltrace/compiler.h>
 
 #define ALIGN(x, a)            __ALIGN_MASK(x, (typeof(x))(a) - 1)
 #define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
index 448ea9524ef897ca84c86279f360560f7823c0d1..a2ccca680d16bd2d0d094a0d97dba19848ead1da 100644 (file)
@@ -19,6 +19,7 @@
  * all copies or substantial portions of the Software.
  */
 
+#include <babeltrace/types.h>
 #include <stdint.h>
 #include <glib.h>
 
@@ -52,8 +53,9 @@ long double ctf_ldouble_read(struct stream_pos *pos,
 void ctf_ldouble_write(struct stream_pos *pos,
                const struct type_class_float *dest,
                long double v);
-void ctf_float_copy(struct stream_pos *destp, const struct type_class_float *dest,
-               struct stream_pos *srcp, const struct type_class_float *src);
+void ctf_float_copy(struct stream_pos *destp,
+               struct stream_pos *srcp,
+               const struct type_class_float *float_class);
 
 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
                     const struct type_class_string *string_class);
index 7162c0ea0822cbb2320317407aa1be87d0020f5e..c6dedc1afbd14279054708add6d766e6a5cd4c76 100644 (file)
@@ -19,6 +19,7 @@
  * all copies or substantial portions of the Software.
  */
 
+#include <babeltrace/types.h>
 #include <stdint.h>
 #include <glib.h>
 
@@ -36,9 +37,9 @@ struct format {
                          const struct type_class_integer *int_class,
                          int64_t v);
 
-       void (*float_copy)(struct stream_pos *dest,
-                          struct stream_pos *src,
-                          const struct type_class_float *src);
+       void (*float_copy)(struct stream_pos *destp,
+                          struct stream_pos *srcp,
+                          const struct type_class_float *float_class);
        double (*double_read)(struct stream_pos *pos,
                              const struct type_class_float *float_class);
        void (*double_write)(struct stream_pos *pos,
@@ -73,7 +74,7 @@ struct format {
 };
 
 struct format *bt_lookup_format(GQuark qname);
-int bt_register_format(const struct format *format);
+int bt_register_format(struct format *format);
 
 /* TBD: format unregistration */
 
index cc5cc89c45012c608b1a4c796de25c203852f61c..02b209117475a8939ce8703c959aa3c846c68c29 100644 (file)
  * all copies or substantial portions of the Software.
  */
 
-#include <babeltrace/format.h>
 #include <babeltrace/align.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <limits.h>
 #include <string.h>
+#include <glib.h>
 
 /* Preallocate this many fields for structures */
 #define DEFAULT_NR_STRUCT_FIELDS 8
@@ -75,20 +78,23 @@ static inline
 unsigned char *get_pos_addr(struct stream_pos *pos)
 {
        /* Only makes sense to get the address after aligning on CHAR_BIT */
-       assert(!(pos->alignment % CHAR_BIT));
+       assert(!(pos->offset % CHAR_BIT));
        return pos->base + (pos->offset / CHAR_BIT);
 }
 
+struct format;
+
 struct type_class {
        GQuark name;            /* type name */
        size_t alignment;       /* type alignment, in bits */
+       int ref;                /* number of references to the type */
        /*
         * Type copy function. Knows how to find the child type_class from the
         * parent type_class.
         */
-       size_t (*copy)(struct stream_pos *dest, const struct format *fdest, 
-                      struct stream_pos *src, const struct format *fsrc,
-                      const struct type_class *type_class);
+       void (*copy)(struct stream_pos *dest, const struct format *fdest, 
+                    struct stream_pos *src, const struct format *fsrc,
+                    const struct type_class *type_class);
        void (*free)(struct type_class *type_class);
 };
 
@@ -106,9 +112,9 @@ struct type_class_integer {
 
 struct type_class_float {
        struct type_class p;
-       struct int_class *sign;
-       struct int_class *mantissa;
-       struct int_class *exp;
+       struct type_class_integer *sign;
+       struct type_class_integer *mantissa;
+       struct type_class_integer *exp;
        int byte_order;
        /* TODO: we might want to express more info about NaN, +inf and -inf */
 };
@@ -119,7 +125,7 @@ struct enum_table {
 };
 
 struct type_class_enum {
-       struct type_class_int p;        /* inherit from integer */
+       struct type_class_integer p;    /* inherit from integer */
        struct enum_table table;
 };
 
@@ -150,8 +156,11 @@ struct type_class_sequence {
        struct type_class *elem;
 };
 
-struct type_class *ctf_lookup_type(GQuark qname);
-int ctf_register_type(struct type_class *type_class);
+struct type_class *lookup_type(GQuark qname);
+int register_type(struct type_class *type_class);
+
+void type_ref(struct type_class *type_class);
+void type_unref(struct type_class *type_class);
 
 /* Nameless types can be created by passing a NULL name */
 
@@ -178,9 +187,9 @@ void float_type_free(struct type_class_float *float_class);
 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);
+                           GQuark q);
 int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
-                         size_t len, int byte_order, GQuark q);
+                         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,
@@ -195,7 +204,7 @@ void enum_type_free(struct type_class_enum *enum_class);
 struct type_class_struct *struct_type_new(const char *name);
 void struct_type_free(struct type_class_struct *struct_class);
 void struct_type_add_field(struct type_class_struct *struct_class,
-                          GQuark field_name,
+                          const char *field_name,
                           struct type_class *type_class);
 /*
  * Returns the index of a field within a structure.
index d6a0c8b2bc552f622473e8babe165d51be659ad1..43aee466e26c6919a053a54d18dfb9f9e6f056d8 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
 void array_copy(struct stream_pos *dest, const struct format *fdest, 
                struct stream_pos *src, const struct format *fsrc,
@@ -32,7 +32,7 @@ void array_copy(struct stream_pos *dest, const struct format *fdest,
 
        for (i = 0; i < array_class->len; i++) {
                struct type_class *elem_class = array_class->elem;
-               elem_class->copy(dest, fdest, src, fsrc, &elem_class->p);
+               elem_class->copy(dest, fdest, src, fsrc, elem_class);
        }
        fsrc->array_end(src, array_class);
        fdest->array_end(dest, array_class);
@@ -40,13 +40,13 @@ void array_copy(struct stream_pos *dest, const struct format *fdest,
 
 void array_type_free(struct type_class_array *array_class)
 {
-       array_class->elem->free(&array_class->elem->p);
+       type_unref(array_class->elem);
        g_free(array_class);
 }
 
 static void _array_type_free(struct type_class *type_class)
 {
-       struct type_class_struct *array_class =
+       struct type_class_array *array_class =
                container_of(type_class, struct type_class_array, p);
        array_type_free(array_class);
 }
@@ -55,17 +55,21 @@ struct type_class_array *array_type_new(const char *name, size_t len,
                                        struct type_class *elem)
 {
        struct type_class_array *array_class;
+       struct type_class *type_class;
        int ret;
 
        array_class = g_new(struct type_class_array, 1);
-       type_class = &float_class->p;
+       type_class = &array_class->p;
 
        array_class->len = len;
+       type_ref(elem);
+       array_class->elem = elem;
        type_class->name = g_quark_from_string(name);
        /* No need to align the array, the first element will align itself */
        type_class->alignment = 1;
        type_class->copy = array_copy;
        type_class->free = _array_type_free;
+       type_class->ref = 1;
 
        if (type_class->name) {
                ret = ctf_register_type(type_class);
@@ -75,7 +79,7 @@ struct type_class_array *array_type_new(const char *name, size_t len,
        return array_class;
 
 error_register:
-       array_class->elem->free(&array_class->elem->p);
+       type_unref(array_class->elem);
        g_free(array_class);
        return NULL;
 }
index 489667a3abf8dd09c84e63c3f5c7bd0bae1d155b..015cf7fc757deaeaaefc1fb946f9d19f7b213abb 100644 (file)
  */
 
 #include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.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)
 {
@@ -42,7 +37,7 @@ 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)
+                           GQuark q)
 {
        gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
                                              (gconstpointer) q);
@@ -50,7 +45,7 @@ uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
 }
 
 int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
-                         size_t len, int byte_order, GQuark q)
+                         GQuark q)
 {
        gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
                                              (gconstpointer) q);
@@ -81,7 +76,7 @@ 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,
+       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,
@@ -114,7 +109,7 @@ 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)
+                           GQuark q)
 {
        gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
                                              (gconstpointer) (unsigned long) q);
@@ -122,7 +117,7 @@ uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
 }
 
 int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
-                         size_t len, int byte_order, GQuark q)
+                         GQuark q)
 {
        gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_value,
                                              (gconstpointer) (unsigned long) q);
@@ -164,16 +159,16 @@ void enum_unsigned_insert(struct type_class_enum *enum_class,
 }
 #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)
+void enum_copy(struct stream_pos *dest, const struct format *fdest, 
+              struct stream_pos *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);
+               container_of(type_class, struct type_class_enum, p.p);
        struct type_class_integer *int_class = &enum_class->p;
        GQuark v;
 
-       v = fsrc->enum_read(src, enum_class)
+       v = fsrc->enum_read(src, enum_class);
        return fdest->enum_write(dest, enum_class, v);
 }
 
@@ -188,7 +183,7 @@ static
 void _enum_type_free(struct type_class *type_class)
 {
        struct type_class_enum *enum_class =
-               container_of(type_class, struct type_class_enum, p);
+               container_of(type_class, struct type_class_enum, p.p);
        enum_type_free(enum_class);
 }
 
@@ -197,6 +192,7 @@ struct type_class_enum *enum_type_new(const char *name,
                                      int signedness,
                                      size_t alignment)
 {
+       struct type_class_enum *enum_class;
        struct type_class_integer *int_class;
        int ret;
 
@@ -211,6 +207,7 @@ struct type_class_enum *enum_type_new(const char *name,
        int_class->p.alignment = alignment;
        int_class->p.copy = enum_copy;
        int_class->p.free = _enum_type_free;
+       int_class->p.ref = 1;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
index b3e0dc1cfc3808c27ebf16ee8be6e731a91a39f0..abbd86d5fb4d2aff1c0d5eb6da61f43b79eae216 100644 (file)
  */
 
 #include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
-void float_copy(struct stream_pos *dest, const struct format *fdest, 
-               struct stream_pos *src, const struct format *fsrc,
+void float_copy(struct stream_pos *destp,
+               const struct format *fdest,
+               struct stream_pos *srcp,
+               const struct format *fsrc,
                const struct type_class *type_class)
 {
        struct type_class_float *float_class =
                container_of(type_class, struct type_class_float, p);
 
        if (fsrc->float_copy == fdest->float_copy) {
-               fsrc->float_copy(dest, src, float_class);
+               fsrc->float_copy(destp, srcp, float_class);
        } else {
                double v;
 
-               v = fsrc->double_read(src, float_class);
-               fdest->double_write(dest, float_class, v);
+               v = fsrc->double_read(srcp, float_class);
+               fdest->double_write(destp, float_class, v);
        }
 }
 
@@ -68,6 +70,7 @@ struct type_class_float *float_type_new(const char *name,
        type_class->alignment = alignment;
        type_class->copy = float_copy;
        type_class->free = _float_type_free;
+       type_class->ref = 1;
        float_class->byte_order = byte_order;
 
        float_class->sign = integer_type_new(NULL, 1,
index 41a3116120984f32fe74011476b11c00924aa85d..bbbf4b3e0145da9e8c80d84b6e54db900de4cbfc 100644 (file)
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 #include <stdint.h>
 
-size_t integer_copy(unsigned char *dest, const struct format *fdest, 
-                   const unsigned char *src, const struct format *fsrc,
-                   const struct type_class *type_class)
+void integer_copy(struct stream_pos *dest, const struct format *fdest, 
+                 struct stream_pos *src, const struct format *fsrc,
+                 const struct type_class *type_class)
 {
        struct type_class_integer *int_class =
                container_of(type_class, struct type_class_integer, p);
@@ -32,12 +32,12 @@ size_t integer_copy(unsigned char *dest, const struct format *fdest,
                uint64_t v;
 
                v = fsrc->uint_read(src, int_class);
-               return fdest->uint_write(dest, int_class, v);
+               fdest->uint_write(dest, int_class, v);
        } else {
                int64_t v;
 
                v = fsrc->int_read(src, int_class);
-               return fdest->int_write(dest, int_class, v);
+               fdest->int_write(dest, int_class, v);
        }
 }
 
@@ -66,6 +66,7 @@ struct type_class_integer *integer_type_new(const char *name,
        int_class->p.alignment = alignment;
        int_class->p.copy = integer_copy;
        int_class->p.free = _integer_type_free;
+       int_class->p.ref = 1;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
index a8d745296f72746341b78173b77797019d699edd..f6025af61b3470fdda7c43ff2e8feefbdfa373e1 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
 void sequence_copy(struct stream_pos *dest, const struct format *fdest, 
                   struct stream_pos *src, const struct format *fsrc,
@@ -36,7 +36,7 @@ void sequence_copy(struct stream_pos *dest, const struct format *fdest,
 
        for (i = 0; i < len; i++) {
                struct type_class *elem_class = sequence_class->elem;
-               elem_class->copy(dest, fdest, src, fsrc, &elem_class->p);
+               elem_class->copy(dest, fdest, src, fsrc, elem_class);
        }
        fsrc->sequence_end(src, sequence_class);
        fdest->sequence_end(dest, sequence_class);
@@ -44,13 +44,15 @@ void sequence_copy(struct stream_pos *dest, const struct format *fdest,
 
 void sequence_type_free(struct type_class_sequence *sequence_class)
 {
-       sequence_class->elem->free(&sequence_class->elem->p);
+       sequence_class->elem->free(sequence_class->elem);
+       type_unref(&sequence_class->len_class->p);
+       type_unref(sequence_class->elem);
        g_free(sequence_class);
 }
 
 static void _sequence_type_free(struct type_class *type_class)
 {
-       struct type_class_struct *sequence_class =
+       struct type_class_sequence *sequence_class =
                container_of(type_class, struct type_class_sequence, p);
        sequence_type_free(sequence_class);
 }
@@ -60,19 +62,24 @@ sequence_type_new(const char *name, struct type_class_integer *len_class,
                  struct type_class *elem)
 {
        struct type_class_sequence *sequence_class;
+       struct type_class *type_class;
        int ret;
 
        sequence_class = g_new(struct type_class_sequence, 1);
-       type_class = &float_class->p;
+       type_class = &sequence_class->p;
 
        assert(!len_class->signedness);
 
-       sequence_class->len = len;
+       type_ref(&len_class->p);
+       sequence_class->len_class = len_class;
+       type_ref(elem);
+       sequence_class->elem = elem;
        type_class->name = g_quark_from_string(name);
        type_class->alignment = max(len_class->p.alignment,
-                                   elem->p.alignment);
+                                   elem->alignment);
        type_class->copy = sequence_copy;
        type_class->free = _sequence_type_free;
+       type_class->ref = 1;
 
        if (type_class->name) {
                ret = ctf_register_type(type_class);
@@ -82,8 +89,8 @@ sequence_type_new(const char *name, struct type_class_integer *len_class,
        return sequence_class;
 
 error_register:
-       len_class->p.free(&len_class->p);
-       sequence_class->elem->free(&sequence_class->elem->p);
+       type_unref(&len_class->p);
+       type_unref(elem);
        g_free(sequence_class);
        return NULL;
 }
index 4d57914112fe3a7aceeed0abda1621168e8d22f5..f81c1a7e62904ecb8339986181b50cd93d60da58 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
 void string_copy(struct stream_pos *dest, const struct format *fdest, 
                 struct stream_pos *src, const struct format *fsrc,
@@ -60,6 +60,7 @@ struct type_class_string *string_type_new(const char *name)
        string_class->p.alignment = CHAR_BIT;
        string_class->p.copy = string_copy;
        string_class->p.free = _string_type_free;
+       string_class->p.ref = 1;
        if (string_class->p.name) {
                ret = ctf_register_type(&string_class->p);
                if (ret) {
index 3bbb8409230ff26afd0653cc40b909d112994f81..a1bfbf431055539b610791c221144c4dec6da4e4 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
 void struct_copy(struct stream_pos *dest, const struct format *fdest, 
                 struct stream_pos *src, const struct format *fsrc,
@@ -35,7 +35,7 @@ void struct_copy(struct stream_pos *dest, const struct format *fdest,
                                                     struct field, i);
                struct type_class *field_class = field->type_class;
 
-               field_class->copy(dest, fdest, src, fsrc, &field_class->p);
+               field_class->copy(dest, fdest, src, fsrc, field_class);
 
        }
        fsrc->struct_end(src, struct_class);
@@ -44,7 +44,15 @@ void struct_copy(struct stream_pos *dest, const struct format *fdest,
 
 void struct_type_free(struct type_class_struct *struct_class)
 {
+       unsigned int i;
+
        g_hash_table_destroy(struct_class->fields_by_name);
+
+       for (i = 0; i < struct_class->fields->len; i++) {
+               struct field *field = &g_array_index(struct_class->fields,
+                                                    struct field, i);
+               type_unref(field->type_class);
+       }
        g_array_free(struct_class->fields, true);
        g_free(struct_class);
 }
@@ -59,20 +67,22 @@ static void _struct_type_free(struct type_class *type_class)
 struct type_class_struct *struct_type_new(const char *name)
 {
        struct type_class_struct *struct_class;
+       struct type_class *type_class;
        int ret;
 
        struct_class = g_new(struct type_class_struct, 1);
-       type_class = &float_class->p;
+       type_class = &struct_class->p;
 
        struct_class->fields_by_name = g_hash_table_new(g_direct_hash,
                                                        g_direct_equal);
        struct_class->fields = g_array_sized_new(false, false,
                                                 sizeof(struct field),
-                                                DEFAULT_NR_STRUCT_FIELDS)
+                                                DEFAULT_NR_STRUCT_FIELDS);
        type_class->name = g_quark_from_string(name);
        type_class->alignment = 1;
        type_class->copy = struct_copy;
        type_class->free = _struct_type_free;
+       type_class->ref = 1;
 
        if (type_class->name) {
                ret = ctf_register_type(type_class);
@@ -97,6 +107,7 @@ void struct_type_add_field(struct type_class_struct *struct_class,
        index = struct_class->fields->len - 1;  /* last field (new) */
        field = &g_array_index(struct_class->fields, struct field, index);
        field->name = g_quark_from_string(field_name);
+       type_ref(type_class);
        field->type_class = type_class;
        /* Keep index in hash rather than pointer, because array can relocate */
        g_hash_table_insert(struct_class->fields_by_name,
@@ -117,7 +128,7 @@ struct_type_lookup_field_index(struct type_class_struct *struct_class,
        unsigned long index;
 
        index = (unsigned long) g_hash_table_lookup(struct_class->fields_by_name,
-                                                   field_name);
+                                                   (gconstpointer) (unsigned long) field_name);
        return index;
 }
 
index 91d6b211d118acaafe50a0a9f29bc5f1b12de329..fbd1ed50bb26b621ce06c852bef68a8f6bcf434a 100644 (file)
@@ -18,7 +18,7 @@
  * all copies or substantial portions of the Software.
  */
 
-#include <ctf/ctf-types.h>
+#include <babeltrace/format.h>
 #include <glib.h>
 #include <errno.h>
 
  * performed by a type plugin.
  * TODO: support plugin unload (unregistration of types).
  */
-GHashTable *types;
+GHashTable *type_classes;
 
-struct type_class *ctf_lookup_type(GQuark qname)
+struct type_class *lookup_type(GQuark qname)
 {
        return g_hash_table_lookup(type_classes,
-                                  (gconstpointer) (unsigned long) qname)
+                                  (gconstpointer) (unsigned long) qname);
 }
 
 static void free_type(struct type_class *type_class)
@@ -40,27 +40,38 @@ static void free_type(struct type_class *type_class)
        type_class->free(type_class);
 }
 
-int ctf_register_type(struct type_class *type_class)
+int register_type(struct type_class *type_class)
 {
        if (ctf_lookup_type_class(type_class->name))
                return -EEXIST;
 
        g_hash_table_insert(type_classes,
-                           (gconstpointer) (unsigned long) type_class->name,
+                           (gpointer) (unsigned long) type_class->name,
                            type_class);
        return 0;
 }
 
-int ctf_init_types(void)
+void type_ref(struct type_class *type_class)
+{
+       type_class->ref++;
+}
+
+void type_unref(struct type_class *type_class)
+{
+       if (!--type_class->ref)
+               free_type(type_class);
+}
+
+int init_types(void)
 {
        type_classes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                                            NULL, free_type);
+                                            NULL, (GDestroyNotify) free_type);
        if (!type_classes)
                return -ENOMEM;
        return 0;
 }
 
-int ctf_finalize_types(void)
+int finalize_types(void)
 {
        g_hash_table_destroy(type_classes);
 }
This page took 0.072293 seconds and 4 git commands to generate.