//struct lttng_mystruct teststr1;
};
-
+#if 0
static inline size_t lttng_get_size_mystruct2(
struct lttng_mystruct2 * obj)
{
return sizeof(struct lttng_mystruct2);
}
+#endif //0
static inline size_t lttng_get_alignment_mystruct2(
struct lttng_mystruct2 *obj)
}
static inline void lttng_write_mystruct2(
- void **to_base,
+ void *buffer,
+ size_t *to_base,
size_t *to,
void **from,
size_t *len,
size_t align, size;
align = lttng_get_alignment_mystruct2(obj);
- size = lttng_get_size_mystruct2(obj);
+ //size = lttng_get_size_mystruct2(obj);
+ size = sizeof(struct lttng_mystruct2);
if(*len == 0) {
*to += ltt_align(*to, align); /* align output */
#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+#if 0
static inline size_t lttng_get_size_array_mystruct_myarray(
lttng_array_mystruct_myarray obj)
{
return sizeof(lttng_array_mystruct_myarray);
}
+#endif //0
static inline size_t lttng_get_alignment_array_mystruct_myarray(
lttng_array_mystruct_myarray obj)
static inline void lttng_write_array_mystruct_myarray(
- void **to_base,
+ void *buffer,
+ size_t *to_base,
size_t *to,
void **from,
size_t *len,
size_t align, size;
align = lttng_get_alignment_array_mystruct_myarray(obj);
- size = lttng_get_size_array_mystruct_myarray(obj);
+ //size = lttng_get_size_array_mystruct_myarray(obj);
+ size = sizeof(lttng_array_mystruct_myarray);
if(*len == 0) {
*to += ltt_align(*to, align); /* align output */
}
*len += size;
+#if 0
+ /* For varlen child : let the child align itself. */
+ for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_mystruct_myarray; i++) {
+ lttng_write_child(buffer, to_base, to, from, len, obj[i]);
+ }
+#endif //0
+
}
double *array;
};
-
+#if 0
static inline size_t lttng_get_size_sequence_mystruct_mysequence(
lttng_sequence_mystruct_mysequence *obj)
{
return size;
}
+#endif //0
static inline size_t lttng_get_alignment_sequence_mystruct_mysequence(
lttng_sequence_mystruct_mysequence *obj)
static inline void lttng_write_sequence_mystruct_mysequence(
- void **to_base,
+ void *buffer,
+ size_t *to_base,
size_t *to,
void **from,
size_t *len,
lttng_sequence_mystruct_mysequence *obj)
{
size_t align;
- void *varfrom;
- size_t varlen=0;
+ size_t size;
/* Flush pending memcpy */
if(*len != 0) {
- memcpy(*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
}
+ *to += *len;
+ *len = 0;
align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
//no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
*to += ltt_align(*to, align); /* *len = 0 in this function */
/* Copy members */
- *to += ltt_align(*to, sizeof(unsigned int));
- varfrom = &obj->len;
- varlen += sizeof(unsigned int);
- memcpy(*to_base+*to, varfrom, varlen);
- *to += varlen;
- varlen = 0;
-
- *to += ltt_align(*to, sizeof(double));
- varfrom = obj->array;
- varlen += obj->len * sizeof(double);
- memcpy(*to_base+*to, varfrom, varlen);
- *to += varlen;
- varlen = 0;
+ size = sizeof(unsigned int);
+ *to += ltt_align(*to, size);
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, &obj->len, size);
+ *to += size;
+
+ size = sizeof(double);
+ *to += ltt_align(*to, size);
+ size = obj->len * sizeof(double);
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj->array, size);
+ *to += size;
+#if 0
+ /* If varlen child : let child align itself */
+ for(unsigned int i=0; i<obj->len; i++) {
+ lttng_write_child(buffer, to_base, to, from, len, obj->array[i]);
+ }
+#endif //0
+
/* Realign the *to_base on arch size, set *to to 0 */
*to = ltt_align(*to, sizeof(void *));
unsigned long myulong;
};
-
+#if 0
static inline size_t lttng_get_size_mystruct_myunion(
union lttng_mystruct_myunion *obj)
{
return sizeof(union lttng_mystruct_myunion);
}
-
+#endif //0
static inline size_t lttng_get_alignment_mystruct_myunion(
union lttng_mystruct_myunion *obj)
static inline void lttng_write_mystruct_myunion(
- void **to_base,
+ void *buffer,
+ size_t *to_base,
size_t *to,
void **from,
size_t *len,
size_t align, size;
align = lttng_get_alignment_mystruct_myunion(obj);
- size = lttng_get_size_mystruct_myunion(obj);
+ //size = lttng_get_size_mystruct_myunion(obj);
+ size = sizeof(union lttng_mystruct_myunion);
if(*len == 0) {
*to += ltt_align(*to, align); /* align output */
union lttng_mystruct_myunion myunion;
};
+#if 0
static inline size_t lttng_get_size_mystruct(
struct lttng_mystruct *obj)
{
return size;
}
-
+#endif //0
static inline size_t lttng_get_alignment_mystruct(
struct lttng_mystruct *obj)
}
static inline void lttng_write_mystruct(
- void **to_base,
+ void *buffer,
+ size_t *to_base,
size_t *to,
void **from,
size_t *len,
size += ltt_align(*to+*len, size) + size;
*len += size;
- lttng_write_mystruct2(to_base, to, from, len, &obj->teststr);
+ lttng_write_mystruct2(buffer, to_base, to, from, len, &obj->teststr);
- lttng_write_array_mystruct_myarray(to_base, to, from, len, obj->myarray);
+ lttng_write_array_mystruct_myarray(buffer, to_base, to, from, len, obj->myarray);
/* Variable length field */
- lttng_write_sequence_mystruct_mysequence(to_base, to, from, len, &obj->mysequence);
- //*to = 0; /* Force the compiler to know it's 0 */
+ lttng_write_sequence_mystruct_mysequence(buffer, to_base, to, from, len, &obj->mysequence);
/* After this previous write, we are sure that *to is 0, and *to_base is
* aligned on the architecture size : to rest of alignment will be calculated
* statically. */
- lttng_write_mystruct_myunion(to_base, to, from, len, &obj->myunion);
+ lttng_write_mystruct_myunion(buffer, to_base, to, from, len, &obj->myunion);
/* Don't forget to flush last write..... */
}
test.mysequence.len = 20;
test.mysequence.array = malloc(20);
- size_t size = lttng_get_size_mystruct(&test);
- size_t align = lttng_get_alignment_mystruct(&test);
-
- void *buf = malloc(align + size);
- void *to_base = buf; /* the buffer is allocated on arch_size alignment */
+ //size_t size = lttng_get_size_mystruct(&test);
+ //size_t align = lttng_get_alignment_mystruct(&test);
+ //
+ size_t to_base = 0; /* the buffer is allocated on arch_size alignment */
size_t to = 0;
void *from = &test;
size_t len = 0;
- lttng_write_mystruct(&to_base, &to, &from, &len, &test);
+ /* Get size */
+ lttng_write_mystruct(NULL, &to_base, &to, &from, &len, &test);
+ /* Size = to_base + to + len */
+
+ void *buffer = malloc(to_base + to + len);
+ to_base = 0; /* the buffer is allocated on arch_size alignment */
+ to = 0;
+ from = &test;
+ len = 0;
+
+ lttng_write_mystruct(buffer, &to_base, &to, &from, &len, &test);
/* Final flush */
/* Flush pending memcpy */
if(len != 0) {
- memcpy(to_base+to, from, len);
+ // Assert buffer != NULL */
+ memcpy(buffer+to_base+to, from, len);
to += len;
from += len;
len = 0;
}
free(test.mysequence.array);
- free(buf);
+ free(buffer);
}