4 * BabelTrace - String Type Converter
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
24 struct definition
*_string_definition_new(struct declaration
*declaration
,
25 struct definition_scope
*parent_scope
,
26 GQuark field_name
, int index
);
28 void _string_definition_free(struct definition
*definition
);
31 void _string_declaration_free(struct declaration
*declaration
)
33 struct declaration_string
*string_declaration
=
34 container_of(declaration
, struct declaration_string
, p
);
35 g_free(string_declaration
);
38 struct declaration_string
*
39 string_declaration_new(enum ctf_string_encoding encoding
)
41 struct declaration_string
*string_declaration
;
43 string_declaration
= g_new(struct declaration_string
, 1);
44 string_declaration
->p
.id
= CTF_TYPE_STRING
;
45 string_declaration
->p
.alignment
= CHAR_BIT
;
46 string_declaration
->p
.declaration_free
= _string_declaration_free
;
47 string_declaration
->p
.definition_new
= _string_definition_new
;
48 string_declaration
->p
.definition_free
= _string_definition_free
;
49 string_declaration
->p
.ref
= 1;
50 string_declaration
->encoding
= encoding
;
51 return string_declaration
;
56 _string_definition_new(struct declaration
*declaration
,
57 struct definition_scope
*parent_scope
,
58 GQuark field_name
, int index
)
60 struct declaration_string
*string_declaration
=
61 container_of(declaration
, struct declaration_string
, p
);
62 struct definition_string
*string
;
64 string
= g_new(struct definition_string
, 1);
65 declaration_ref(&string_declaration
->p
);
66 string
->p
.declaration
= declaration
;
67 string
->declaration
= string_declaration
;
69 string
->p
.index
= index
;
70 string
->p
.name
= field_name
;
71 string
->p
.path
= new_definition_path(parent_scope
, field_name
);
74 string
->alloc_len
= 0;
79 void _string_definition_free(struct definition
*definition
)
81 struct definition_string
*string
=
82 container_of(definition
, struct definition_string
, p
);
84 declaration_unref(string
->p
.declaration
);
85 g_free(string
->value
);