Update glib dep to 2.22 in configure.ac
[babeltrace.git] / types / integer.c
1 /*
2 * integer.c
3 *
4 * BabelTrace - Integer Type Converter
5 *
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
22 #include <stdint.h>
23
24 static
25 struct definition *_integer_definition_new(struct declaration *declaration,
26 struct definition_scope *parent_scope,
27 GQuark field_name, int index,
28 const char *root_name);
29 static
30 void _integer_definition_free(struct definition *definition);
31
32 static
33 void _integer_declaration_free(struct declaration *declaration)
34 {
35 struct declaration_integer *integer_declaration =
36 container_of(declaration, struct declaration_integer, p);
37 g_free(integer_declaration);
38 }
39
40 struct declaration_integer *
41 integer_declaration_new(size_t len, int byte_order,
42 int signedness, size_t alignment, int base,
43 enum ctf_string_encoding encoding)
44 {
45 struct declaration_integer *integer_declaration;
46
47 integer_declaration = g_new(struct declaration_integer, 1);
48 integer_declaration->p.id = CTF_TYPE_INTEGER;
49 integer_declaration->p.alignment = alignment;
50 integer_declaration->p.declaration_free = _integer_declaration_free;
51 integer_declaration->p.definition_free = _integer_definition_free;
52 integer_declaration->p.definition_new = _integer_definition_new;
53 integer_declaration->p.ref = 1;
54 integer_declaration->len = len;
55 integer_declaration->byte_order = byte_order;
56 integer_declaration->signedness = signedness;
57 integer_declaration->base = base;
58 integer_declaration->encoding = encoding;
59 return integer_declaration;
60 }
61
62 static
63 struct definition *
64 _integer_definition_new(struct declaration *declaration,
65 struct definition_scope *parent_scope,
66 GQuark field_name, int index,
67 const char *root_name)
68 {
69 struct declaration_integer *integer_declaration =
70 container_of(declaration, struct declaration_integer, p);
71 struct definition_integer *integer;
72 int ret;
73
74 integer = g_new(struct definition_integer, 1);
75 declaration_ref(&integer_declaration->p);
76 integer->p.declaration = declaration;
77 integer->declaration = integer_declaration;
78 integer->p.ref = 1;
79 /*
80 * Use INT_MAX order to ensure that all fields of the parent
81 * scope are seen as being prior to this scope.
82 */
83 integer->p.index = root_name ? INT_MAX : index;
84 integer->p.name = field_name;
85 integer->p.path = new_definition_path(parent_scope, field_name,
86 root_name);
87 integer->p.scope = NULL;
88 integer->value._unsigned = 0;
89 ret = register_field_definition(field_name, &integer->p,
90 parent_scope);
91 assert(!ret);
92 return &integer->p;
93 }
94
95 static
96 void _integer_definition_free(struct definition *definition)
97 {
98 struct definition_integer *integer =
99 container_of(definition, struct definition_integer, p);
100
101 declaration_unref(integer->p.declaration);
102 g_free(integer);
103 }
This page took 0.031016 seconds and 4 git commands to generate.