Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4674

Pointless code in bson-clock.c

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.24.3
    • Affects Version/s: 1.24.1
    • Component/s: BSON
    • Labels:
      None

      Summary

      These lines in bson-clock.c are pointless and can be removed:

      https://github.com/mongodb/mongo-c-driver/blob/9e7bf882d1fb4e16f5701a152f5c664088ffcda3/src/libbson/src/bson/bson-clock.c#L128-L130

      The code essentially says if clock_gettime and CLOCK_MONOTONIC are defined, use them, otherwise if we're on macOS, use clock_gettime_nsec_np and CLOCK_UPTIME_RAW.

      This makes no sense since clock_gettime and CLOCK_MONOTONIC were introduced in OS X 10.11 and clock_gettime_nsec_np and CLOCK_UPTIME_RAW were introduced in macOS 10.12. So what happens on OS X 10.11 and later is that the first block of code that uses clock_gettime gets used and this compiles fine. And on OS X 10.10 and earlier the second block that uses clock_gettime_nsec_np is used which fails to compile.

      Environment

      libbson 1.24.1

      OS X 10.10 (or earlier) x86_64 (but this is irrelevant)

      Apple LLVM version 7.0.2 (clang-700.1.81) (but this is irrelevant)

      How to Reproduce

      Build libbson 1.24.1 (with the patch to fix CDRIVER-4609) on OS X 10.10 or earlier

      Additional Background

      The previous version of the don't-have-clock_gettime fallback code for macOS compiled fine because it used mach_timebase_info and mach_absolute_time which exist on every version of macOS. Now that this code was removed, the headers for the mach time functions can be removed too:

      https://github.com/mongodb/mongo-c-driver/blob/9e7bf882d1fb4e16f5701a152f5c664088ffcda3/src/libbson/src/bson/bson-clock.c#L18-L23

            Assignee:
            josh.siegel@mongodb.com Josh Siegel (Inactive)
            Reporter:
            ryandesign Ryan Schmidt
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: