Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-3321

Address precision loss compiler warnings in bson

    • Type: Icon: Build Failure Build Failure
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: bson-4.15.0
    • Component/s: BSON
    • Labels:

      Compiling bson on OSX produces a number of precision loss warnings (-Wshorten-64-to-32)

      rake compile
      [bson] Warning: No private key present, creating unsigned gem.
      mkdir -p tmp/x86_64-darwin21/bson_native/3.1.2
      cd tmp/x86_64-darwin21/bson_native/3.1.2
      /Users/alex/.rvm/rubies/ruby-3.1.2/bin/ruby -I. -r.rake-compiler-siteconf.rb ../../../../ext/bson/extconf.rb
      [bson] Warning: No private key present, creating unsigned gem.
      creating Makefile
      cd -
      cd tmp/x86_64-darwin21/bson_native/3.1.2
      /usr/bin/make
      compiling ../../../../ext/bson/bytebuf.c
      ../../../../ext/bson/bytebuf.c:90:19: warning: implicit conversion loses integer precision: 'unsigned long' to 'unsigned int' [-Wshorten-64-to-32]
        return UINT2NUM(READ_SIZE(b));
               ~~~~~~~~ ^~~~~~~~~~~~
      ../../../../ext/bson/bson-native.h:59:36: note: expanded from macro 'READ_SIZE'
        (byte_buffer_ptr->write_position - byte_buffer_ptr->read_position)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ../../../../ext/bson/bytebuf.c:98:21: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
        return INT2NUM(b->read_position);
               ~~~~~~~ ~~~^~~~~~~~~~~~~
      ../../../../ext/bson/bytebuf.c:116:21: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
        return INT2NUM(b->write_position);
               ~~~~~~~ ~~~^~~~~~~~~~~~~~
      3 warnings generated.
      compiling ../../../../ext/bson/endian.c
      compiling ../../../../ext/bson/init.c
      compiling ../../../../ext/bson/libbson-utf8.c
      compiling ../../../../ext/bson/read.c
      ../../../../ext/bson/read.c:33:49: warning: function 'pvt_raise_decode_error' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
      void pvt_raise_decode_error(volatile VALUE msg) {
                                                      ^
      ../../../../ext/bson/read.c:136:27: warning: implicit conversion loses integer precision: 'long' to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
        const uint32_t length = FIX2LONG(i);
                       ~~~~~~   ^~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:46:22: note: expanded from macro 'FIX2LONG'
      #define FIX2LONG     RB_FIX2LONG          /**< @old{RB_FIX2LONG} */
                           ^
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:53:22: note: expanded from macro 'RB_FIX2LONG'
      #define RB_FIX2LONG  rb_fix2long          /**< @alias{rb_fix2long} */
                           ^
      ../../../../ext/bson/read.c:157:5: warning: variable 'result' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
          default:
          ^~~~~~~
      ../../../../ext/bson/read.c:161:10: note: uninitialized use occurs here
        return result;
               ^~~~~~
      ../../../../ext/bson/read.c:146:15: note: initialize the variable 'result' to silence this warning
        VALUE result;
                    ^
                     = 0
      3 warnings generated.
      compiling ../../../../ext/bson/util.c
      compiling ../../../../ext/bson/write.c
      ../../../../ext/bson/write.c:224:14: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
          length = RSTRING_LEN(utf8_string);
                 ~ ^~~~~~~~~~~~~~~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
      #define RSTRING_LEN       RSTRING_LEN
                                ^
      ../../../../ext/bson/write.c:247:12: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        length = RSTRING_LEN(utf8_string);
               ~ ^~~~~~~~~~~~~~~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
      #define RSTRING_LEN       RSTRING_LEN
                                ^
      ../../../../ext/bson/write.c:291:12: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        length = RSTRING_LEN(string);
               ~ ^~~~~~~~~~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
      #define RSTRING_LEN       RSTRING_LEN
                                ^
      ../../../../ext/bson/write.c:320:26: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        const int32_t length = RSTRING_LEN(symbol_str);
                      ~~~~~~   ^~~~~~~~~~~~~~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
      #define RSTRING_LEN       RSTRING_LEN
                                ^
      ../../../../ext/bson/write.c:333:29: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        pvt_put_cstring(b, c_str, length, "Key");
        ~~~~~~~~~~~~~~~           ^~~~~~
      ../../../../ext/bson/write.c:363:35: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        pvt_replace_int32(b, _position, NUM2LONG(newval));
        ~~~~~~~~~~~~~~~~~               ^~~~~~~~~~~~~~~~
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:51:22: note: expanded from macro 'NUM2LONG'
      #define NUM2LONG     RB_NUM2LONG          /**< @old{RB_NUM2LONG} */
                           ^
      /Users/alex/.rvm/rubies/ruby-3.1.2/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:57:22: note: expanded from macro 'RB_NUM2LONG'
      #define RB_NUM2LONG  rb_num2long_inline   /**< @alias{rb_num2long_inline} */
                           ^
      ../../../../ext/bson/write.c:363:24: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        pvt_replace_int32(b, _position, NUM2LONG(newval));
        ~~~~~~~~~~~~~~~~~    ^~~~~~~~~
      ../../../../ext/bson/write.c:522:29: warning: implicit conversion loses integer precision: 'unsigned long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        new_length = new_position - position;
                   ~ ~~~~~~~~~~~~~^~~~~~~~~~
      ../../../../ext/bson/write.c:523:24: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        pvt_replace_int32(b, position, new_length);
        ~~~~~~~~~~~~~~~~~    ^~~~~~~~
      ../../../../ext/bson/write.c:667:29: warning: implicit conversion loses integer precision: 'unsigned long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        new_length = new_position - position;
                   ~ ~~~~~~~~~~~~~^~~~~~~~~~
      ../../../../ext/bson/write.c:668:24: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        pvt_replace_int32(b, position, new_length);
        ~~~~~~~~~~~~~~~~~    ^~~~~~~~
      11 warnings generated.
      linking shared-object bson_native.bundle
      cd -
      mkdir -p tmp/x86_64-darwin21/stage/lib
      /usr/bin/make install target_prefix=
      /usr/local/opt/coreutils/bin/ginstall -c -m 0755 bson_native.bundle /Users/alex/Workspace/bson-ruby/lib
      cp tmp/x86_64-darwin21/bson_native/3.1.2/bson_native.bundle tmp/x86_64-darwin21/stage/lib/bson_native.bundle
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: