Babeltrace-wide warning fixes
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 21 Feb 2011 22:33:08 +0000 (17:33 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 21 Feb 2011 22:33:08 +0000 (17:33 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/types/enum.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
formats/ctf/types/string.c
include/babeltrace/bitfield.h
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
tests/test-bitfield.c
types/enum.c
types/string.c

index a62d84e712ef6104802f3301197cdc85c859b3c8..e0bb545b72963b18fcb7f9c860c6309f00bfac25 100644 (file)
@@ -20,8 +20,8 @@
 #include <stdint.h>
 #include <glib.h>
 
 #include <stdint.h>
 #include <glib.h>
 
-GQuark ctf_enum_read(struct stream_pos *pos,
-                    const struct type_class_enum *src)
+GArray *ctf_enum_read(struct stream_pos *pos,
+                     const struct type_class_enum *src)
 {
        const struct type_class_integer *int_class = &src->p;
 
 {
        const struct type_class_integer *int_class = &src->p;
 
@@ -29,30 +29,33 @@ GQuark ctf_enum_read(struct stream_pos *pos,
                uint64_t v;
 
                v = ctf_uint_read(pos, int_class);
                uint64_t v;
 
                v = ctf_uint_read(pos, int_class);
-               return enum_uint_to_quark(src, v);
+               return enum_uint_to_quark_set(src, v);
        } else {
                int64_t v;
 
                v = ctf_int_read(pos, int_class);
        } else {
                int64_t v;
 
                v = ctf_int_read(pos, int_class);
-               return enum_int_to_quark(src, v);
+               return enum_int_to_quark_set(src, v);
        }
 }
 
        }
 }
 
+/*
+ * Arbitrarily choose the start of the first matching range.
+ */
 void ctf_enum_write(struct stream_pos *pos,
 void ctf_enum_write(struct stream_pos *pos,
-                     const struct type_class_enum *dest,
-                     GQuark q)
+                   const struct type_class_enum *dest,
+                   GQuark q)
 {
        const struct type_class_integer *int_class = &dest->p;
 {
        const struct type_class_integer *int_class = &dest->p;
+       GArray *array;
 
 
-       if (!int_class->signedness) {
-               uint64_t v;
+       array = enum_quark_to_range_set(dest, q);
+       assert(array);
 
 
-               v = enum_quark_to_uint(dest, q);
+       if (!int_class->signedness) {
+               uint64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
                ctf_uint_write(pos, int_class, v);
        } else {
                ctf_uint_write(pos, int_class, v);
        } else {
-               int64_t v;
-
-               v = enum_quark_to_int(dest, q);
+               int64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
                ctf_int_write(pos, int_class, v);
        }
 }
                ctf_int_write(pos, int_class, v);
        }
 }
index be068316eb9241084abd4b0e662d6f2acd1880a9..3651f0c3acf9c5338104ff1490489877e3967af9 100644 (file)
@@ -119,7 +119,7 @@ double ctf_double_read(struct stream_pos *srcp,
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
-       init_pos(&destp, (unsigned char *) u.bits);
+       init_pos(&destp, (char *) u.bits);
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
@@ -139,7 +139,7 @@ void ctf_double_write(struct stream_pos *destp,
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
-       init_pos(&srcp, (unsigned char *) u.bits);
+       init_pos(&srcp, (char *) u.bits);
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
@@ -156,7 +156,7 @@ long double ctf_ldouble_read(struct stream_pos *srcp,
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
        struct stream_pos destp;
 
        align_pos(srcp, float_class->p.alignment);
-       init_pos(&destp, (unsigned char *) u.bits);
+       init_pos(&destp, (char *) u.bits);
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
        _ctf_float_copy(&destp, dest_class, srcp, float_class);
        float_type_free(dest_class);
        return u.v;
@@ -176,7 +176,7 @@ void ctf_ldouble_write(struct stream_pos *destp,
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
 
        u.v = v;
        align_pos(destp, float_class->p.alignment);
-       init_pos(&srcp, (unsigned char *) u.bits);
+       init_pos(&srcp, (char *) u.bits);
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
        _ctf_float_copy(destp, float_class, &srcp, src_class);
        float_type_free(src_class);
 }
index e0de8052940349dbd5d1ff565b8badee08890b1b..127b8062bf6901240ad3c38d9f6082cae2cbdb71 100644 (file)
@@ -190,15 +190,15 @@ end:
 uint64_t ctf_uint_read(struct stream_pos *pos,
                        const struct type_class_integer *int_class)
 {
 uint64_t ctf_uint_read(struct stream_pos *pos,
                        const struct type_class_integer *int_class)
 {
-       uint64_t v;
+       uint64_t v = 0;
 
        align_pos(pos, int_class->p.alignment);
        if (int_class->byte_order == LITTLE_ENDIAN)
 
        align_pos(pos, int_class->p.alignment);
        if (int_class->byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_read_le(pos->base, pos->offset,
-                                    int_class->len, &v);
+               bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
+                                   int_class->len, &v);
        else
        else
-               ctf_bitfield_read_be(pos->base, pos->offset,
-                                    int_class->len, &v);
+               bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
+                                   int_class->len, &v);
        move_pos(pos, int_class->len);
        return v;
 }
        move_pos(pos, int_class->len);
        return v;
 }
@@ -206,15 +206,15 @@ uint64_t ctf_uint_read(struct stream_pos *pos,
 int64_t ctf_int_read(struct stream_pos *pos,
                        const struct type_class_integer *int_class)
 {
 int64_t ctf_int_read(struct stream_pos *pos,
                        const struct type_class_integer *int_class)
 {
-       int64_t v;
+       int64_t v = 0;
 
        align_pos(pos, int_class->p.alignment);
        if (int_class->byte_order == LITTLE_ENDIAN)
 
        align_pos(pos, int_class->p.alignment);
        if (int_class->byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_read_le(pos->base, pos->offset,
-                                    int_class->len, &v);
+               bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
+                                   int_class->len, &v);
        else
        else
-               ctf_bitfield_read_be(pos->base, pos->offset,
-                                    int_class->len, &v);
+               bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
+                                   int_class->len, &v);
        move_pos(pos, int_class->len);
        return v;
 }
        move_pos(pos, int_class->len);
        return v;
 }
@@ -227,11 +227,11 @@ void ctf_uint_write(struct stream_pos *pos,
        if (pos->dummy)
                goto end;
        if (int_class->byte_order == LITTLE_ENDIAN)
        if (pos->dummy)
                goto end;
        if (int_class->byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_write_le(pos->base, pos->offset,
-                                     int_class->len, v);
+               bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
+                                    int_class->len, v);
        else
        else
-               ctf_bitfield_write_be(pos->base, pos->offset,
-                                     int_class->len, v);
+               bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
+                                    int_class->len, v);
 end:
        move_pos(pos, int_class->len);
 }
 end:
        move_pos(pos, int_class->len);
 }
@@ -244,11 +244,11 @@ void ctf_int_write(struct stream_pos *pos,
        if (pos->dummy)
                goto end;
        if (int_class->byte_order == LITTLE_ENDIAN)
        if (pos->dummy)
                goto end;
        if (int_class->byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_write_le(pos->base, pos->offset,
-                                     int_class->len, v);
+               bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
+                                    int_class->len, v);
        else
        else
-               ctf_bitfield_write_be(pos->base, pos->offset,
-                                     int_class->len, v);
+               bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
+                                    int_class->len, v);
 end:
        move_pos(pos, int_class->len);
 }
 end:
        move_pos(pos, int_class->len);
 }
