Uploaded image for project: 'PHP Legacy Driver'
  1. PHP Legacy Driver
  2. PHP-1484

Some PHP MongoDB driver tests for 32-bit integers fail on big endian platform

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: 1.6.11
    • Fix Version/s: None
    • Component/s: pecl-mongo
    • Labels:
      None
    • Environment:
    • # Replies:
      1
    • Last comment by Customer:
      true

      Description

      I built the PHP MongoDB driver on a Linux Z system (big endian) and found that some of the tests provided with the driver, relating to 32-bit integers, failed.

      The following lists the failures and shows the 'diff' between expected and actual output:

      Disabled "mongo.native_long" INI option stores 32-bits of 64-bit integers [tests/generic/ini-mongo_native_long_64bit-002.phpt]
      001+ int(4294967295)
      001- int(-1)

      "mongo.native_long" INI option has no effect on 32-bit integers [tests/generic/ini-mongo_native_long_64bit-004.phpt]
      002+ int(2249056121)
      002- int(-2045911175)

      Long integer insertion [tests/generic/long_int_64bit-001.phpt]
      001+ int(4294967295)
      001- int(-1)
      003+ int(4294967295)
      003- int(-1)

      MongoInt32 constructed with 64-bit integer [tests/generic/mongoint32_64bit-002.phpt]
      001+ int(2249056121)
      002+ int(2249056121)
      003+ int(2249056121)
      004+ int(2249056121)
      001- int(-2045911175)
      002- int(-2045911175)
      003- int(-2045911175)
      004- int(-2045911175)

      For a big endian system the macro MONGO_32 effectively strips off any bits that are more significant than the first 32, but does not do this for a little endian system.
      Changing the macro so that it does strip such bits for a little endian system causes the above tests to fail in the same way that they fail for a big endian system (and does not impact the result of other tests provided with the driver, running in standalone setup).

      The change was made to 2 files, diffs as follows (for version 1.6.11):

      bson.h
      137c137
      < # define MONGO_32(b) (b)

      > # define MONGO_32(b) ((b) & 0xffffffff)

      mcon/bson_helpers.h
      38c38
      < # define MONGO_32(b) (b)

      > # define MONGO_32(b) ((b) & 0xffffffff)

      Please can you resolve this issue.

      Perhaps it can be resolved by changing the MONGO_32 macro in the way described above (as I guess it is only intended to operate on 32-bit items) ?

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                3 years, 43 weeks, 2 days ago
                Date of 1st Reply: