4 * BabelTrace - String Type Converter
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/compiler.h>
22 #include <babeltrace/align.h>
23 #include <babeltrace/format.h>
26 struct definition
*_string_definition_new(struct declaration
*declaration
,
27 struct definition_scope
*parent_scope
,
28 GQuark field_name
, int index
,
29 const char *root_name
);
31 void _string_definition_free(struct definition
*definition
);
34 void _string_declaration_free(struct declaration
*declaration
)
36 struct declaration_string
*string_declaration
=
37 container_of(declaration
, struct declaration_string
, p
);
38 g_free(string_declaration
);
41 struct declaration_string
*
42 string_declaration_new(enum ctf_string_encoding encoding
)
44 struct declaration_string
*string_declaration
;
46 string_declaration
= g_new(struct declaration_string
, 1);
47 string_declaration
->p
.id
= CTF_TYPE_STRING
;
48 string_declaration
->p
.alignment
= CHAR_BIT
;
49 string_declaration
->p
.declaration_free
= _string_declaration_free
;
50 string_declaration
->p
.definition_new
= _string_definition_new
;
51 string_declaration
->p
.definition_free
= _string_definition_free
;
52 string_declaration
->p
.ref
= 1;
53 string_declaration
->encoding
= encoding
;
54 return string_declaration
;
59 _string_definition_new(struct declaration
*declaration
,
60 struct definition_scope
*parent_scope
,
61 GQuark field_name
, int index
,
62 const char *root_name
)
64 struct declaration_string
*string_declaration
=
65 container_of(declaration
, struct declaration_string
, p
);
66 struct definition_string
*string
;
69 string
= g_new(struct definition_string
, 1);
70 declaration_ref(&string_declaration
->p
);
71 string
->p
.declaration
= declaration
;
72 string
->declaration
= string_declaration
;
75 * Use INT_MAX order to ensure that all fields of the parent
76 * scope are seen as being prior to this scope.
78 string
->p
.index
= root_name
? INT_MAX
: index
;
79 string
->p
.name
= field_name
;
80 string
->p
.path
= new_definition_path(parent_scope
, field_name
,
82 string
->p
.scope
= NULL
;
85 string
->alloc_len
= 0;
86 ret
= register_field_definition(field_name
, &string
->p
,
93 void _string_definition_free(struct definition
*definition
)
95 struct definition_string
*string
=
96 container_of(definition
, struct definition_string
, p
);
98 declaration_unref(string
->p
.declaration
);
99 g_free(string
->value
);