index fab69c4fa8833208c2f95d5d971a7764e9029ad9..95a81a30e76cd46929c7e16fb899625e0050f0ee 100644 (file)
@@ -24,7 +24,7 @@ void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
                     const struct type_class_string *string_class)
 {
        size_t len;
                     const struct type_class_string *string_class)
 {
        size_t len;
-       unsigned char *destaddr, *srcaddr;
+       char *destaddr, *srcaddr;
 
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
 
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
@@ -39,26 +39,25 @@ end:
        move_pos(src, len);
 }
 
        move_pos(src, len);
 }
 
-void ctf_string_read(unsigned char **dest, struct stream_pos *src,
+void ctf_string_read(char **dest, struct stream_pos *src,
                     const struct type_class_string *string_class)
 {
        size_t len;
                     const struct type_class_string *string_class)
 {
        size_t len;
-       unsigned char *srcaddr;
+       char *srcaddr;
 
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        *dest = g_realloc(*dest, len);
        strcpy(*dest, srcaddr);
 
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        *dest = g_realloc(*dest, len);
        strcpy(*dest, srcaddr);
-end:
        move_pos(src, len);
 }
 
        move_pos(src, len);
 }
 
-void ctf_string_write(struct stream_pos *dest, const unsigned char *src,
+void ctf_string_write(struct stream_pos *dest, const char *src,
                      const struct type_class_string *string_class)
 {
        size_t len;
                      const struct type_class_string *string_class)
 {
        size_t len;
-       unsigned char *destaddr;
+       char *destaddr;
 
        align_pos(dest, string_class->p.alignment);
        len = strlen(src) + 1;
 
        align_pos(dest, string_class->p.alignment);
        len = strlen(src) + 1;
@@ -70,7 +69,7 @@ end:
        move_pos(dest, len);
 }
 
        move_pos(dest, len);
 }
 
-void ctf_string_free_temp(unsigned char *string)
+void ctf_string_free_temp(char *string)
 {
        g_free(string);
 }
 {
        g_free(string);
 }
index 449923c2a801ae1569c9da8d42f943494269e44c..455650ed0e57c847e22162dc1087ec7b8a61c109 100644 (file)
  * Also, consecutive bitfields are placed from higher to lower bits.
  */
 
  * Also, consecutive bitfields are placed from higher to lower bits.
  */
 
