Skip to content

bson_atomic_int32_fetch_add uses a header declared type for the int32_t argument #1250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2023

Conversation

Downchuck
Copy link
Contributor

bson_atomic_int32_fetch_add is generated with the type DECL_ATOMIC_INTEGRAL_INT32, but is coded as int32_t in two places. This results in an incompatible pointer types error when MSVC is true from the bson-atomic.h file.

This patch resolves the error, tested and resolved with clang-cl for compatibility.

@vector-of-bool vector-of-bool self-assigned this Apr 27, 2023
@vector-of-bool
Copy link
Contributor

After looking at the problem and the code in question, I'm thinking there may be a better solution pending more refactoring, but I think this is sufficient to keep things working for now. Thank you for your contribution!

I'll let CI run its checks, then it should be good to merge.

@vector-of-bool
Copy link
Contributor

It looks like the macro is not defined on many compilation environments. This may require further refactoring. I will investigate some more possible changes to the API.

@Downchuck
Copy link
Contributor Author

Yeah I'd just pop it in around line 375 of bson atomic around that else statement, but I'm worried about that emulate 32 but statement.

Should I update the PR to do it so we can at least see how many more builds pass?

@vector-of-bool
Copy link
Contributor

Sure, give it a try.

@Downchuck
Copy link
Contributor Author

I was so uncomfortable with this tweak, I made a typo in the commit message. I agree there's good reason to do a little refactoring. Hopefully the failed checks give a little more signal.

@Downchuck
Copy link
Contributor Author

@vector-of-bool - checking in - looks like it needs an approve to run the autotests.

@vector-of-bool
Copy link
Contributor

Sorry for the delay. Been quite distracted.

Taking a quick look, I suspect you meant to define to "int32_t", instead of "int32"? If you can confirm/fix then I'll get this running again.

@Downchuck
Copy link
Contributor Author

@vector-of-bool I'm really not sure: there's that note of "Other compilers that we support provide generic intrinsics" above, which uses int32 - though it also has that emulate flag. The fall-through statements in this section seem to suggest that's where it'll land for these other compilers (which I haven't used).

int32_t certainly makes more sense at first glance, it's just the surrounding code I took a hint from.

@vector-of-bool
Copy link
Contributor

In those other contexts, the int32 is token-pasted to form other identifiers, including int32_t, so you probably want int32_t here.

@Downchuck
Copy link
Contributor Author

Seemed a mostly OK build check.

@vector-of-bool
Copy link
Contributor

This looks like to be a safe solution for the time being. I'll probably refactor the atomic.h header in the future to make things cleaner. Thank you for finding this issue! Apologies for the long delay, though.

@vector-of-bool vector-of-bool merged commit 6a0a3d1 into mongodb:master May 24, 2023
@Downchuck
Copy link
Contributor Author

@vector-of-bool You have an idea when this libbson update will go out in a release zip? Hoping to change a cmake file to point to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants