String type: complete migration to bitwise position
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 3 Oct 2010 14:58:49 +0000 (10:58 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 3 Oct 2010 14:58:49 +0000 (10:58 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/types/string.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h
types/string.c

index 017d0e058b97a5a8b06c82c14b04ea2dfdd5ec11..9a0e003a2fa3e5081ca331cad3c533c7223706af 100644 (file)
@@ -38,6 +38,9 @@ static const struct format ctf_format = {
        .double_write = ctf_double_write,
        .float_copy = ctf_float_copy,
        .string_copy = ctf_string_copy,
+       .string_read = ctf_string_read,
+       .string_write = ctf_string_write,
+       .string_free_temp = ctf_string_free_temp,
        .enum_read = ctf_enum_read,
        .enum_write = ctf_enum_write,
 };
index 5cd09d9538e4acd3e6f8470d7b8884cc356ff2dd..53a9692f85b46b3c2c8baaef851fd27ac08eac6f 100644 (file)
@@ -33,12 +33,50 @@ void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
        align_pos(src, string_class->p.alignment);
        srcaddr = get_pos_addr(src);
        len = strlen(srcaddr) + 1;
-       if (!dest)
+       if (dest->dummy)
                goto end;
        align_pos(dest, string_class->p.alignment);
        destaddr = get_pos_addr(dest);
-       strcpy(dest, src);
+       strcpy(destaddr, srcaddr);
+end:
        move_pos(dest, len);
+       move_pos(src, len);
+}
+
+void ctf_string_read(unsigned char **dest, struct stream_pos *src,
+                    const struct type_class_string *string_class)
+{
+       size_t len;
+       unsigned char *srcaddr;
+
+       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);
 end:
        move_pos(src, len);
 }
+
+void ctf_string_write(struct stream_pos *dest, const unsigned char *src,
+                     const struct type_class_string *string_class)
+{
+       size_t len;
+       unsigned char *destaddr;
+
+       align_pos(dest, string_class->p.alignment);
+       len = strlen(src) + 1;
+       if (dest->dummy)
+               goto end;
+       destaddr = get_pos_addr(dest);
+       strcpy(destaddr, src);
+end:
+       move_pos(dest, len);
+}
+
+void ctf_string_free_temp(unsigned char *string)
+{
+       g_free(string);
+}
index 473bbff9df4918e1159faa87e741c34d8fd127c5..40b89847d759ec6bb410e56cd65b5461982804c5 100644 (file)
@@ -72,6 +72,11 @@ void ctf_float_copy(struct stream_pos *destp, const struct type_class_float *des
 
 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,
+                    const struct type_class_string *string_class);
+void ctf_string_write(struct stream_pos *dest, const unsigned char *src,
+                     const struct type_class_string *string_class);
+void ctf_string_free_temp(unsigned char *string);
 
 GQuark ctf_enum_read(struct stream_pos *pos,
                const struct type_class_enum *src);
index 1a847846b6dc659e63459b49afdbfedd447267db..43b38eed350b980641ca2f8f14bb8b63f507a8d5 100644 (file)
@@ -63,6 +63,11 @@ struct format {
 
        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,
+                           const struct type_class_string *string_class);
+       void (*string_write)(struct stream_pos *dest, const unsigned char *src,
+                            const struct type_class_string *string_class);
+       void (*string_free_temp)(unsigned char *string);
 
        GQuark (*enum_read)(struct stream_pos *pos,
                            const struct type_class_enum *src);
index df9bacac43260257d832c68ffd805f4e325bcf7c..3f9c1787f3c942e165c8e1284bdd1633862a54ba 100644 (file)
@@ -32,7 +32,11 @@ 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 {
-               /* TODO */
+               unsigned char *tmp = NULL;
+
+               fsrc->string_read(&tmp, src, string_class);
+               fdest->string_write(dest, tmp, string_class);
+               fsrc->string_free_temp(tmp);
        }
 }
 
This page took 0.026366 seconds and 4 git commands to generate.