X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Ftypes%2Fstring.c;h=b19335e2b860d4418fde30cb0d4526726896e048;hb=809cbff588674d09c14b128eb95d332048382770;hp=fab69c4fa8833208c2f95d5d971a7764e9029ad9;hpb=4c8bfb7e0a9cef6e74cefa38ed54bf8cbd424183;p=babeltrace.git diff --git a/formats/ctf/types/string.c b/formats/ctf/types/string.c index fab69c4f..b19335e2 100644 --- a/formats/ctf/types/string.c +++ b/formats/ctf/types/string.c @@ -20,57 +20,68 @@ #include /* C99 limits */ #include -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 *pdest, struct stream_pos *psrc, + const struct declaration_string *string_declaration) { + struct ctf_stream_pos *dest = ctf_pos(pdest); + struct ctf_stream_pos *src = ctf_pos(psrc); size_t len; - unsigned char *destaddr, *srcaddr; + char *destaddr, *srcaddr; - align_pos(src, string_class->p.alignment); - srcaddr = get_pos_addr(src); + ctf_align_pos(src, string_declaration->p.alignment); + srcaddr = ctf_get_pos_addr(src); len = strlen(srcaddr) + 1; if (dest->dummy) goto end; - align_pos(dest, string_class->p.alignment); - destaddr = get_pos_addr(dest); + ctf_align_pos(dest, string_declaration->p.alignment); + destaddr = ctf_get_pos_addr(dest); strcpy(destaddr, srcaddr); end: - move_pos(dest, len); - move_pos(src, len); + ctf_move_pos(dest, len); + ctf_move_pos(src, len); } -void ctf_string_read(unsigned char **dest, struct stream_pos *src, - const struct type_class_string *string_class) +void ctf_string_read(struct stream_pos *ppos, struct definition *definition) { + struct definition_string *string_definition = + container_of(definition, struct definition_string, p); + const struct declaration_string *string_declaration = + string_definition->declaration; + struct ctf_stream_pos *pos = ctf_pos(ppos); size_t len; - unsigned char *srcaddr; + char *srcaddr; - align_pos(src, string_class->p.alignment); - srcaddr = get_pos_addr(src); + ctf_align_pos(pos, string_declaration->p.alignment); + srcaddr = ctf_get_pos_addr(pos); len = strlen(srcaddr) + 1; - *dest = g_realloc(*dest, len); - strcpy(*dest, srcaddr); -end: - move_pos(src, len); + if (string_definition->alloc_len < len) { + string_definition->value = + g_realloc(string_definition->value, len); + string_definition->alloc_len = len; + } + memcpy(string_definition->value, srcaddr, len); + string_definition->len = len; + ctf_move_pos(pos, len); } -void ctf_string_write(struct stream_pos *dest, const unsigned char *src, - const struct type_class_string *string_class) +void ctf_string_write(struct stream_pos *ppos, + struct definition *definition) { + struct definition_string *string_definition = + container_of(definition, struct definition_string, p); + const struct declaration_string *string_declaration = + string_definition->declaration; + struct ctf_stream_pos *pos = ctf_pos(ppos); size_t len; - unsigned char *destaddr; + char *destaddr; - align_pos(dest, string_class->p.alignment); - len = strlen(src) + 1; - if (dest->dummy) + ctf_align_pos(pos, string_declaration->p.alignment); + assert(string_definition->value != NULL); + len = string_definition->len; + if (pos->dummy) goto end; - destaddr = get_pos_addr(dest); - strcpy(destaddr, src); + destaddr = ctf_get_pos_addr(pos); + strcpy(destaddr, string_definition->value); end: - move_pos(dest, len); -} - -void ctf_string_free_temp(unsigned char *string) -{ - g_free(string); + ctf_move_pos(pos, len); }