+#endif //0
+
+
+
+
+
+/*****************************************************************************
+ *Function name
+ * compute_fields_offsets : set the precomputable offset of the fields
+ *Input params
+ * fac : facility
+ * field : the field
+ * offset : pointer to the current offset, must be incremented
+ ****************************************************************************/
+
+
+void compute_fields_offsets(LttTracefile *tf,
+ LttFacility *fac, LttField *field, off_t *offset, void *root)
+{
+ LttType *type = &field->field_type;
+
+ switch(type->type_class) {
+ case LTT_INT_FIXED:
+ case LTT_UINT_FIXED:
+ case LTT_POINTER:
+ case LTT_CHAR:
+ case LTT_UCHAR:
+ case LTT_SHORT:
+ case LTT_USHORT:
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ if(field->fixed_root == FIELD_VARIABLE) {
+ /* Align offset on type size */
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ /* Increment offset */
+ *offset += field->field_size;
+ } else {
+ //g_debug("type before offset : %llu %llu %u\n", *offset,
+ // field->offset_root,
+ // field->field_size);
+ *offset = field->offset_root;
+ *offset += field->field_size;
+ //g_debug("type after offset : %llu\n", *offset);
+ }
+ break;
+ case LTT_STRING:
+ if(field->fixed_root == FIELD_VARIABLE) {
+ field->offset_root = *offset;
+ }
+ *offset += strlen((gchar*)(root+*offset)) + 1;
+ /* Realign the data */
+ *offset += ltt_align(*offset, fac->pointer_size,
+ fac->alignment);
+ break;
+ case LTT_ARRAY:
+ g_assert(type->fields->len == 1);
+ {
+ off_t local_offset;
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ field->array_offset = *offset;
+ }
+
+ if(field->field_size != 0) {
+ /* Increment offset */
+ /* field_size is the array size in bytes */
+ *offset = field->offset_root + field->field_size;
+ } else {
+ guint i;
+ *offset = field->array_offset;
+ field->dynamic_offsets = g_array_set_size(field->dynamic_offsets,
+ 0);
+ for(i=0; i<type->size; i++) {
+ g_array_append_val(field->dynamic_offsets, *offset);
+ compute_fields_offsets(tf, fac, child, offset, root);
+ }
+ }
+ // local_offset = field->array_offset;
+ // /* Set the offset at position 0 */
+ // compute_fields_offsets(tf, fac, child, &local_offset, root);
+ }
+ break;
+ case LTT_SEQUENCE:
+ g_assert(type->fields->len == 2);
+ {
+ off_t local_offset;
+ LttField *child;
+ guint i;
+ guint num_elem;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+
+ child = &g_array_index(type->fields, LttField, 0);
+ compute_fields_offsets(tf, fac, child, offset, root);
+ child = &g_array_index(type->fields, LttField, 1);
+ *offset += ltt_align(*offset, get_alignment(child),
+ fac->alignment);
+ field->array_offset = *offset;
+
+ } else {
+ child = &g_array_index(type->fields, LttField, 1);
+ }
+ *offset = field->array_offset;
+ field->dynamic_offsets = g_array_set_size(field->dynamic_offsets,
+ 0);
+ num_elem = ltt_event_field_element_number(&tf->event, field);
+ for(i=0; i<num_elem; i++) {
+ g_array_append_val(field->dynamic_offsets, *offset);
+ compute_fields_offsets(tf, fac, child, offset, root);
+ }
+ g_assert(num_elem == field->dynamic_offsets->len);
+
+ /* Realign the data */
+ *offset += ltt_align(*offset, fac->pointer_size,
+ fac->alignment);
+
+ // local_offset = field->array_offset;
+ // /* Set the offset at position 0 */
+ // compute_fields_offsets(tf, fac, child, &local_offset, root);
+ }
+ break;
+ case LTT_STRUCT:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(fac, field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ } else {
+ *offset = field->offset_root;
+ }
+ for(i=0; i<type->fields->len; i++) {
+ child = &g_array_index(type->fields, LttField, i);
+ compute_fields_offsets(tf, fac, child, offset, root);
+ }
+ }
+ break;
+ case LTT_UNION:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ }
+ for(i=0; i<type->fields->len; i++) {
+ *offset = field->offset_root;
+ child = &g_array_index(type->fields, LttField, i);
+ compute_fields_offsets(tf, fac, child, offset, root);
+ }
+ *offset = field->offset_root + field->field_size;
+ }
+ break;
+ case LTT_NONE:
+ default:
+ g_error("compute_fields_offsets : unknown type");
+ }
+
+}
+
+
+/*****************************************************************************
+ *Function name
+ * compute_offsets : set the dynamically computable offsets of an event type
+ *Input params
+ * tf : tracefile
+ * event : event type
+ *
+ ****************************************************************************/
+void compute_offsets(LttTracefile *tf, LttFacility *fac,
+ LttEventType *event, off_t *offset, void *root)
+{
+ guint i;