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
,
27 const char *root_name
);
29 void _string_definition_free(struct definition
*definition
);
32 void _string_declaration_free(struct declaration
*declaration
)
34 struct declaration_string
*string_declaration
=
35 container_of(declaration
, struct declaration_string
, p
);
36 g_free(string_declaration
);
39 struct declaration_string
*
40 string_declaration_new(enum ctf_string_encoding encoding
)
42 struct declaration_string
*string_declaration
;
44 string_declaration
= g_new(struct declaration_string
, 1);
45 string_declaration
->p
.id
= CTF_TYPE_STRING
;
46 string_declaration
->p
.alignment
= CHAR_BIT
;
47 string_declaration
->p
.declaration_free
= _string_declaration_free
;
48 string_declaration
->p
.definition_new
= _string_definition_new
;
49 string_declaration
->p
.definition_free
= _string_definition_free
;
50 string_declaration
->p
.ref
= 1;
51 string_declaration
->encoding
= encoding
;
52 return string_declaration
;
57 _string_definition_new(struct declaration
*declaration
,
58 struct definition_scope
*parent_scope
,
59 GQuark field_name
, int index
,
60 const char *root_name
)
62 struct declaration_string
*string_declaration
=
63 container_of(declaration
, struct declaration_string
, p
);
64 struct definition_string
*string
;
67 string
= g_new(struct definition_string
, 1);
68 declaration_ref(&string_declaration
->p
);
69 string
->p
.declaration
= declaration
;
70 string
->declaration
= string_declaration
;
73 * Use INT_MAX order to ensure that all fields of the parent
74 * scope are seen as being prior to this scope.
76 string
->p
.index
= root_name
? INT_MAX
: index
;
77 string
->p
.name
= field_name
;
78 string
->p
.path
= new_definition_path(parent_scope
, field_name
,
80 string
->p
.scope
= NULL
;
83 string
->alloc_len
= 0;
84 ret
= register_field_definition(field_name
, &string
->p
,
91 void _string_definition_free(struct definition
*definition
)
93 struct definition_string
*string
=
94 container_of(definition
, struct definition_string
, p
);
96 declaration_unref(string
->p
.declaration
);
97 g_free(string
->value
);