Fix: writer.py: make `uint64_ft` a 64-bit (instead of 32-bit) int FT
[babeltrace.git] / bindings / python / babeltrace / babeltrace / writer.py
index 12e040229c00bc8a20dc9db2bd845ae2b07db8d7..5d6660845de4f8cf2ef9d644c167137292001af0 100644 (file)
@@ -27,6 +27,7 @@
 import babeltrace.common as common
 import bt2
 
+
 class EnumerationMapping:
     """
     Mapping from an enumeration label to a range of integers.
@@ -334,6 +335,7 @@ _ENCODING_TO_BT2_ENCODING = {
     common.CTFStringEncoding.UTF8: bt2.Encoding.UTF8,
 }
 
+
 class FieldDeclaration:
     """
     Base class of all field declarations. This class is not meant to
@@ -679,7 +681,6 @@ class FloatingPointFieldDeclaration(FieldDeclaration):
             raise TypeError(
                 "Could not get Floating point exponent digit count")
 
-
     @exponent_digits.setter
     def exponent_digits(self, exponent_digits):
         try:
@@ -705,7 +706,6 @@ class FloatingPointFieldDeclaration(FieldDeclaration):
             raise TypeError(
                 "Could not get Floating point mantissa digit count")
 
-
     @mantissa_digits.setter
     def mantissa_digits(self, mantissa_digits):
         try:
@@ -803,7 +803,7 @@ class VariantFieldDeclaration(FieldDeclaration):
             raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
 
         self._field_type = bt2.VariantFieldType(tag_name=tag_name,
-                                        tag_field_type=enum_tag._field_type)
+                                                tag_field_type=enum_tag._field_type)
         super().__init__()
 
     @property
@@ -1583,6 +1583,7 @@ class Event:
         except:
             raise ValueError("Invalid stream context field.")
 
+
 class StreamClass:
     """
     A stream class contains the properties of specific
@@ -1606,8 +1607,8 @@ class StreamClass:
         try:
             # Set default event header and packet context.
             event_header_type = bt2.StructureFieldType()
-            uint32_ft = bt2.IntegerFieldType(32, is_signed=False)
-            uint64_ft = bt2.IntegerFieldType(32, is_signed=False)
+            uint32_ft = bt2.IntegerFieldType(32)
+            uint64_ft = bt2.IntegerFieldType(64)
             event_header_type.append_field('id', uint32_ft)
             event_header_type.append_field('timestamp', uint64_ft)
 
@@ -1745,11 +1746,13 @@ class StreamClass:
 
     @packet_context_type.setter
     def packet_context_type(self, field_type):
-        if not isinstance(field_type, StructureFieldDeclaration):
+        if field_type is not None and not isinstance(field_type,
+                                                     StructureFieldDeclaration):
             raise TypeError("field_type argument must be of type StructureFieldDeclaration.")
 
+        bt2_field_type = None if field_type is None else field_type._field_type
         try:
-            self._stream_class.packet_context_field_type = field_type._field_type
+            self._stream_class.packet_context_field_type = bt2_field_type
         except:
             raise ValueError("Failed to set packet context type.")
 
@@ -1779,11 +1782,13 @@ class StreamClass:
 
     @event_context_type.setter
     def event_context_type(self, field_type):
-        if not isinstance(field_type, StructureFieldDeclaration):
+        if field_type is not None and not isinstance(field_type,
+                                                     StructureFieldDeclaration):
             raise TypeError("field_type argument must be of type StructureFieldDeclaration.")
 
+        bt2_field_type = None if field_type is None else field_type._field_type
         try:
-            self._stream_class.event_context_field_type = field_type._field_type
+            self._stream_class.event_context_field_type = bt2_field_type
         except:
             raise ValueError("Failed to set event context type.")
 
@@ -1883,7 +1888,10 @@ class Stream:
         :exc:`ValueError` is raised on error.
         """
 
-        self._s.flush()
+        try:
+            self._s.flush()
+        except:
+            raise ValueError('Failed to flush CTF writer stream')
 
 
 class Writer:
@@ -1947,7 +1955,7 @@ class Writer:
             raise TypeError("Value type is not supported.")
 
         try:
-            self._w.trace.env += {name: value}
+            self._w.trace.env[name] = value
         except:
             raise ValueError("Could not add environment field to trace.")
 
This page took 0.026087 seconds and 4 git commands to generate.