-#define _bt_bitfield_write_le(ptr, _start, _length, _v)                        \
+#define _bt_bitfield_write_le(ptr, type, _start, _length, _v)          \
 do {                                                                   \
        typeof(_v) v = (_v);                                            \
 do {                                                                   \
        typeof(_v) v = (_v);                                            \
-       typeof(*(ptr)) mask, cmask;                                     \
-       unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
+       type mask, cmask;                                               \
+       unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */     \
        unsigned long start = (_start), length = (_length);             \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
        unsigned long start = (_start), length = (_length);             \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
@@ -97,10 +97,10 @@ do {                                                                        \
        /* We can now append v with a simple "or", shift it piece-wise */ \
        this_unit = start_unit;                                         \
        if (start_unit == end_unit - 1) {                               \
        /* We can now append v with a simple "or", shift it piece-wise */ \
        this_unit = start_unit;                                         \
        if (start_unit == end_unit - 1) {                               \
-               mask = ~((~(typeof(*(ptr))) 0) << (start % ts));        \
+               mask = ~((~(type) 0) << (start % ts));                  \
                if (end % ts)                                           \
                if (end % ts)                                           \
-                       mask |= (~(typeof(*(ptr))) 0) << (end % ts);    \
-               cmask = (typeof(*(ptr))) v << (start % ts);             \
+                       mask |= (~(type) 0) << (end % ts);              \
+               cmask = (type) v << (start % ts);                       \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
@@ -108,8 +108,8 @@ do {                                                                        \
        }                                                               \
        if (start % ts) {                                               \
                cshift = start % ts;                                    \
        }                                                               \
        if (start % ts) {                                               \
                cshift = start % ts;                                    \
-               mask = ~((~(typeof(*(ptr))) 0) << cshift);              \
-               cmask = (typeof(*(ptr))) v << cshift;                   \
+               mask = ~((~(type) 0) << cshift);                        \
+               cmask = (type) v << cshift;                             \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
@@ -118,26 +118,26 @@ do {                                                                      \
                this_unit++;                                            \
        }                                                               \
        for (; this_unit < end_unit - 1; this_unit++) {                 \
                this_unit++;                                            \
        }                                                               \
        for (; this_unit < end_unit - 1; this_unit++) {                 \
-               (ptr)[this_unit] = (typeof(*(ptr))) v;                  \
+               (ptr)[this_unit] = (type) v;                            \
                v = _bt_piecewise_rshift(v, ts);                        \
                start += ts;                                            \
        }                                                               \
        if (end % ts) {                                                 \
                v = _bt_piecewise_rshift(v, ts);                        \
                start += ts;                                            \
        }                                                               \
        if (end % ts) {                                                 \
-               mask = (~(typeof(*(ptr))) 0) << (end % ts);             \
-               cmask = (typeof(*(ptr))) v;                             \
+               mask = (~(type) 0) << (end % ts);                       \
+               cmask = (type) v;                                       \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
        } else                                                          \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
        } else                                                          \
-               (ptr)[this_unit] = (typeof(*(ptr))) v;                  \
+               (ptr)[this_unit] = (type) v;                            \
 } while (0)
 
 } while (0)
 
-#define _bt_bitfield_write_be(ptr, _start, _length, _v)                        \
+#define _bt_bitfield_write_be(ptr, type, _start, _length, _v)          \
 do {                                                                   \
        typeof(_v) v = (_v);                                            \
 do {                                                                   \
        typeof(_v) v = (_v);                                            \
-       typeof(*(ptr)) mask, cmask;                                     \
-       unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
-       unsigned long start = _start, length = _length;                 \
+       type mask, cmask;                                               \
+       unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */     \
+       unsigned long start = (_start), length = (_length);             \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
@@ -155,10 +155,10 @@ do {                                                                      \
        /* We can now append v with a simple "or", shift it piece-wise */ \
        this_unit = end_unit - 1;                                       \
        if (start_unit == end_unit - 1) {                               \
        /* We can now append v with a simple "or", shift it piece-wise */ \
        this_unit = end_unit - 1;                                       \
        if (start_unit == end_unit - 1) {                               \
-               mask = ~((~(typeof(*(ptr))) 0) << ((ts - (end % ts)) % ts)); \
+               mask = ~((~(type) 0) << ((ts - (end % ts)) % ts));      \
                if (start % ts)                                         \
                if (start % ts)                                         \
-                       mask |= (~((typeof(*(ptr))) 0)) << (ts - (start % ts)); \
-               cmask = (typeof(*(ptr))) v << ((ts - (end % ts)) % ts); \
+                       mask |= (~((type) 0)) << (ts - (start % ts));   \
+               cmask = (type) v << ((ts - (end % ts)) % ts);           \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
@@ -166,8 +166,8 @@ do {                                                                        \
        }                                                               \
        if (end % ts) {                                                 \
                cshift = end % ts;                                      \
        }                                                               \
        if (end % ts) {                                                 \
                cshift = end % ts;                                      \
-               mask = ~((~(typeof(*(ptr))) 0) << (ts - cshift));       \
-               cmask = (typeof(*(ptr))) v << (ts - cshift);            \
+               mask = ~((~(type) 0) << (ts - cshift));                 \
+               cmask = (type) v << (ts - cshift);                      \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
@@ -176,18 +176,18 @@ do {                                                                      \
                this_unit--;                                            \
        }                                                               \
        for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
                this_unit--;                                            \
        }                                                               \
        for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
-               (ptr)[this_unit] = (typeof(*(ptr))) v;                  \
+               (ptr)[this_unit] = (type) v;                            \
                v = _bt_piecewise_rshift(v, ts);                        \
                end -= ts;                                              \
        }                                                               \
        if (start % ts) {                                               \
                v = _bt_piecewise_rshift(v, ts);                        \
                end -= ts;                                              \
        }                                                               \
        if (start % ts) {                                               \
-               mask = (~(typeof(*(ptr))) 0) << (ts - (start % ts));    \
-               cmask = (typeof(*(ptr))) v;                             \
+               mask = (~(type) 0) << (ts - (start % ts));              \
+               cmask = (type) v;                                       \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
        } else                                                          \
                cmask &= ~mask;                                         \
                (ptr)[this_unit] &= mask;                               \
                (ptr)[this_unit] |= cmask;                              \
        } else                                                          \
-               (ptr)[this_unit] = (typeof(*(ptr))) v;                  \
+               (ptr)[this_unit] = (type) v;                            \
 } while (0)
 
 /*
 } while (0)
 
 /*
@@ -198,25 +198,25 @@ do {                                                                      \
 
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 
 
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 
-#define bt_bitfield_write(ptr, _start, _length, _v)                    \
-       _bt_bitfield_write_le(ptr, _start, _length, _v)
+#define bt_bitfield_write(ptr, type, _start, _length, _v)              \
+       _bt_bitfield_write_le(ptr, type, _start, _length, _v)
 
 
-#define bt_bitfield_write_le(ptr, _start, _length, _v)                 \
-       _bt_bitfield_write_le(ptr, _start, _length, _v)
+#define bt_bitfield_write_le(ptr, type, _start, _length, _v)           \
+       _bt_bitfield_write_le(ptr, type, _start, _length, _v)
        
        
-#define bt_bitfield_write_be(ptr, _start, _length, _v)                 \
-       _bt_bitfield_write_be((unsigned char *) (ptr), _start, _length, _v)
+#define bt_bitfield_write_be(ptr, type, _start, _length, _v)           \
+       _bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v)
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
-#define bt_bitfield_write(ptr, _start, _length, _v)                    \
-       _bt_bitfield_write_be(ptr, _start, _length, _v)
+#define bt_bitfield_write(ptr, type, _start, _length, _v)              \
+       _bt_bitfield_write_be(ptr, type, _start, _length, _v)
 
 
-#define bt_bitfield_write_le(ptr, _start, _length, _v)                 \
-       _bt_bitfield_write_le((unsigned char *) (ptr), _start, _length, _v)
+#define bt_bitfield_write_le(ptr, type, _start, _length, _v)           \
+       _bt_bitfield_write_le(ptr, unsigned char, _start, _length, _v)
        
        
-#define bt_bitfield_write_be(ptr, _start, _length, _v)                 \
-       _bt_bitfield_write_be(ptr, _start, _length, _v)
+#define bt_bitfield_write_be(ptr, type, _start, _length, _v)           \
+       _bt_bitfield_write_be(ptr, type, _start, _length, _v)
 
 #else /* (BYTE_ORDER == PDP_ENDIAN) */
 
 
 #else /* (BYTE_ORDER == PDP_ENDIAN) */
 
@@ -224,12 +224,12 @@ do {                                                                      \
 
 #endif
 
 
 #endif
 
-#define _bt_bitfield_read_le(ptr, _start, _length, vptr)               \
+#define _bt_bitfield_read_le(ptr, type, _start, _length, vptr)         \
 do {                                                                   \
        typeof(*(vptr)) v;                                              \
 do {                                                                   \
        typeof(*(vptr)) v;                                              \
-       typeof(*(ptr)) mask, cmask;                                     \
-       unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
-       unsigned long start = _start, length = _length;                 \
+       type mask, cmask;                                               \
+       unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */     \
+       unsigned long start = (_start), length = (_length);             \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
@@ -244,7 +244,7 @@ do {                                                                        \
                                                                        \
        this_unit = end_unit - 1;                                       \
        if (_bt_is_signed_type(typeof(v))                               \
                                                                        \
        this_unit = end_unit - 1;                                       \
        if (_bt_is_signed_type(typeof(v))                               \
-           && ((ptr)[this_unit] & ((typeof(*(ptr))) 1 << ((end % ts ? : ts) - 1)))) \
+           && ((ptr)[this_unit] & ((type) 1 << ((end % ts ? : ts) - 1)))) \
                v = ~(typeof(v)) 0;                                     \
        else                                                            \
                v = 0;                                                  \
                v = ~(typeof(v)) 0;                                     \
        else                                                            \
                v = 0;                                                  \
@@ -252,7 +252,7 @@ do {                                                                        \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (start % ts);                                 \
                if ((end - start) % ts) {                               \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (start % ts);                                 \
                if ((end - start) % ts) {                               \
-                       mask = ~((~(typeof(*(ptr))) 0) << (end - start)); \
+                       mask = ~((~(type) 0) << (end - start));         \
                        cmask &= mask;                                  \
                }                                                       \
                v = _bt_piecewise_lshift(v, end - start);               \
                        cmask &= mask;                                  \
                }                                                       \
                v = _bt_piecewise_lshift(v, end - start);               \
@@ -262,7 +262,7 @@ do {                                                                        \
        }                                                               \
        if (end % ts) {                                                 \
                cshift = end % ts;                                      \
        }                                                               \
        if (end % ts) {                                                 \
                cshift = end % ts;                                      \
-               mask = ~((~(typeof(*(ptr))) 0) << cshift);              \
+               mask = ~((~(type) 0) << cshift);                        \
                cmask = (ptr)[this_unit];                               \
                cmask &= mask;                                          \
                v = _bt_piecewise_lshift(v, cshift);                    \
                cmask = (ptr)[this_unit];                               \
                cmask &= mask;                                          \
                v = _bt_piecewise_lshift(v, cshift);                    \
@@ -276,7 +276,7 @@ do {                                                                        \
                end -= ts;                                              \
        }                                                               \
        if (start % ts) {                                               \
                end -= ts;                                              \
        }                                                               \
        if (start % ts) {                                               \
-               mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \
+               mask = ~((~(type) 0) << (ts - (start % ts)));           \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (start % ts);                                 \
                cmask &= mask;                                          \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (start % ts);                                 \
                cmask &= mask;                                          \
@@ -289,12 +289,12 @@ do {                                                                      \
        *(vptr) = v;                                                    \
 } while (0)
 
        *(vptr) = v;                                                    \
 } while (0)
 
-#define _bt_bitfield_read_be(ptr, _start, _length, vptr)               \
+#define _bt_bitfield_read_be(ptr, type, _start, _length, vptr)         \
 do {                                                                   \
        typeof(*(vptr)) v;                                              \
 do {                                                                   \
        typeof(*(vptr)) v;                                              \
-       typeof(*(ptr)) mask, cmask;                                     \
-       unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
-       unsigned long start = _start, length = _length;                 \
+       type mask, cmask;                                               \
+       unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */     \
+       unsigned long start = (_start), length = (_length);             \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
        unsigned long start_unit, end_unit, this_unit;                  \
        unsigned long end, cshift; /* cshift is "complement shift" */   \
                                                                        \
@@ -309,7 +309,7 @@ do {                                                                        \
                                                                        \
        this_unit = start_unit;                                         \
        if (_bt_is_signed_type(typeof(v))                               \
                                                                        \
        this_unit = start_unit;                                         \
        if (_bt_is_signed_type(typeof(v))                               \
-           && ((ptr)[this_unit] & ((typeof(*(ptr))) 1 << (ts - (start % ts) - 1)))) \
+           && ((ptr)[this_unit] & ((type) 1 << (ts - (start % ts) - 1)))) \
                v = ~(typeof(v)) 0;                                     \
        else                                                            \
                v = 0;                                                  \
                v = ~(typeof(v)) 0;                                     \
        else                                                            \
                v = 0;                                                  \
@@ -317,7 +317,7 @@ do {                                                                        \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (ts - (end % ts)) % ts;                       \
                if ((end - start) % ts) {                               \
                cmask = (ptr)[this_unit];                               \
                cmask >>= (ts - (end % ts)) % ts;                       \
                if ((end - start) % ts) {                               \
-                       mask = ~((~(typeof(*(ptr))) 0) << (end - start)); \
+                       mask = ~((~(type) 0) << (end - start));         \
                        cmask &= mask;                                  \
                }                                                       \
                v = _bt_piecewise_lshift(v, end - start);               \
                        cmask &= mask;                                  \
                }                                                       \
                v = _bt_piecewise_lshift(v, end - start);               \
@@ -326,12 +326,13 @@ do {                                                                      \
                break;                                                  \
        }                                                               \
        if (start % ts) {                                               \
                break;                                                  \
        }                                                               \
        if (start % ts) {                                               \
-               mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \
+               cshift = start % ts;                                    \
+               mask = ~((~(type) 0) << (ts - cshift));                 \
                cmask = (ptr)[this_unit];                               \
                cmask &= mask;                                          \
                cmask = (ptr)[this_unit];                               \
                cmask &= mask;                                          \
-               v = _bt_piecewise_lshift(v, ts - (start % ts));         \
+               v = _bt_piecewise_lshift(v, ts - cshift);               \
                v |= _bt_unsigned_cast(typeof(v), cmask);               \
                v |= _bt_unsigned_cast(typeof(v), cmask);               \
-               start += ts - (start % ts);                             \
+               start += ts - cshift;                                   \
                this_unit++;                                            \
        }                                                               \
        for (; this_unit < end_unit - 1; this_unit++) {                 \
                this_unit++;                                            \
        }                                                               \
        for (; this_unit < end_unit - 1; this_unit++) {                 \
@@ -340,7 +341,7 @@ do {                                                                        \
                start += ts;                                            \
        }                                                               \
        if (end % ts) {                                                 \
                start += ts;                                            \
        }                                                               \
        if (end % ts) {                                                 \
-               mask = ~((~(typeof(*(ptr))) 0) << (end % ts));          \
+               mask = ~((~(type) 0) << (end % ts));                    \
                cmask = (ptr)[this_unit];                               \
                cmask >>= ts - (end % ts);                              \
                cmask &= mask;                                          \
                cmask = (ptr)[this_unit];                               \
                cmask >>= ts - (end % ts);                              \
                cmask &= mask;                                          \
@@ -361,25 +362,25 @@ do {                                                                      \
 
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 
 
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 
-#define bt_bitfield_read(ptr, _start, _length, _vptr)                  \
-       _bt_bitfield_read_le(ptr, _start, _length, _vptr)
+#define bt_bitfield_read(ptr, type, _start, _length, _vptr)            \
+       _bt_bitfield_read_le(ptr, type, _start, _length, _vptr)
 
 
-#define bt_bitfield_read_le(ptr, _start, _length, _vptr)               \
-       _bt_bitfield_read_le(ptr, _start, _length, _vptr)
+#define bt_bitfield_read_le(ptr, type, _start, _length, _vptr)         \
+       _bt_bitfield_read_le(ptr, type, _start, _length, _vptr)
        
        
-#define bt_bitfield_read_be(ptr, _start, _length, _vptr)               \
-       _bt_bitfield_read_be((const unsigned char *) (ptr), _start, _length, _vptr)
+#define bt_bitfield_read_be(ptr, type, _start, _length, _vptr)         \
+       _bt_bitfield_read_be(ptr, unsigned char, _start, _length, _vptr)
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
-#define bt_bitfield_read(ptr, _start, _length, _vptr)                  \
-       _bt_bitfield_read_be(ptr, _start, _length, _vptr)
+#define bt_bitfield_read(ptr, type, _start, _length, _vptr)            \
+       _bt_bitfield_read_be(ptr, type, _start, _length, _vptr)
 
 
-#define bt_bitfield_read_le(ptr, _start, _length, _vptr)               \
-       _bt_bitfield_read_le((const unsigned char *) (ptr), _start, _length, _vptr)
+#define bt_bitfield_read_le(ptr, type, _start, _length, _vptr)         \
+       _bt_bitfield_read_le(ptr, unsigned char, _start, _length, _vptr)
        
        
-#define bt_bitfield_read_be(ptr, _start, _length, _vptr)               \
-       _bt_bitfield_read_be(ptr, _start, _length, _vptr)
+#define bt_bitfield_read_be(ptr, type, _start, _length, _vptr)         \
+       _bt_bitfield_read_be(ptr, type, _start, _length, _vptr)
 
 #else /* (BYTE_ORDER == PDP_ENDIAN) */
 
 
 #else /* (BYTE_ORDER == PDP_ENDIAN) */
 
index a2ccca680d16bd2d0d094a0d97dba19848ead1da..c5ce9d2bddeb39676aa8a0c26bd44fd6be0207c2 100644 (file)
@@ -59,14 +59,14 @@ void ctf_float_copy(struct stream_pos *destp,
 
 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
                     const struct type_class_string *string_class);
 
 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
                     const struct type_class_string *string_class);
-void ctf_string_read(unsigned char **dest, struct stream_pos *src,
+void ctf_string_read(char **dest, struct stream_pos *src,
                     const struct type_class_string *string_class);
                     const struct type_class_string *string_class);
-void ctf_string_write(struct stream_pos *dest, const unsigned char *src,
+void ctf_string_write(struct stream_pos *dest, const char *src,
                      const struct type_class_string *string_class);
                      const struct type_class_string *string_class);
-void ctf_string_free_temp(unsigned char *string);
+void ctf_string_free_temp(char *string);
 
 
-GQuark ctf_enum_read(struct stream_pos *pos,
-               const struct type_class_enum *src);
+GArray *ctf_enum_read(struct stream_pos *pos,
+                     const struct type_class_enum *src);
 void ctf_enum_write(struct stream_pos *pos,
                const struct type_class_enum *dest,
                GQuark q);
 void ctf_enum_write(struct stream_pos *pos,
                const struct type_class_enum *dest,
                GQuark q);
index c6dedc1afbd14279054708add6d766e6a5cd4c76..b9c3e9fb0b029845ae280260d454a558cb070e1b 100644 (file)
@@ -48,13 +48,17 @@ struct format {
 
        void (*string_copy)(struct stream_pos *dest, struct stream_pos *src,
                            const struct type_class_string *string_class);
 
        void (*string_copy)(struct stream_pos *dest, struct stream_pos *src,
                            const struct type_class_string *string_class);
-       void (*string_read)(unsigned char **dest, struct stream_pos *src,
+       void (*string_read)(char **dest, struct stream_pos *src,
                            const struct type_class_string *string_class);
                            const struct type_class_string *string_class);
-       void (*string_write)(struct stream_pos *dest, const unsigned char *src,
+       void (*string_write)(struct stream_pos *dest, const char *src,
                             const struct type_class_string *string_class);
                             const struct type_class_string *string_class);
-       void (*string_free_temp)(unsigned char *string);
+       void (*string_free_temp)(char *string);
 
 
-       GQuark (*enum_read)(struct stream_pos *pos,
+       /*
+        * enum_read returns a GArray of GQuark. Must be released with
+        * g_array_unref().
+        */
+       GArray *(*enum_read)(struct stream_pos *pos,
                            const struct type_class_enum *src);
        void (*enum_write)(struct stream_pos *pos,
                           const struct type_class_enum *dest,
                            const struct type_class_enum *src);
        void (*enum_write)(struct stream_pos *pos,
                           const struct type_class_enum *dest,
index 9a425ae2b5738758642256d1b43a64785cad5c08..d6ac792438bf5573b6f4eb103687e43370656614 100644 (file)
  * Always update stream_pos with move_pos and init_pos.
  */
 struct stream_pos {
  * Always update stream_pos with move_pos and init_pos.
  */
 struct stream_pos {
-       unsigned char *base;    /* Base address */
+       char *base;             /* Base address */
        size_t offset;          /* Offset from base, in bits */
        int dummy;              /* Dummy position, for length calculation */
 };
 
 static inline
        size_t offset;          /* Offset from base, in bits */
        int dummy;              /* Dummy position, for length calculation */
 };
 
 static inline
-void init_pos(struct stream_pos *pos, unsigned char *base)
+void init_pos(struct stream_pos *pos, char *base)
 {
        pos->base = base;       /* initial base, page-aligned */
        pos->offset = 0;
 {
        pos->base = base;       /* initial base, page-aligned */
        pos->offset = 0;
@@ -77,7 +77,7 @@ void copy_pos(struct stream_pos *dest, struct stream_pos *src)
 }
 
 static inline
 }
 
 static inline
-unsigned char *get_pos_addr(struct stream_pos *pos)
+char *get_pos_addr(struct stream_pos *pos)
 {
        /* Only makes sense to get the address after aligning on CHAR_BIT */
        assert(!(pos->offset % CHAR_BIT));
 {
        /* Only makes sense to get the address after aligning on CHAR_BIT */
        assert(!(pos->offset % CHAR_BIT));
@@ -219,15 +219,25 @@ 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().
  */
  * A GQuark can be translated to/from strings with g_quark_from_string() and
  * g_quark_to_string().
  */
+
+/*
+ * Returns a GArray of GQuark or NULL.
+ * Caller must release the GArray with g_array_unref().
+ */
 GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class,
                               uint64_t v);
 
 /*
 GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class,
                               uint64_t v);
 
 /*
- * Returns a GArray or NULL.
+ * Returns a GArray of GQuark or NULL.
  * Caller must release the GArray with g_array_unref().
  */
 GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class,
                              uint64_t v);
  * Caller must release the GArray with g_array_unref().
  */
 GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class,
                              uint64_t v);
+
+/*
+ * Returns a GArray of struct enum_range or NULL.
+ * Caller must release the GArray with g_array_unref().
+ */
 GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
                                GQuark q);
 void enum_signed_insert(struct type_class_enum *enum_class,
 GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
                                GQuark q);
 void enum_signed_insert(struct type_class_enum *enum_class,
index f8b63853452f8641eedfa36d01ecd365a926c96d..045b7d9484760a0ccaff29d46714f70f35872761 100644 (file)
@@ -22,6 +22,8 @@
 
 #define _GNU_SOURCE
 #include <babeltrace/bitfield.h>
 
 #define _GNU_SOURCE
 #include <babeltrace/bitfield.h>
+#include <time.h>
+#include <stdlib.h>
 #include <stdio.h>
 
 unsigned int glob;
 #include <stdio.h>
 
 unsigned int glob;
@@ -32,7 +34,7 @@ unsigned int glob;
  */
 void fct(void)
 {
  */
 void fct(void)
 {
-       bt_bitfield_write(&glob, 12, 15, 0x12345678);
+       bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678);
 }
 
 /* Test array size, in bytes */
 }
 
 /* Test array size, in bytes */
@@ -95,31 +97,29 @@ static int fls(unsigned int x)
 
 #endif
 
 
 #endif
 
-static void print_byte_array(const unsigned char *c, unsigned long len)
-{
-       unsigned long i;
-
-       for (i = 0; i < len; i++) {
-               printf("0x%X", c[i]);
-               if (i != len - 1)
-                       printf(" ");
-       }
-       printf("\n");
-}
-
-static void init_byte_array(unsigned char *c,
-                           unsigned long len,
-                           unsigned char val)
-{
-       unsigned long i;
-
-       for (i = 0; i < len; i++)
-               c[i] = val;
-}
+#define print_byte_array(c, len)       \
+do {                                   \
+       unsigned long i;                \
+                                       \
+       for (i = 0; i < (len); i++) {   \
+               printf("0x%X", (c)[i]); \
+               if (i != (len) - 1)     \
+                       printf(" ");    \
+       }                               \
+       printf("\n");                   \
+} while (0)
+
+#define init_byte_array(c, len, val)   \
+do {                                   \
+       unsigned long i;                \
+                                       \
+       for (i = 0; i < (len); i++)     \
+               (c)[i] = (val);         \
+} while (0)
 
 int run_test_unsigned(void)
 {
 
 int run_test_unsigned(void)
 {
-       unsigned int src, nrbits;
+       unsigned long src, nrbits;
        union {
                unsigned char c[TEST_LEN];
                unsigned short s[TEST_LEN/sizeof(unsigned short)];
        union {
                unsigned char c[TEST_LEN];
                unsigned short s[TEST_LEN/sizeof(unsigned short)];
@@ -139,8 +139,8 @@ int run_test_unsigned(void)
        for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
                for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
                        init_byte_array(target.c, TEST_LEN, 0xFF);
        for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
                for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
                        init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.c, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.c, unsigned char, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -149,8 +149,8 @@ int run_test_unsigned(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.s, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.s, unsigned short, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -159,8 +159,8 @@ int run_test_unsigned(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.i, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.i, unsigned int, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (intwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (intwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -169,8 +169,8 @@ int run_test_unsigned(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.l, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.l, unsigned long, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (longwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (longwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -179,8 +179,8 @@ int run_test_unsigned(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.ll, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.ll, unsigned long long, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -198,9 +198,9 @@ int run_test_unsigned(void)
 
 int run_test_signed(void)
 {
 
 int run_test_signed(void)
 {
-       int src, nrbits;
+       long src, nrbits;
        union {
        union {
-               char c[TEST_LEN];
+               signed char c[TEST_LEN];
                short s[TEST_LEN/sizeof(short)];
                int i[TEST_LEN/sizeof(int)];
                long l[TEST_LEN/sizeof(long)];
                short s[TEST_LEN/sizeof(short)];
                int i[TEST_LEN/sizeof(int)];
                long l[TEST_LEN/sizeof(long)];
@@ -221,8 +221,8 @@ int run_test_signed(void)
        for (s = 0; s < 8 * TEST_LEN; s++) {
                for (l = nrbits; l < (8 * TEST_LEN) - s; l++) {
                        init_byte_array(target.c, TEST_LEN, 0x0);
        for (s = 0; s < 8 * TEST_LEN; s++) {
                for (l = nrbits; l < (8 * TEST_LEN) - s; l++) {
                        init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.c, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.c, signed char, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -231,8 +231,8 @@ int run_test_signed(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.s, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.s, short, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -241,8 +241,8 @@ int run_test_signed(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.i, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.i, int, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (intwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (intwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -251,8 +251,8 @@ int run_test_signed(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.l, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.l, long, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (longwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (longwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -261,8 +261,8 @@ int run_test_signed(void)
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
                        }
 
                        init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.ll, s, l, src);
-                       bt_bitfield_read(target.c, s, l, &readval);
+                       bt_bitfield_write(target.ll, long long, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
                        if (readval != src) {
                                printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
                        if (readval != src) {
                                printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
                                       src, readval, s, l);
@@ -335,35 +335,35 @@ int main(int argc, char **argv)
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.c, shift, len, src);
+       bt_bitfield_write(target.c, unsigned char, shift, len, src);
        printf("bytewise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
        printf("bytewise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.s, shift, len, src);
+       bt_bitfield_write(target.s, unsigned short, shift, len, src);
        printf("shortwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
        printf("shortwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.i, shift, len, src);
+       bt_bitfield_write(target.i, unsigned int, shift, len, src);
        printf("intwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
        printf("intwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.l, shift, len, src);
+       bt_bitfield_write(target.l, unsigned long, shift, len, src);
        printf("longwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
        printf("longwise\n");
        print_byte_array(target.c, 8);
 
        target.i[0] = 0xFFFFFFFF;
        target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.ll, shift, len, src);
+       bt_bitfield_write(target.ll, unsigned long long, shift, len, src);
        printf("lluwise\n");
        print_byte_array(target.c, 8);
 
        printf("lluwise\n");
        print_byte_array(target.c, 8);
 
-       bt_bitfield_read(target.c, shift, len, &readval);
+       bt_bitfield_read(target.c, unsigned char, shift, len, &readval);
        printf("read: %llX\n", readval);
 
        ret = run_test();
        printf("read: %llX\n", readval);
 
        ret = run_test();
index bfed769de4889cb8e55bc6c80ccc9ffd3c645cc7..daf135076e00f1684dcb47bba611affc57cbbfc2 100644 (file)
@@ -233,9 +233,8 @@ void enum_unsigned_insert_value_to_quark_set(struct type_class_enum *enum_class,
 GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
                                GQuark q)
 {
 GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class,
                                GQuark q)
 {
-       gconstpointer v = g_hash_table_lookup(enum_class->table.quark_to_range_set,
-                                             (gconstpointer) (unsigned long) q);
-       return (GArray *) v;
+       return g_hash_table_lookup(enum_class->table.quark_to_range_set,
+                                  (gconstpointer) (unsigned long) q);
 }
 
 static
 }
 
 static
@@ -339,9 +338,17 @@ void enum_copy(struct stream_pos *dest, const struct format *fdest,
 {
        struct type_class_enum *enum_class =
                container_of(type_class, struct type_class_enum, p.p);
 {
        struct type_class_enum *enum_class =
                container_of(type_class, struct type_class_enum, p.p);
+       GArray *array;
        GQuark v;
 
        GQuark v;
 
-       v = fsrc->enum_read(src, enum_class);
+       array = fsrc->enum_read(src, enum_class);
+       assert(array);
+       /*
+        * Arbitrarily choose the first one.
+        * TODO: use direct underlying type read/write intead. Not doing it for
+        * now to test enum read and write code.
+        */
+       v = g_array_index(array, GQuark, 0);
        return fdest->enum_write(dest, enum_class, v);
 }
 
        return fdest->enum_write(dest, enum_class, v);
 }
 
index d38d3cf33b45a24920a1114e1555d0521f73bc00..ab0ec72c30da53209355a229bf35aaefbd60867e 100644 (file)
@@ -30,7 +30,7 @@ void string_copy(struct stream_pos *dest, const struct format *fdest,
        if (fsrc->string_copy == fdest->string_copy) {
                fsrc->string_copy(dest, src, string_class);
        } else {
        if (fsrc->string_copy == fdest->string_copy) {
                fsrc->string_copy(dest, src, string_class);
        } else {
-               unsigned char *tmp = NULL;
+               char *tmp = NULL;
 
                fsrc->string_read(&tmp, src, string_class);
                fdest->string_write(dest, tmp, string_class);
 
                fsrc->string_read(&tmp, src, string_class);
                fdest->string_write(dest, tmp, string_class);
This page took 0.051957 seconds and 4 git commands to generate.