[gjs: 1/3] arg-cache: Don't set always the array length to an ulong in little endian




commit 0bf49f9a5e502571177e86862211f2e00c855161
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Aug 21 14:26:33 2020 +0200

    arg-cache: Don't set always the array length to an ulong in little endian
    
    The size value we get may be in some cases a signed integer and in some others
    an unsigned one. However in case we're using a little endian
    architecture we always save it as the GIArgument unsigned value, while
    we read it depending on the type tag.
    
    This seems to work properly in all the architectures, but the assumtion
    is wrong in armhf, causing a test failure:
    
      it('marshals an array with a 64-bit length parameter', function () {
        expect(() => GIMarshallingTests.array_in_guint64_len([-1, 0, 1, 2]))
          .not.toThrow();
      });
    
      ERROR:/usr/share/gobject-introspection-1.0/tests/gimarshallingtests.c
        gi_marshalling_tests_array_in_guint64_len:
          assertion failed (length == 4): (-498216206332 == 4)
    
    At the end the switch check is just an extra operation that will ensure
    us safety, at a really minimal cost at this point (given we've got the tag
    anyways).
    
    Closes: #342

 gi/arg-cache.cpp | 8 --------
 1 file changed, 8 deletions(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index ab8c0f84..a0451d24 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -101,13 +101,6 @@ static void gjs_destroy_notify_callback(void* data) {
 
 static void gjs_g_argument_set_array_length(GITypeTag tag, GIArgument* arg,
                                             size_t value) {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-    // In a little endian system, the first bytes of an unsigned long value are
-    // the same value, downcasted, and no code is needed. Also, we ignore the
-    // sign, as we're just moving bits here.
-    (void)tag;
-    arg->v_ulong = value;
-#else
     switch (tag) {
         case GI_TYPE_TAG_INT8:
             gjs_arg_set<int8_t>(arg, value);
@@ -134,7 +127,6 @@ static void gjs_g_argument_set_array_length(GITypeTag tag, GIArgument* arg,
             gjs_arg_set<uint64_t>(arg, value);
             break;
     }
-#endif
 }
 
 GJS_JSAPI_RETURN_CONVENTION


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]