[PATCH v3 2/5] libqmi-glib: handle gfloats on big-endian systems

Thomas WeiƟschuh thomas at t-8ch.de
Thu Feb 22 22:43:17 UTC 2018


---
 build-aux/qmi-codegen/VariableInteger.py | 4 ++--
 src/libqmi-glib/qmi-message.c            | 6 +++++-
 src/libqmi-glib/qmi-message.h            | 2 ++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index 12d2a77..ecfb1b8 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -66,7 +66,7 @@ class VariableInteger(Variable):
                          'private_format' : self.private_format,
                          'len'            : self.guint_sized_size }
 
-        if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat':
+        if self.private_format not in ('guint8', 'gint8'):
             translations['endian'] = ' ' + self.endian + ','
         else:
             translations['endian'] = ''
@@ -193,7 +193,7 @@ class VariableInteger(Variable):
                          'common_format'  : common_format,
                          'common_cast'    : common_cast }
 
-        if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat':
+        if self.private_format not in ('guint8', 'gint8'):
             translations['endian'] = ' ' + self.endian + ','
         else:
             translations['endian'] = ''
diff --git a/src/libqmi-glib/qmi-message.c b/src/libqmi-glib/qmi-message.c
index 308fc00..65a18bb 100644
--- a/src/libqmi-glib/qmi-message.c
+++ b/src/libqmi-glib/qmi-message.c
@@ -1158,6 +1158,7 @@ gboolean
 qmi_message_tlv_read_gfloat (QmiMessage  *self,
                              gsize        tlv_offset,
                              gsize       *offset,
+                             QmiEndian    endian,
                              gfloat      *out,
                              GError     **error)
 {
@@ -1170,8 +1171,11 @@ qmi_message_tlv_read_gfloat (QmiMessage  *self,
     if (!(ptr = tlv_error_if_read_overflow (self, tlv_offset, *offset, 4, error)))
         return FALSE;
 
-    /* Yeah, do this for now */
     memcpy (out, ptr, 4);
+    if (endian == QMI_ENDIAN_BIG)
+        *out = __QMI_GFLOAT_FROM_BE (*out);
+    else
+        *out = __QMI_GFLOAT_FROM_LE (*out);
     *offset = *offset + 4;
     return TRUE;
 }
diff --git a/src/libqmi-glib/qmi-message.h b/src/libqmi-glib/qmi-message.h
index c15f071..9f502c9 100644
--- a/src/libqmi-glib/qmi-message.h
+++ b/src/libqmi-glib/qmi-message.h
@@ -834,6 +834,7 @@ gboolean qmi_message_tlv_read_sized_guint (QmiMessage  *self,
  * @self: a #QmiMessage.
  * @tlv_offset: offset that was returned by qmi_message_tlv_read_init().
  * @offset: address of a the offset within the TLV value.
+ * @endian: source endianness, which will be swapped to host byte order if necessary.
  * @out: return location for the read #gfloat.
  * @error: return location for error or %NULL.
  *
@@ -850,6 +851,7 @@ gboolean qmi_message_tlv_read_sized_guint (QmiMessage  *self,
 gboolean qmi_message_tlv_read_gfloat (QmiMessage  *self,
                                       gsize        tlv_offset,
                                       gsize       *offset,
+                                      QmiEndian    endian,
                                       gfloat      *out,
                                       GError     **error);
 
-- 
2.16.2



More information about the libqmi-devel mailing list