struct trace_descriptor *ctf_open_trace(const char *path, int flags);
void ctf_close_trace(struct trace_descriptor *descriptor);
-static struct format ctf_format = {
- .uint_read = ctf_uint_read,
- .int_read = ctf_int_read,
- .uint_write = ctf_uint_write,
- .int_write = ctf_int_write,
- .double_read = ctf_double_read,
- .double_write = ctf_double_write,
- .ldouble_read = ctf_ldouble_read,
- .ldouble_write = ctf_ldouble_write,
- .float_copy = ctf_float_copy,
- .string_copy = ctf_string_copy,
- .string_read = ctf_string_read,
- .string_write = ctf_string_write,
- .string_free_temp = ctf_string_free_temp,
- .enum_read = ctf_enum_read,
- .enum_write = ctf_enum_write,
- .struct_begin = ctf_struct_begin,
- .struct_end = ctf_struct_end,
- .variant_begin = ctf_variant_begin,
- .variant_end = ctf_variant_end,
- .array_begin = ctf_array_begin,
- .array_end = ctf_array_end,
- .sequence_begin = ctf_sequence_begin,
- .sequence_end = ctf_sequence_end,
+static rw_dispatch read_dispatch_table[] = {
+ [ CTF_TYPE_INTEGER ] = ctf_integer_read,
+ [ CTF_TYPE_FLOAT ] = ctf_float_read,
+ [ CTF_TYPE_ENUM ] = ctf_enum_read,
+ [ CTF_TYPE_STRING ] = ctf_string_read,
+ [ CTF_TYPE_STRUCT ] = ctf_struct_rw,
+ [ CTF_TYPE_VARIANT ] = ctf_variant_rw,
+ [ CTF_TYPE_ARRAY ] = ctf_array_rw,
+ [ CTF_TYPE_SEQUENCE ] = ctf_sequence_rw,
+};
+
+static rw_dispatch write_dispatch_table[] = {
+ [ CTF_TYPE_INTEGER ] = ctf_integer_write,
+ [ CTF_TYPE_FLOAT ] = ctf_float_write,
+ [ CTF_TYPE_ENUM ] = ctf_enum_write,
+ [ CTF_TYPE_STRING ] = ctf_string_write,
+ [ CTF_TYPE_STRUCT ] = ctf_struct_rw,
+ [ CTF_TYPE_VARIANT ] = ctf_variant_rw,
+ [ CTF_TYPE_ARRAY ] = ctf_array_rw,
+ [ CTF_TYPE_SEQUENCE ] = ctf_sequence_rw,
+};
+
+struct format ctf_format = {
.open_trace = ctf_open_trace,
.close_trace = ctf_close_trace,
};
case O_RDONLY:
pos->prot = PROT_READ;
pos->flags = MAP_PRIVATE;
+ pos->parent.rw_table = read_dispatch_table;
break;
case O_WRONLY:
case O_RDWR:
pos->prot = PROT_WRITE; /* Write has priority */
pos->flags = MAP_SHARED;
+ pos->parent.rw_table = write_dispatch_table;
ctf_move_pos_slow(pos, 0); /* position for write */
break;
default:
/* read and check header, set stream id (and check) */
if (td->packet_header) {
/* Read packet header */
- td->packet_header->p.declaration->copy(NULL, NULL,
- &pos->parent, &ctf_format, &td->packet_header->p);
+ generic_rw(&pos->parent, &td->packet_header->p);
len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
if (len_index >= 0) {
if (stream->packet_context) {
/* Read packet context */
- stream->packet_context->p.declaration->copy(NULL, NULL,
- &pos->parent, &ctf_format, &stream->packet_context->p);
+ generic_rw(&pos->parent, &stream->packet_context->p);
/* read content size from header */
len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
#include <babeltrace/ctf/types.h>
-void ctf_array_begin(struct stream_pos *pos,
- const struct declaration_array *array_declaration)
-{
- /* No need to align, because the first field will align itself. */
-}
-
-void ctf_array_end(struct stream_pos *pos,
- const struct declaration_array *array_declaration)
+void ctf_array_rw(struct stream_pos *pos, struct definition *definition)
{
+ array_rw(pos, definition);
}
#include <stdint.h>
#include <glib.h>
-/*
- * The caller should unref the GArray.
- */
-GArray *ctf_enum_read(struct stream_pos *pos,
- const struct declaration_enum *src)
+void ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
{
- const struct declaration_integer *integer_declaration = src->integer_declaration;
-
- if (!integer_declaration->signedness) {
- uint64_t v;
-
- v = ctf_uint_read(pos, integer_declaration);
- return enum_uint_to_quark_set(src, v);
- } else {
- int64_t v;
-
- v = ctf_int_read(pos, integer_declaration);
- return enum_int_to_quark_set(src, v);
- }
+ struct definition_enum *enum_definition =
+ container_of(definition, struct definition_enum, p);
+ const struct declaration_enum *enum_declaration =
+ enum_definition->declaration;
+ struct definition_integer *integer_definition =
+ enum_definition->integer;
+ const struct declaration_integer *integer_declaration =
+ integer_definition->declaration;
+ GArray *qs;
+
+ ctf_integer_read(ppos, &integer_definition->p);
+ if (!integer_declaration->signedness)
+ qs = enum_uint_to_quark_set(enum_declaration,
+ integer_definition->value._unsigned);
+ else
+ qs = enum_int_to_quark_set(enum_declaration,
+ integer_definition->value._signed);
+ assert(qs);
+ /* unref previous quark set */
+ if (enum_definition->value)
+ g_array_unref(enum_definition->value);
+ enum_definition->value = qs;
}
-/*
- * Arbitrarily choose the start of the first matching range.
- */
-void ctf_enum_write(struct stream_pos *pos,
- const struct declaration_enum *dest,
- GQuark q)
+void ctf_enum_write(struct stream_pos *pos, struct definition *definition)
{
- const struct declaration_integer *integer_declaration = dest->integer_declaration;
- GArray *array;
-
- array = enum_quark_to_range_set(dest, q);
- assert(array);
+ struct definition_enum *enum_definition =
+ container_of(definition, struct definition_enum, p);
+ struct definition_integer *integer_definition =
+ enum_definition->integer;
- if (!integer_declaration->signedness) {
- uint64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
- ctf_uint_write(pos, integer_declaration, v);
- } else {
- int64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
- ctf_int_write(pos, integer_declaration, v);
- }
+ ctf_integer_write(pos, &integer_definition->p);
}
#endif
};
+static struct declaration_float *static_ldouble_declaration;
+
struct pos_len {
size_t sign_start, exp_start, mantissa_start, len;
};
void _ctf_float_copy(struct stream_pos *destp,
- const struct declaration_float *dest_declaration,
+ struct definition_float *dest_definition,
struct stream_pos *srcp,
- const struct declaration_float *src_declaration)
+ const struct definition_float *src_definition)
{
- uint8_t sign;
- int64_t exp;
- uint64_t mantissa;
-
/* Read */
- if (src_declaration->byte_order == LITTLE_ENDIAN) {
- mantissa = ctf_uint_read(srcp, src_declaration->mantissa);
- exp = ctf_int_read(srcp, src_declaration->exp);
- sign = ctf_uint_read(srcp, src_declaration->sign);
+ if (src_definition->declaration->byte_order == LITTLE_ENDIAN) {
+ ctf_integer_read(srcp, &src_definition->mantissa->p);
+ ctf_integer_read(srcp, &src_definition->exp->p);
+ ctf_integer_read(srcp, &src_definition->sign->p);
} else {
- sign = ctf_uint_read(srcp, src_declaration->sign);
- exp = ctf_int_read(srcp, src_declaration->exp);
- mantissa = ctf_uint_read(srcp, src_declaration->mantissa);
+ ctf_integer_read(srcp, &src_definition->sign->p);
+ ctf_integer_read(srcp, &src_definition->exp->p);
+ ctf_integer_read(srcp, &src_definition->mantissa->p);
}
+
+ dest_definition->mantissa->value._unsigned =
+ src_definition->mantissa->value._unsigned;
+ dest_definition->exp->value._signed =
+ src_definition->exp->value._signed;
+ dest_definition->sign->value._unsigned =
+ src_definition->sign->value._unsigned;
+
/* Write */
- if (dest_declaration->byte_order == LITTLE_ENDIAN) {
- ctf_uint_write(destp, dest_declaration->mantissa, mantissa);
- ctf_int_write(destp, dest_declaration->exp, exp);
- ctf_uint_write(destp, dest_declaration->sign, sign);
+ if (dest_definition->declaration->byte_order == LITTLE_ENDIAN) {
+ ctf_integer_write(destp, &dest_definition->mantissa->p);
+ ctf_integer_write(destp, &dest_definition->exp->p);
+ ctf_integer_write(destp, &dest_definition->sign->p);
} else {
- ctf_uint_write(destp, dest_declaration->sign, sign);
- ctf_int_write(destp, dest_declaration->exp, exp);
- ctf_uint_write(destp, dest_declaration->mantissa, mantissa);
+ ctf_integer_write(destp, &dest_definition->sign->p);
+ ctf_integer_write(destp, &dest_definition->exp->p);
+ ctf_integer_write(destp, &dest_definition->mantissa->p);
}
}
-void ctf_float_copy(struct stream_pos *dest, struct stream_pos *src,
- const struct declaration_float *float_declaration)
-{
- ctf_align_pos(ctf_pos(src), float_declaration->p.alignment);
- ctf_align_pos(ctf_pos(dest), float_declaration->p.alignment);
- _ctf_float_copy(dest, float_declaration, src, float_declaration);
-}
-
-double ctf_double_read(struct stream_pos *srcp,
- const struct declaration_float *float_declaration)
+void ctf_float_read(struct stream_pos *ppos, struct definition *definition)
{
- union doubleIEEE754 u;
- struct declaration_float *dest_declaration =
- float_declaration_new(DBL_MANT_DIG,
- sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
- BYTE_ORDER,
- __alignof__(double));
+ struct definition_float *float_definition =
+ container_of(definition, struct definition_float, p);
+ const struct declaration_float *float_declaration =
+ float_definition->declaration;
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+ union ldoubleIEEE754 u;
+ struct definition *tmpdef =
+ static_ldouble_declaration->p.definition_new(&static_ldouble_declaration->p,
+ NULL, 0, 0);
+ struct definition_float *tmpfloat =
+ container_of(tmpdef, struct definition_float, p);
struct ctf_stream_pos destp;
- ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
ctf_init_pos(&destp, -1);
destp.base = (char *) u.bits;
- _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
- declaration_unref(&dest_declaration->p);
- return u.v;
+
+ ctf_align_pos(pos, float_declaration->p.alignment);
+ _ctf_float_copy(&destp.parent, tmpfloat, ppos, float_definition);
+ float_definition->value = u.v;
+ definition_unref(tmpdef);
}
-void ctf_double_write(struct stream_pos *destp,
- const struct declaration_float *float_declaration,
- double v)
+void ctf_float_write(struct stream_pos *ppos, struct definition *definition)
{
- union doubleIEEE754 u;
- struct declaration_float *src_declaration =
- float_declaration_new(DBL_MANT_DIG,
- sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
- BYTE_ORDER,
- __alignof__(double));
+ struct definition_float *float_definition =
+ container_of(definition, struct definition_float, p);
+ const struct declaration_float *float_declaration =
+ float_definition->declaration;
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+ union ldoubleIEEE754 u;
+ struct definition *tmpdef =
+ static_ldouble_declaration->p.definition_new(&static_ldouble_declaration->p,
+ NULL, 0, 0);
+ struct definition_float *tmpfloat =
+ container_of(tmpdef, struct definition_float, p);
struct ctf_stream_pos srcp;
- u.v = v;
- ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
ctf_init_pos(&srcp, -1);
srcp.base = (char *) u.bits;
- _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
- declaration_unref(&src_declaration->p);
+
+ u.v = float_definition->value;
+ ctf_align_pos(pos, float_declaration->p.alignment);
+ _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
+ definition_unref(tmpdef);
}
-long double ctf_ldouble_read(struct stream_pos *srcp,
- const struct declaration_float *float_declaration)
+void __attribute__((constructor)) ctf_float_init(void)
{
- union ldoubleIEEE754 u;
- struct declaration_float *dest_declaration =
+ static_ldouble_declaration =
float_declaration_new(LDBL_MANT_DIG,
sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
BYTE_ORDER,
__alignof__(long double));
- struct ctf_stream_pos destp;
-
- ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
- ctf_init_pos(&destp, -1);
- destp.base = (char *) u.bits;
- _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
- declaration_unref(&dest_declaration->p);
- return u.v;
}
-void ctf_ldouble_write(struct stream_pos *destp,
- const struct declaration_float *float_declaration,
- long double v)
+void __attribute__((destructor)) ctf_float_fini(void)
{
- union ldoubleIEEE754 u;
- struct declaration_float *src_declaration =
- float_declaration_new(LDBL_MANT_DIG,
- sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
- BYTE_ORDER,
- __alignof__(long double));
- struct ctf_stream_pos srcp;
-
- u.v = v;
- ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
- ctf_init_pos(&srcp, -1);
- srcp.base = (char *) u.bits;
- _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
- declaration_unref(&src_declaration->p);
+ declaration_unref(&static_ldouble_declaration->p);
}
#include <endian.h>
static
-uint64_t _aligned_uint_read(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration)
+void _aligned_integer_read(struct stream_pos *ppos,
+ struct definition *definition)
{
+ struct definition_integer *integer_definition =
+ container_of(definition, struct definition_integer, p);
+ const struct declaration_integer *integer_declaration =
+ integer_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
- switch (integer_declaration->len) {
- case 8:
- {
- uint8_t v;
- v = *(const uint8_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return v;
- }
- case 16:
- {
- uint16_t v;
-
- v = *(const uint16_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT16_SWAP_LE_BE(v) : v;
- }
- case 32:
- {
- uint32_t v;
-
- v = *(const uint32_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT32_SWAP_LE_BE(v) : v;
- }
- case 64:
- {
- uint64_t v;
-
- v = *(const uint64_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT64_SWAP_LE_BE(v) : v;
- }
- default:
- assert(0);
+ if (!integer_declaration->signedness) {
+ switch (integer_declaration->len) {
+ case 8:
+ {
+ uint8_t v;
+
+ v = *(const uint8_t *)pos->base;
+ integer_definition->value._unsigned = v;
+ break;
+ }
+ case 16:
+ {
+ uint16_t v;
+
+ v = *(const uint16_t *)pos->base;
+ integer_definition->value._unsigned =
+ rbo ? GUINT16_SWAP_LE_BE(v) : v;
+ break;
+ }
+ case 32:
+ {
+ uint32_t v;
+
+ v = *(const uint32_t *)pos->base;
+ integer_definition->value._unsigned =
+ rbo ? GUINT32_SWAP_LE_BE(v) : v;
+ break;
+ }
+ case 64:
+ {
+ uint64_t v;
+
+ v = *(const uint64_t *)pos->base;
+ integer_definition->value._unsigned =
+ rbo ? GUINT64_SWAP_LE_BE(v) : v;
+ break;
+ }
+ default:
+ assert(0);
+ }
+ } else {
+ switch (integer_declaration->len) {
+ case 8:
+ {
+ int8_t v;
+
+ v = *(const int8_t *)pos->base;
+ integer_definition->value._signed = v;
+ break;
+ }
+ case 16:
+ {
+ int16_t v;
+
+ v = *(const int16_t *)pos->base;
+ integer_definition->value._signed =
+ rbo ? GUINT16_SWAP_LE_BE(v) : v;
+ break;
+ }
+ case 32:
+ {
+ int32_t v;
+
+ v = *(const int32_t *)pos->base;
+ integer_definition->value._signed =
+ rbo ? GUINT32_SWAP_LE_BE(v) : v;
+ break;
+ }
+ case 64:
+ {
+ int64_t v;
+
+ v = *(const int64_t *)pos->base;
+ integer_definition->value._signed =
+ rbo ? GUINT64_SWAP_LE_BE(v) : v;
+ break;
+ }
+ default:
+ assert(0);
+ }
}
+ ctf_move_pos(pos, integer_declaration->len);
}
static
-int64_t _aligned_int_read(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration)
+void _aligned_integer_write(struct stream_pos *ppos,
+ struct definition *definition)
{
+ struct definition_integer *integer_definition =
+ container_of(definition, struct definition_integer, p);
+ const struct declaration_integer *integer_declaration =
+ integer_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
- switch (integer_declaration->len) {
- case 8:
- {
- int8_t v;
- v = *(const int8_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return v;
- }
- case 16:
- {
- int16_t v;
-
- v = *(const int16_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT16_SWAP_LE_BE(v) : v;
- }
- case 32:
- {
- int32_t v;
-
- v = *(const int32_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT32_SWAP_LE_BE(v) : v;
- }
- case 64:
- {
- int64_t v;
-
- v = *(const int64_t *)pos->base;
- ctf_move_pos(pos, integer_declaration->len);
- return rbo ? GUINT64_SWAP_LE_BE(v) : v;
- }
- default:
- assert(0);
- }
-}
-
-static
-void _aligned_uint_write(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration,
- uint64_t v)
-{
- struct ctf_stream_pos *pos = ctf_pos(ppos);
- int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
-
- ctf_align_pos(pos, integer_declaration->p.alignment);
- assert(!(pos->offset % CHAR_BIT));
if (pos->dummy)
goto end;
-
- switch (integer_declaration->len) {
- case 8: *(uint8_t *) ctf_get_pos_addr(pos) = (uint8_t) v;
- break;
- case 16:
- *(uint16_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT16_SWAP_LE_BE((uint16_t) v) :
- (uint16_t) v;
- break;
- case 32:
- *(uint32_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT32_SWAP_LE_BE((uint32_t) v) :
- (uint32_t) v;
- break;
- case 64:
- *(uint64_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT64_SWAP_LE_BE(v) : v;
- break;
- default:
- assert(0);
+ if (!integer_declaration->signedness) {
+ uint64_t v = integer_definition->value._unsigned;
+
+ switch (integer_declaration->len) {
+ case 8: *(uint8_t *) ctf_get_pos_addr(pos) = (uint8_t) v;
+ break;
+ case 16:
+ *(uint16_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT16_SWAP_LE_BE((uint16_t) v) :
+ (uint16_t) v;
+ break;
+ case 32:
+ *(uint32_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT32_SWAP_LE_BE((uint32_t) v) :
+ (uint32_t) v;
+ break;
+ case 64:
+ *(uint64_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT64_SWAP_LE_BE(v) : v;
+ break;
+ default:
+ assert(0);
+ }
+ } else {
+ int64_t v = integer_definition->value._signed;
+
+ switch (integer_declaration->len) {
+ case 8: *(int8_t *) ctf_get_pos_addr(pos) = (int8_t) v;
+ break;
+ case 16:
+ *(int16_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT16_SWAP_LE_BE((int16_t) v) :
+ (int16_t) v;
+ break;
+ case 32:
+ *(int32_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT32_SWAP_LE_BE((int32_t) v) :
+ (int32_t) v;
+ break;
+ case 64:
+ *(int64_t *) ctf_get_pos_addr(pos) = rbo ?
+ GUINT64_SWAP_LE_BE(v) : v;
+ break;
+ default:
+ assert(0);
+ }
}
end:
ctf_move_pos(pos, integer_declaration->len);
}
-static
-void _aligned_int_write(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration,
- int64_t v)
+void ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
{
+ struct definition_integer *integer_definition =
+ container_of(definition, struct definition_integer, p);
+ const struct declaration_integer *integer_declaration =
+ integer_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
- int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
ctf_align_pos(pos, integer_declaration->p.alignment);
- assert(!(pos->offset % CHAR_BIT));
- if (pos->dummy)
- goto end;
-
- switch (integer_declaration->len) {
- case 8: *(int8_t *) ctf_get_pos_addr(pos) = (int8_t) v;
- break;
- case 16:
- *(int16_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT16_SWAP_LE_BE((int16_t) v) :
- (int16_t) v;
- break;
- case 32:
- *(int32_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT32_SWAP_LE_BE((int32_t) v) :
- (int32_t) v;
- break;
- case 64:
- *(int64_t *) ctf_get_pos_addr(pos) = rbo ?
- GUINT64_SWAP_LE_BE(v) : v;
- break;
- default:
- assert(0);
+ if (!integer_declaration->signedness) {
+ if (integer_declaration->byte_order == LITTLE_ENDIAN)
+ bt_bitfield_read_le(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ &integer_definition->value._unsigned);
+ else
+ bt_bitfield_read_be(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ &integer_definition->value._unsigned);
+ } else {
+ if (integer_declaration->byte_order == LITTLE_ENDIAN)
+ bt_bitfield_read_le(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ &integer_definition->value._signed);
+ else
+ bt_bitfield_read_be(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ &integer_definition->value._signed);
}
-end:
ctf_move_pos(pos, integer_declaration->len);
- return;
}
-uint64_t ctf_uint_read(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration)
-{
- struct ctf_stream_pos *pos = ctf_pos(ppos);
- uint64_t v = 0;
-
- ctf_align_pos(pos, integer_declaration->p.alignment);
- if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
- integer_declaration->len, &v);
- else
- bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
- integer_declaration->len, &v);
- ctf_move_pos(pos, integer_declaration->len);
- return v;
-}
-
-int64_t ctf_int_read(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration)
-{
- struct ctf_stream_pos *pos = ctf_pos(ppos);
- int64_t v = 0;
-
- ctf_align_pos(pos, integer_declaration->p.alignment);
- if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
- integer_declaration->len, &v);
- else
- bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
- integer_declaration->len, &v);
- ctf_move_pos(pos, integer_declaration->len);
- return v;
-}
-
-void ctf_uint_write(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration,
- uint64_t v)
-{
- struct ctf_stream_pos *pos = ctf_pos(ppos);
-
- ctf_align_pos(pos, integer_declaration->p.alignment);
- if (pos->dummy)
- goto end;
- if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
- integer_declaration->len, v);
- else
- bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
- integer_declaration->len, v);
-end:
- ctf_move_pos(pos, integer_declaration->len);
-}
-
-void ctf_int_write(struct stream_pos *ppos,
- const struct declaration_integer *integer_declaration,
- int64_t v)
+void ctf_integer_write(struct stream_pos *ppos, struct definition *definition)
{
+ struct definition_integer *integer_definition =
+ container_of(definition, struct definition_integer, p);
+ const struct declaration_integer *integer_declaration =
+ integer_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, integer_declaration->p.alignment);
if (pos->dummy)
goto end;
- if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_write_le(pos->base, unsigned long, pos->offset,
- integer_declaration->len, v);
- else
- bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
- integer_declaration->len, v);
+ if (!integer_declaration->signedness) {
+ if (integer_declaration->byte_order == LITTLE_ENDIAN)
+ bt_bitfield_write_le(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ integer_definition->value._unsigned);
+ else
+ bt_bitfield_write_be(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ integer_definition->value._unsigned);
+ } else {
+ if (integer_declaration->byte_order == LITTLE_ENDIAN)
+ bt_bitfield_write_le(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ integer_definition->value._signed);
+ else
+ bt_bitfield_write_be(pos->base, unsigned long,
+ pos->offset, integer_declaration->len,
+ integer_definition->value._signed);
+ }
end:
ctf_move_pos(pos, integer_declaration->len);
}
#include <babeltrace/ctf/types.h>
-void ctf_sequence_begin(struct stream_pos *ppos,
- const struct declaration_sequence *sequence_declaration)
+void ctf_sequence_rw(struct stream_pos *ppos, struct definition *definition)
{
+ struct declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
- ctf_align_pos(pos, sequence_declaration->p.alignment);
-}
-
-void ctf_sequence_end(struct stream_pos *pos,
- const struct declaration_sequence *sequence_declaration)
-{
+ ctf_align_pos(pos, declaration->alignment);
+ sequence_rw(ppos, definition);
}
ctf_move_pos(src, len);
}
-void ctf_string_read(char **dest, struct stream_pos *psrc,
- const struct declaration_string *string_declaration)
+void ctf_string_read(struct stream_pos *ppos, struct definition *definition)
{
- struct ctf_stream_pos *src = ctf_pos(psrc);
+ struct definition_string *string_definition =
+ container_of(definition, struct definition_string, p);
+ const struct declaration_string *string_declaration =
+ string_definition->declaration;
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
size_t len;
char *srcaddr;
- ctf_align_pos(src, string_declaration->p.alignment);
- srcaddr = ctf_get_pos_addr(src);
+ ctf_align_pos(pos, string_declaration->p.alignment);
+ srcaddr = ctf_get_pos_addr(pos);
len = strlen(srcaddr) + 1;
- *dest = g_realloc(*dest, len);
- strcpy(*dest, srcaddr);
- ctf_move_pos(src, len);
+ if (string_definition->alloc_len < len) {
+ string_definition->value =
+ g_realloc(string_definition->value, len);
+ string_definition->alloc_len = len;
+ }
+ memcpy(string_definition->value, srcaddr, len);
+ string_definition->len = len;
+ ctf_move_pos(pos, len);
}
-void ctf_string_write(struct stream_pos *pdest, const char *src,
- const struct declaration_string *string_declaration)
+void ctf_string_write(struct stream_pos *ppos,
+ struct definition *definition)
{
- struct ctf_stream_pos *dest = ctf_pos(pdest);
+ struct definition_string *string_definition =
+ container_of(definition, struct definition_string, p);
+ const struct declaration_string *string_declaration =
+ string_definition->declaration;
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
size_t len;
char *destaddr;
- ctf_align_pos(dest, string_declaration->p.alignment);
- len = strlen(src) + 1;
- if (dest->dummy)
+ ctf_align_pos(pos, string_declaration->p.alignment);
+ assert(string_definition->value != NULL);
+ len = string_definition->len;
+ if (pos->dummy)
goto end;
- destaddr = ctf_get_pos_addr(dest);
- strcpy(destaddr, src);
+ destaddr = ctf_get_pos_addr(pos);
+ strcpy(destaddr, string_definition->value);
end:
- ctf_move_pos(dest, len);
-}
-
-void ctf_string_free_temp(char *string)
-{
- g_free(string);
+ ctf_move_pos(pos, len);
}
#include <babeltrace/ctf/types.h>
-void ctf_struct_begin(struct stream_pos *ppos,
- const struct declaration_struct *struct_declaration)
+void ctf_struct_rw(struct stream_pos *ppos, struct definition *definition)
{
+ struct declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
- ctf_align_pos(pos, struct_declaration->p.alignment);
-}
-
-void ctf_struct_end(struct stream_pos *ppos,
- const struct declaration_struct *struct_declaration)
-{
+ ctf_align_pos(pos, declaration->alignment);
+ struct_rw(ppos, definition);
}
#include <babeltrace/ctf/types.h>
-void ctf_variant_begin(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration)
+void ctf_variant_rw(struct stream_pos *ppos, struct definition *definition)
{
-}
+ struct declaration *declaration = definition->declaration;
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
-void ctf_variant_end(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration)
-{
+ ctf_align_pos(pos, declaration->alignment);
+ variant_rw(ppos, definition);
}
* the size is returned.
*/
-uint64_t ctf_uint_read(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration);
-int64_t ctf_int_read(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration);
-void ctf_uint_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- uint64_t v);
-void ctf_int_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- int64_t v);
-
-double ctf_double_read(struct stream_pos *pos,
- const struct declaration_float *src);
-void ctf_double_write(struct stream_pos *pos,
- const struct declaration_float *dest,
- double v);
-long double ctf_ldouble_read(struct stream_pos *pos,
- const struct declaration_float *src);
-void ctf_ldouble_write(struct stream_pos *pos,
- const struct declaration_float *dest,
- long double v);
-void ctf_float_copy(struct stream_pos *destp,
- struct stream_pos *srcp,
- const struct declaration_float *float_declaration);
-
-void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
- const struct declaration_string *string_declaration);
-void ctf_string_read(char **dest, struct stream_pos *src,
- const struct declaration_string *string_declaration);
-void ctf_string_write(struct stream_pos *dest, const char *src,
- const struct declaration_string *string_declaration);
-void ctf_string_free_temp(char *string);
-
-GArray *ctf_enum_read(struct stream_pos *pos,
- const struct declaration_enum *src);
-void ctf_enum_write(struct stream_pos *pos,
- const struct declaration_enum *dest,
- GQuark q);
-void ctf_struct_begin(struct stream_pos *pos,
- const struct declaration_struct *struct_declaration);
-void ctf_struct_end(struct stream_pos *pos,
- const struct declaration_struct *struct_declaration);
-void ctf_variant_begin(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration);
-void ctf_variant_end(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration);
-void ctf_array_begin(struct stream_pos *pos,
- const struct declaration_array *array_declaration);
-void ctf_array_end(struct stream_pos *pos,
- const struct declaration_array *array_declaration);
-void ctf_sequence_begin(struct stream_pos *pos,
- const struct declaration_sequence *sequence_declaration);
-void ctf_sequence_end(struct stream_pos *pos,
- const struct declaration_sequence *sequence_declaration);
+void ctf_integer_read(struct stream_pos *pos, struct definition *definition);
+void ctf_integer_write(struct stream_pos *pos, struct definition *definition);
+void ctf_float_read(struct stream_pos *pos, struct definition *definition);
+void ctf_float_write(struct stream_pos *pos, struct definition *definition);
+void ctf_string_read(struct stream_pos *pos, struct definition *definition);
+void ctf_string_write(struct stream_pos *pos, struct definition *definition);
+void ctf_enum_read(struct stream_pos *pos, struct definition *definition);
+void ctf_enum_write(struct stream_pos *pos, struct definition *definition);
+void ctf_struct_rw(struct stream_pos *pos, struct definition *definition);
+void ctf_variant_rw(struct stream_pos *pos, struct definition *definition);
+void ctf_array_rw(struct stream_pos *pos, struct definition *definition);
+void ctf_sequence_rw(struct stream_pos *pos, struct definition *definition);
void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset);
struct format {
GQuark name;
- uint64_t (*uint_read)(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration);
- int64_t (*int_read)(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration);
- void (*uint_write)(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- uint64_t v);
- void (*int_write)(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- int64_t v);
-
- void (*float_copy)(struct stream_pos *destp,
- struct stream_pos *srcp,
- const struct declaration_float *float_declaration);
- double (*double_read)(struct stream_pos *pos,
- const struct declaration_float *float_declaration);
- void (*double_write)(struct stream_pos *pos,
- const struct declaration_float *float_declaration,
- double v);
- long double (*ldouble_read)(struct stream_pos *pos,
- const struct declaration_float *float_declaration);
- void (*ldouble_write)(struct stream_pos *pos,
- const struct declaration_float *float_declaration,
- long double v);
-
- void (*string_copy)(struct stream_pos *dest, struct stream_pos *src,
- const struct declaration_string *string_declaration);
- void (*string_read)(char **dest, struct stream_pos *src,
- const struct declaration_string *string_declaration);
- void (*string_write)(struct stream_pos *dest, const char *src,
- const struct declaration_string *string_declaration);
- void (*string_free_temp)(char *string);
-
- /*
- * enum_read returns a GArray of GQuark. Must be released with
- * g_array_unref().
- */
- GArray *(*enum_read)(struct stream_pos *pos,
- const struct declaration_enum *src);
- void (*enum_write)(struct stream_pos *pos,
- const struct declaration_enum *dest,
- GQuark q);
- void (*struct_begin)(struct stream_pos *pos,
- const struct declaration_struct *struct_declaration);
- void (*struct_end)(struct stream_pos *pos,
- const struct declaration_struct *struct_declaration);
- void (*variant_begin)(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration);
- void (*variant_end)(struct stream_pos *pos,
- const struct declaration_variant *variant_declaration);
- void (*array_begin)(struct stream_pos *pos,
- const struct declaration_array *array_declaration);
- void (*array_end)(struct stream_pos *pos,
- const struct declaration_array *array_declaration);
- void (*sequence_begin)(struct stream_pos *pos,
- const struct declaration_sequence *sequence_declaration);
- void (*sequence_end)(struct stream_pos *pos,
- const struct declaration_sequence *sequence_declaration);
struct trace_descriptor *(*open_trace)(const char *path, int flags);
void (*close_trace)(struct trace_descriptor *descriptor);
};
struct format;
struct definition;
-/* Parent of per-plugin positions */
-struct stream_pos {
-};
-
/* type scope */
struct declaration_scope {
/* Hash table mapping type name GQuark to "struct declaration" */
* definition_free called with definition ref is decremented to 0.
*/
void (*definition_free)(struct definition *definition);
- /*
- * Definition copy function. Knows how to find the child
- * definition from the parent definition.
- */
- void (*copy)(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition);
};
struct definition {
int ref; /* number of references to the definition */
};
+typedef void (*rw_dispatch)(struct stream_pos *pos,
+ struct definition *definition);
+
+/* Parent of per-plugin positions */
+struct stream_pos {
+ /* read/write dispatch table. Specific to plugin used for stream. */
+ rw_dispatch *rw_table; /* rw dispatch table */
+};
+
+static inline
+void generic_rw(struct stream_pos *pos, struct definition *definition)
+{
+ enum ctf_type_id dispatch_id = definition->declaration->id;
+ rw_dispatch call;
+
+ assert(pos->rw_table[dispatch_id] != NULL);
+ call = pos->rw_table[dispatch_id];
+ call(pos, definition);
+}
+
/*
* Because we address in bits, bitfields end up being exactly the same as
* integers, except that their read/write functions must be able to deal with
struct definition_float {
struct definition p;
struct declaration_float *declaration;
+ struct definition_integer *sign;
+ struct definition_integer *mantissa;
+ struct definition_integer *exp;
/* Last values read */
long double value;
};
struct definition p;
struct declaration_string *declaration;
char *value; /* freed at definition_string teardown */
+ size_t len, alloc_len;
};
struct declaration_field {
struct field *
struct_definition_get_field_from_index(struct definition_struct *struct_definition,
int index);
+void struct_rw(struct stream_pos *pos, struct definition *definition);
/*
* The tag enumeration is validated to ensure that it contains only mappings
* to.
*/
struct field *variant_get_current_field(struct definition_variant *variant);
+void variant_rw(struct stream_pos *pos, struct definition *definition);
/*
* elem_declaration passed as parameter now belongs to the array. No
struct declaration_scope *parent_scope);
uint64_t array_len(struct definition_array *array);
struct definition *array_index(struct definition_array *array, uint64_t i);
+void array_rw(struct stream_pos *pos, struct definition *definition);
/*
* int_declaration and elem_declaration passed as parameter now belong
struct declaration_scope *parent_scope);
uint64_t sequence_len(struct definition_sequence *sequence);
struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i);
+void sequence_rw(struct stream_pos *pos, struct definition *definition);
/*
* in: path (dot separated), out: q (GArray of GQuark)
static
void _array_definition_free(struct definition *definition);
-void array_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
+void array_rw(struct stream_pos *pos, struct definition *definition)
{
- struct definition_array *array =
+ struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
- struct declaration_array *array_declaration = array->declaration;
+ const struct declaration_array *array_declaration =
+ array_definition->declaration;
uint64_t i;
- fsrc->array_begin(src, array_declaration);
- if (fdest)
- fdest->array_begin(dest, array_declaration);
-
+ /* No need to align, because the first field will align itself. */
for (i = 0; i < array_declaration->len; i++) {
struct definition *elem =
- g_array_index(array->elems, struct field, i).definition;
- elem->declaration->copy(dest, fdest, src, fsrc, elem);
+ g_array_index(array_definition->elems, struct field, i).definition;
+ generic_rw(pos, elem);
}
- fsrc->array_end(src, array_declaration);
- if (fdest)
- fdest->array_end(dest, array_declaration);
}
static
declaration->id = CTF_TYPE_ARRAY;
/* No need to align the array, the first element will align itself */
declaration->alignment = 1;
- declaration->copy = array_copy;
declaration->declaration_free = _array_declaration_free;
declaration->definition_new = _array_definition_new;
declaration->definition_free = _array_definition_free;
return g_hash_table_size(enum_declaration->table.quark_to_range_set);
}
-void enum_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
-{
- struct definition_enum *_enum =
- container_of(definition, struct definition_enum, p);
- struct declaration_enum *enum_declaration= _enum->declaration;
- GArray *array;
- GQuark v;
-
- array = fsrc->enum_read(src, enum_declaration);
- assert(array);
- /* unref previous array */
- if (_enum->value)
- g_array_unref(_enum->value);
- _enum->value = array;
- /*
- * Arbitrarily choose the first one.
- * TODO: use direct underlying declaration read/write intead. Not doing it for
- * now to test enum read and write code.
- */
- v = g_array_index(array, GQuark, 0);
- if (fdest)
- fdest->enum_write(dest, enum_declaration, v);
-}
-
static
void _enum_declaration_free(struct declaration *declaration)
{
enum_declaration->integer_declaration = integer_declaration;
enum_declaration->p.id = CTF_TYPE_ENUM;
enum_declaration->p.alignment = 1;
- enum_declaration->p.copy = enum_copy;
enum_declaration->p.declaration_free = _enum_declaration_free;
enum_declaration->p.definition_new = _enum_definition_new;
enum_declaration->p.definition_free = _enum_definition_free;
static
void _float_definition_free(struct definition *definition);
-void float_copy(struct stream_pos *destp,
- const struct format *fdest,
- struct stream_pos *srcp,
- const struct format *fsrc,
- struct definition *definition)
-{
- struct definition_float *_float =
- container_of(definition, struct definition_float, p);
- struct declaration_float *float_declaration = _float->declaration;
- long double v;
-
- v = fsrc->ldouble_read(srcp, float_declaration);
- _float->value = v;
- if (fdest)
- fdest->ldouble_write(destp, float_declaration, v);
-}
-
static
void _float_declaration_free(struct declaration *declaration)
{
declaration = &float_declaration->p;
declaration->id = CTF_TYPE_FLOAT;
declaration->alignment = alignment;
- declaration->copy = float_copy;
declaration->declaration_free = _float_declaration_free;
declaration->definition_new = _float_definition_new;
declaration->definition_free = _float_definition_free;
struct declaration_float *float_declaration =
container_of(declaration, struct declaration_float, p);
struct definition_float *_float;
+ struct definition *tmp;
_float = g_new(struct definition_float, 1);
declaration_ref(&float_declaration->p);
_float->p.declaration = declaration;
_float->declaration = float_declaration;
+ if (float_declaration->byte_order == LITTLE_ENDIAN) {
+ tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
+ parent_scope, g_quark_from_static_string("mantissa"), 0);
+ _float->mantissa = container_of(tmp, struct definition_integer, p);
+ tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
+ parent_scope, g_quark_from_static_string("exp"), 1);
+ _float->exp = container_of(tmp, struct definition_integer, p);
+ tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
+ parent_scope, g_quark_from_static_string("sign"), 2);
+ _float->sign = container_of(tmp, struct definition_integer, p);
+ } else {
+ tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
+ parent_scope, g_quark_from_static_string("sign"), 0);
+ _float->sign = container_of(tmp, struct definition_integer, p);
+ tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
+ parent_scope, g_quark_from_static_string("exp"), 1);
+ _float->exp = container_of(tmp, struct definition_integer, p);
+ tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
+ parent_scope, g_quark_from_static_string("mantissa"), 2);
+ _float->mantissa = container_of(tmp, struct definition_integer, p);
+ }
_float->p.ref = 1;
_float->p.index = index;
_float->value = 0.0;
struct definition_float *_float =
container_of(definition, struct definition_float, p);
+ definition_unref(&_float->sign->p);
+ definition_unref(&_float->exp->p);
+ definition_unref(&_float->mantissa->p);
declaration_unref(_float->p.declaration);
g_free(_float);
}
static
void _integer_definition_free(struct definition *definition);
-void integer_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
-{
- struct definition_integer *integer =
- container_of(definition, struct definition_integer, p);
- struct declaration_integer *integer_declaration = integer->declaration;
-
- if (!integer_declaration->signedness) {
- uint64_t v;
-
- v = fsrc->uint_read(src, integer_declaration);
- integer->value._unsigned = v;
- if (fdest)
- fdest->uint_write(dest, integer_declaration, v);
- } else {
- int64_t v;
-
- v = fsrc->int_read(src, integer_declaration);
- integer->value._signed = v;
- if (fdest)
- fdest->int_write(dest, integer_declaration, v);
- }
-}
-
static
void _integer_declaration_free(struct declaration *declaration)
{
integer_declaration = g_new(struct declaration_integer, 1);
integer_declaration->p.id = CTF_TYPE_INTEGER;
integer_declaration->p.alignment = alignment;
- integer_declaration->p.copy = integer_copy;
integer_declaration->p.declaration_free = _integer_declaration_free;
integer_declaration->p.definition_free = _integer_definition_free;
integer_declaration->p.definition_new = _integer_definition_new;
static
void _sequence_definition_free(struct definition *definition);
-void sequence_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
+void sequence_rw(struct stream_pos *pos, struct definition *definition)
{
- struct definition_sequence *sequence =
+ struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
- struct declaration_sequence *sequence_declaration = sequence->declaration;
+ const struct declaration_sequence *sequence_declaration =
+ sequence_definition->declaration;
uint64_t len, oldlen, i;
- fsrc->sequence_begin(src, sequence_declaration);
- if (fdest)
- fdest->sequence_begin(dest, sequence_declaration);
-
- sequence->len->p.declaration->copy(dest, fdest, src, fsrc,
- &sequence->len->p);
- len = sequence->len->value._unsigned;
- g_array_set_size(sequence->elems, len);
+ generic_rw(pos, &sequence_definition->len->p);
+ len = sequence_definition->len->value._unsigned;
/*
* Yes, large sequences could be _painfully slow_ to parse due
* to memory allocation for each event read. At least, never
* One should always look at the sequence->len->value._unsigned
* value for that.
*/
- oldlen = sequence->elems->len;
+ oldlen = sequence_definition->elems->len;
if (oldlen < len)
- g_array_set_size(sequence->elems, len);
+ g_array_set_size(sequence_definition->elems, len);
for (i = oldlen; i < len; i++) {
struct field *field;
(void) g_string_free(str, TRUE);
name = g_quark_from_string(str->str);
- field = &g_array_index(sequence->elems, struct field, i);
+ field = &g_array_index(sequence_definition->elems, struct field, i);
field->name = name;
field->definition = sequence_declaration->elem->definition_new(sequence_declaration->elem,
- sequence->scope,
+ sequence_definition->scope,
name, i);
- field->definition->declaration->copy(dest, fdest, src, fsrc, field->definition);
+ generic_rw(pos, field->definition);
}
- fsrc->sequence_end(src, sequence_declaration);
- if (fdest)
- fdest->sequence_end(dest, sequence_declaration);
}
static
sequence_declaration->scope = new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_SEQUENCE;
declaration->alignment = max(len_declaration->p.alignment, elem_declaration->alignment);
- declaration->copy = sequence_copy;
declaration->declaration_free = _sequence_declaration_free;
declaration->definition_new = _sequence_definition_new;
declaration->definition_free = _sequence_definition_free;
static
void _string_definition_free(struct definition *definition);
-void string_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
-{
- struct definition_string *string =
- container_of(definition, struct definition_string, p);
- struct declaration_string *string_declaration = string->declaration;
-
- fsrc->string_read(&string->value, src, string_declaration);
- if (fdest)
- fdest->string_write(dest, string->value, string_declaration);
-}
-
static
void _string_declaration_free(struct declaration *declaration)
{
string_declaration = g_new(struct declaration_string, 1);
string_declaration->p.id = CTF_TYPE_STRING;
string_declaration->p.alignment = CHAR_BIT;
- string_declaration->p.copy = string_copy;
string_declaration->p.declaration_free = _string_declaration_free;
string_declaration->p.definition_new = _string_definition_new;
string_declaration->p.definition_free = _string_definition_free;
string->p.ref = 1;
string->p.index = index;
string->value = NULL;
+ string->len = 0;
+ string->alloc_len = 0;
return &string->p;
}
static
void _struct_definition_free(struct definition *definition);
-void struct_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
+void struct_rw(struct stream_pos *ppos, struct definition *definition)
{
- struct definition_struct *_struct =
+ struct definition_struct *struct_definition =
container_of(definition, struct definition_struct, p);
- struct declaration_struct *struct_declaration = _struct->declaration;
unsigned long i;
- fsrc->struct_begin(src, struct_declaration);
- if (fdest)
- fdest->struct_begin(dest, struct_declaration);
-
- for (i = 0; i < _struct->fields->len; i++) {
- struct field *field = &g_array_index(_struct->fields,
+ for (i = 0; i < struct_definition->fields->len; i++) {
+ struct field *field = &g_array_index(struct_definition->fields,
struct field, i);
- struct declaration *field_declaration = field->definition->declaration;
-
- field_declaration->copy(dest, fdest, src, fsrc, field->definition);
-
+ generic_rw(ppos, field->definition);
}
- fsrc->struct_end(src, struct_declaration);
- if (fdest)
- fdest->struct_end(dest, struct_declaration);
}
static
struct_declaration->scope = new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_STRUCT;
declaration->alignment = 1;
- declaration->copy = struct_copy;
declaration->declaration_free = _struct_declaration_free;
declaration->definition_new = _struct_definition_new;
declaration->definition_free = _struct_definition_free;
static
void _variant_definition_free(struct definition *definition);
-void variant_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct definition *definition)
+void variant_rw(struct stream_pos *ppos, struct definition *definition)
{
- struct definition_variant *variant =
+ struct definition_variant *variant_definition =
container_of(definition, struct definition_variant, p);
- struct declaration_variant *variant_declaration = variant->declaration;
struct field *field;
- struct declaration *field_declaration;
-
- fsrc->variant_begin(src, variant_declaration);
- if (fdest)
- fdest->variant_begin(dest, variant_declaration);
-
- field = variant_get_current_field(variant);
- field_declaration = field->definition->declaration;
- field_declaration->copy(dest, fdest, src, fsrc, field->definition);
- fsrc->variant_end(src, variant_declaration);
- if (fdest)
- fdest->variant_end(dest, variant_declaration);
+ field = variant_get_current_field(variant_definition);
+ generic_rw(ppos, field->definition);
}
static
untagged_variant_declaration->scope = new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_UNTAGGED_VARIANT;
declaration->alignment = 1;
- declaration->copy = NULL;
declaration->declaration_free = _untagged_variant_declaration_free;
declaration->definition_new = NULL;
declaration->definition_free = NULL;
append_scope_path(tag, variant_declaration->tag_name);
declaration->id = CTF_TYPE_VARIANT;
declaration->alignment = 1;
- declaration->copy = variant_copy;
declaration->declaration_free = _variant_declaration_free;
declaration->definition_new = _variant_definition_new;
declaration->definition_free = _variant_definition_free;