lib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()
[babeltrace.git] / lib / ctf-writer / serialize.c
index f20ad405cb99cdcebbb76ac1a4f9ae0c53d9e6a7..ce6b96b34d3ca9dedc7f92c74b3a44c7df77a318 100644 (file)
@@ -42,6 +42,8 @@
 #include <babeltrace/bitfield-internal.h>
 #include <babeltrace/compat/fcntl-internal.h>
 #include <babeltrace/types.h>
+#include <babeltrace/common-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <glib.h>
 
 #if (FLT_RADIX != 2)
@@ -59,26 +61,26 @@ union intval {
  * optimisation.
  */
 static
-int aligned_integer_write(struct bt_ctf_stream_pos *pos,
+int aligned_integer_write(struct bt_stream_pos *pos,
                union intval value, unsigned int alignment, unsigned int size,
-               bt_bool is_signed, enum bt_ctf_byte_order byte_order)
+               bt_bool is_signed, enum bt_byte_order byte_order)
 {
-       bt_bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER); /* reverse byte order */
+       bt_bool rbo = (byte_order != BT_MY_BYTE_ORDER); /* reverse byte order */
 
-       if (!bt_ctf_stream_pos_align(pos, alignment))
+       if (!bt_stream_pos_align(pos, alignment))
                return -EFAULT;
 
-       if (!bt_ctf_stream_pos_access_ok(pos, size))
+       if (!bt_stream_pos_access_ok(pos, size))
                return -EFAULT;
 
-       assert(!(pos->offset % CHAR_BIT));
+       BT_ASSERT(!(pos->offset % CHAR_BIT));
        if (!is_signed) {
                switch (size) {
                case 8:
                {
                        uint8_t v = value.unsignd;
 
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 16:
@@ -87,7 +89,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT16_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 32:
@@ -96,7 +98,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT32_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 64:
@@ -105,7 +107,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT64_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                default:
@@ -117,7 +119,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                {
                        uint8_t v = value.signd;
 
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 16:
@@ -126,7 +128,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT16_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 32:
@@ -135,7 +137,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT32_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                case 64:
@@ -144,7 +146,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
                        if (rbo)
                                v = GUINT64_SWAP_LE_BE(v);
-                       memcpy(bt_ctf_stream_pos_get_addr(pos), &v, sizeof(v));
+                       memcpy(bt_stream_pos_get_addr(pos), &v, sizeof(v));
                        break;
                }
                default:
@@ -152,15 +154,15 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                }
        }
 
-       if (!bt_ctf_stream_pos_move(pos, size))
+       if (!bt_stream_pos_move(pos, size))
                return -EFAULT;
        return 0;
 }
 
 static
-int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
+int integer_write(struct bt_stream_pos *pos, union intval value,
        unsigned int alignment, unsigned int size, bt_bool is_signed,
-       enum bt_ctf_byte_order byte_order)
+       enum bt_byte_order byte_order)
 {
        if (!(alignment % CHAR_BIT)
            && !(size % CHAR_BIT)) {
@@ -168,14 +170,14 @@ int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
                        size, is_signed, byte_order);
        }
 
-       if (!bt_ctf_stream_pos_align(pos, alignment))
+       if (!bt_stream_pos_align(pos, alignment))
                return -EFAULT;
 
-       if (!bt_ctf_stream_pos_access_ok(pos, size))
+       if (!bt_stream_pos_access_ok(pos, size))
                return -EFAULT;
 
        if (!is_signed) {
-               if (byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN)
+               if (byte_order == BT_BYTE_ORDER_LITTLE_ENDIAN)
                        bt_bitfield_write_le(mmap_align_addr(pos->base_mma) +
                                pos->mmap_base_offset, unsigned char,
                                pos->offset, size, value.unsignd);
@@ -184,7 +186,7 @@ int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
                                pos->mmap_base_offset, unsigned char,
                                pos->offset, size, value.unsignd);
        } else {
-               if (byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN)
+               if (byte_order == BT_BYTE_ORDER_LITTLE_ENDIAN)
                        bt_bitfield_write_le(mmap_align_addr(pos->base_mma) +
                                pos->mmap_base_offset, unsigned char,
                                pos->offset, size, value.signd);
@@ -194,23 +196,23 @@ int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
                                pos->offset, size, value.signd);
        }
 
-       if (!bt_ctf_stream_pos_move(pos, size))
+       if (!bt_stream_pos_move(pos, size))
                return -EFAULT;
        return 0;
 }
 
 BT_HIDDEN
-int bt_ctf_field_integer_write(struct bt_ctf_field_integer *int_field,
-               struct bt_ctf_stream_pos *pos,
-               enum bt_ctf_byte_order native_byte_order)
+int bt_field_integer_write(struct bt_field_integer *int_field,
+               struct bt_stream_pos *pos,
+               enum bt_byte_order native_byte_order)
 {
-       struct bt_ctf_field_type *type = int_field->parent.type;
-       struct bt_ctf_field_type_integer *int_type = (void *) type;
-       enum bt_ctf_byte_order byte_order;
+       struct bt_field_type *type = int_field->parent.type;
+       struct bt_field_type_integer *int_type = (void *) type;
+       enum bt_byte_order byte_order;
        union intval value;
 
        byte_order = int_type->user_byte_order;
-       if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+       if (byte_order == BT_BYTE_ORDER_NATIVE) {
                byte_order = native_byte_order;
        }
 
@@ -222,19 +224,19 @@ int bt_ctf_field_integer_write(struct bt_ctf_field_integer *int_field,
 }
 
 BT_HIDDEN
-int bt_ctf_field_floating_point_write(
-               struct bt_ctf_field_floating_point *flt_field,
-               struct bt_ctf_stream_pos *pos,
-               enum bt_ctf_byte_order native_byte_order)
+int bt_field_floating_point_write(
+               struct bt_field_floating_point *flt_field,
+               struct bt_stream_pos *pos,
+               enum bt_byte_order native_byte_order)
 {
-       struct bt_ctf_field_type *type = flt_field->parent.type;
-       struct bt_ctf_field_type_floating_point *flt_type = (void *) type;
-       enum bt_ctf_byte_order byte_order;
+       struct bt_field_type *type = flt_field->parent.type;
+       struct bt_field_type_floating_point *flt_type = (void *) type;
+       enum bt_byte_order byte_order;
        union intval value;
        unsigned int size;
 
        byte_order = flt_type->user_byte_order;
-       if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+       if (byte_order == BT_BYTE_ORDER_NATIVE) {
                byte_order = native_byte_order;
        }
 
@@ -265,12 +267,12 @@ int bt_ctf_field_floating_point_write(
 }
 
 BT_HIDDEN
-void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
+void bt_stream_pos_packet_seek(struct bt_stream_pos *pos, size_t index,
        int whence)
 {
        int ret;
 
-       assert(whence == SEEK_CUR && index == 0);
+       BT_ASSERT(whence == SEEK_CUR && index == 0);
 
        if (pos->base_mma) {
                /* unmap old base */
@@ -284,12 +286,12 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
 
        /* The writer will add padding */
        pos->mmap_offset += pos->packet_size / CHAR_BIT;
-       pos->packet_size = getpagesize() * 8 * CHAR_BIT;
+       pos->packet_size = PACKET_LEN_INCREMENT;
        do {
                ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
                        pos->packet_size / CHAR_BIT);
        } while (ret == EINTR);
-       assert(ret == 0);
+       BT_ASSERT(ret == 0);
        pos->offset = 0;
 
        /* map new base. Need mapping length from header. */
This page took 0.028155 seconds and 4 git commands to generate.