Fix type free memleak
[babeltrace.git] / include / babeltrace / types.h
CommitLineData
d79865b9
MD
1#ifndef _BABELTRACE_TYPES_H
2#define _BABELTRACE_TYPES_H
3
4/*
5 * BabelTrace
6 *
fc93b2bd 7 * Type Header
d79865b9
MD
8 *
9 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
fc93b2bd
MD
26#include <babeltrace/format.h>
27
28struct type_class {
29 GQuark name; /* type name */
30 size_t alignment; /* type alignment, in bits */
31 /*
32 * Type copy function. Knows how to find the child type_class from the
33 * parent type_class.
34 */
35 size_t (*copy)(unsigned char *dest, const struct format *fdest,
36 const unsigned char *src, const struct format *fsrc,
37 const struct type_class *type_class);
90b676d7 38 void (*free)(struct type_class *type_class);
fc93b2bd
MD
39};
40
41struct type_class_integer {
42 struct type_class p;
43 size_t len; /* length, in bits. */
44 int byte_order; /* byte order */
45 int signedness;
46};
47
48struct type_class_bitfield {
49 struct type_class_integer p;
50 size_t start_offset; /* offset from base address, in bits */
51};
52
53struct type_class_float {
54 struct type_class p;
55 size_t mantissa_len;
56 size_t exp_len;
57 int byte_order;
0a46062b 58 /* TODO: we might want to express more info about NaN, +inf and -inf */
fc93b2bd
MD
59};
60
448d3cc7
MD
61struct enum_table {
62 GHashTable *value_to_quark; /* Tuples (value, GQuark) */
63 GHashTable *quark_to_value; /* Tuples (GQuark, value) */
64};
65
fc93b2bd 66struct type_class_enum {
448d3cc7
MD
67 struct type_class_bitfield p; /* inherit from bitfield */
68 struct enum_table table;
fc93b2bd
MD
69};
70
71struct type_class_struct {
72 struct type_class p;
73 /* TODO */
74};
75
698f0fe4
MD
76struct type_class *ctf_lookup_type(GQuark qname);
77int ctf_register_type(struct type_class *type_class);
78
0a46062b
MD
79/* Nameless types can be created by passing a NULL name */
80
81struct type_class_integer *integer_type_new(const char *name,
82 size_t start_offset,
83 size_t len, int byte_order,
84 int signedness);
85void integer_type_free(struct type_class_integer *int_class);
86
87struct type_class_bitfield *bitfield_type_new(const char *name,
88 size_t start_offset,
89 size_t len, int byte_order,
90 int signedness);
91void bitfield_type_free(struct type_class_bitfield *bitfield_class);
92
93struct type_class_float *float_type_new(const char *name,
94 size_t mantissa_len,
95 size_t exp_len, int byte_order,
96 size_t alignment);
97void float_type_free(struct type_class_float *float_class);
98
448d3cc7
MD
99/*
100 * A GQuark can be translated to/from strings with g_quark_from_string() and
101 * g_quark_to_string().
102 */
103GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v);
104GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v);
105uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
106 size_t len, int byte_order, GQuark q);
107int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
108 size_t len, int byte_order, GQuark q);
109void enum_signed_insert(struct type_class_enum *enum_class,
110 int64_t v, GQuark q);
111void enum_unsigned_insert(struct type_class_enum *enum_class,
112 uint64_t v, GQuark q);
113
114struct type_class_enum *enum_type_new(const char *name,
115 size_t start_offset,
116 size_t len, int byte_order,
117 int signedness,
118 size_t alignment);
119void enum_type_free(struct type_class_enum *enum_class);
120
d79865b9 121#endif /* _BABELTRACE_TYPES_H */
This page took 0.026914 seconds and 4 git commands to generate.