Create copy of integer declaration before applying base-16 for pointers
[babeltrace.git] / types / string.c
CommitLineData
bed864a7 1/*
ccd7e1c8 2 * string.c
bed864a7 3 *
ccd7e1c8 4 * BabelTrace - String Type Converter
bed864a7 5 *
c054553d 6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
bed864a7 7 *
ccd7e1c8
MD
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:
bed864a7 14 *
ccd7e1c8
MD
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
bed864a7
MD
17 */
18
19#include <babeltrace/compiler.h>
20#include <babeltrace/align.h>
4c8bfb7e 21#include <babeltrace/format.h>
bed864a7 22
c054553d 23static
f6625916 24struct definition *_string_definition_new(struct declaration *declaration,
05c749e5
MD
25 struct definition_scope *parent_scope,
26 GQuark field_name, int index);
c054553d 27static
e1151715 28void _string_definition_free(struct definition *definition);
c054553d 29
c054553d 30static
f6625916 31void _string_declaration_free(struct declaration *declaration)
bed864a7 32{
f6625916
MD
33 struct declaration_string *string_declaration =
34 container_of(declaration, struct declaration_string, p);
35 g_free(string_declaration);
bed864a7
MD
36}
37
ab4cf058
MD
38struct declaration_string *
39 string_declaration_new(enum ctf_string_encoding encoding)
bed864a7 40{
f6625916 41 struct declaration_string *string_declaration;
bed864a7 42
f6625916
MD
43 string_declaration = g_new(struct declaration_string, 1);
44 string_declaration->p.id = CTF_TYPE_STRING;
f6625916 45 string_declaration->p.alignment = CHAR_BIT;
f6625916
MD
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;
ab4cf058 50 string_declaration->encoding = encoding;
f6625916 51 return string_declaration;
bed864a7 52}
c054553d
MD
53
54static
e1151715 55struct definition *
f6625916 56 _string_definition_new(struct declaration *declaration,
05c749e5
MD
57 struct definition_scope *parent_scope,
58 GQuark field_name, int index)
c054553d 59{
f6625916
MD
60 struct declaration_string *string_declaration =
61 container_of(declaration, struct declaration_string, p);
e1151715 62 struct definition_string *string;
c054553d 63
e1151715 64 string = g_new(struct definition_string, 1);
f6625916
MD
65 declaration_ref(&string_declaration->p);
66 string->p.declaration = declaration;
67 string->declaration = string_declaration;
c054553d 68 string->p.ref = 1;
05c749e5 69 string->p.index = index;
b1a2f580 70 string->p.name = field_name;
31262354 71 string->p.path = new_definition_path(parent_scope, field_name);
c054553d 72 string->value = NULL;
d11e9c49
MD
73 string->len = 0;
74 string->alloc_len = 0;
c054553d
MD
75 return &string->p;
76}
77
78static
e1151715 79void _string_definition_free(struct definition *definition)
c054553d 80{
e1151715
MD
81 struct definition_string *string =
82 container_of(definition, struct definition_string, p);
c054553d 83
f6625916 84 declaration_unref(string->p.declaration);
c054553d
MD
85 g_free(string->value);
86 g_free(string);
87}
This page took 0.026443 seconds and 4 git commands to generate.