[CDRIVER-4674] Pointless code in bson-clock.c Created: 06/Jul/23  Updated: 28/Oct/23  Resolved: 20/Jul/23

Status: Closed
Project: C Driver
Component/s: BSON
Affects Version/s: 1.24.1
Fix Version/s: 1.24.3

Type: Bug Priority: Minor - P4
Reporter: Ryan Schmidt Assignee: Josh Siegel (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by Githook User [ 28/Jul/23 ]

Author:

{'name': 'Joshua Siegel', 'email': '39130209+joshbsiegel@users.noreply.github.com', 'username': 'joshbsiegel'}

Message: CDRIVER-4674 remove unnecessary code from bson-clock.c (#1348)
Branch: r1.24
https://github.com/mongodb/mongo-c-driver/commit/48d25775cd655e3d46b476c510234f76e98fcde7

Comment by Githook User [ 20/Jul/23 ]

Author:

{'name': 'Joshua Siegel', 'email': '39130209+joshbsiegel@users.noreply.github.com', 'username': 'joshbsiegel'}

Message: CDRIVER-4674 remove unnecessary code from bson-clock.c (#1348)
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6d2be25206daeb55960c84a5f129b226f0a25393

Comment by Githook User [ 20/Jul/23 ]

Author:

{'name': 'Joshua Siegel', 'email': '39130209+joshbsiegel@users.noreply.github.com', 'username': 'joshbsiegel'}

Message: CDRIVER-4674 remove unnecessary code from bson-clock.c (#1348)
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6d2be25206daeb55960c84a5f129b226f0a25393

Comment by PM Bot [ 06/Jul/23 ]

Hi ryandesign, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:21:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.