Skip to content

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Oct 10, 2024

Deprecate bson-atomic.h and bson-cmp.h

Background & Motivation

These headers are planned for removal in C driver 2.0. The utility APIs are not essential to working with BSON or using the libbson API.

For simplicity, the headers were copied and symbols renamed. No attempt is made to reduce duplication between the deprecated API and non-deprecated API.

Verified with this patch build: https://spruce.mongodb.com/version/6707be7f32bc5700071e890c

Placement of BSON_GNUC_DEPRECATED in inline functions

I attempted to add BSON_GNUC_DEPRECATED after the inline function parameter list for consistency with other uses of BSON_GNUC_DEPRECATED in function declarations:

static BSON_INLINE int
bson_fn (void) BSON_GNUC_DEPRECATED
{
   return 123;
}

But this resulted in:

error: GCC does not allow '__deprecated__' attribute in this position on a function definition [-Werror,-Wgcc-compat]
 1239 | bson_fn (void) BSON_GNUC_DEPRECATED
      |                ^
/Users/kevin.albertson/code/tasks/mongo-c-driver-2.0/src/libbson/src/bson/bson-macros.h:313:46: note: expanded from macro 'BSON_GNUC_DEPRECATED'
  313 | #define BSON_GNUC_DEPRECATED __attribute__ ((__deprecated__))
      |                                              ^
1 error generated.

Therefore, the BSON_GNUC_DEPRECATED is added after the return type:

static BSON_INLINE int BSON_GNUC_DEPRECATED
bson_foo (void)
{
   return 123;
}

@kevinAlbs kevinAlbs marked this pull request as ready for review October 10, 2024 18:46
Copy link
Collaborator Author

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the reviews.

Should these new headers be named common-*-private.h

Updated the atomic and cmp headers for consistency with (most) other common headers.

This also applies to mcd-string.h and bson-dsl.h

I prefer to do in a follow-up PR to limit scope of this PR.

Latest changes verified with this patch build

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated.

@kevinAlbs kevinAlbs requested review from a user and eramongodb October 14, 2024 13:32
Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last concern; otherwise, LGTM.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! It's nice to pare down the supported API.

Comment on lines 28 to +29
#include <bson-dsl.h>
#include <common-atomic-private.h>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noticing that bson-dsl and common-atomic-private are sensitive to include order; the 'atomic' module redefines a macro (BSON_IF_GNU_LIKE) that's also used by bson-dsl. I just filed a separate issue about this, https://jira.mongodb.org/browse/CDRIVER-5755

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The undef appears to be restored later within bson-atomic.h / common-atomic-private.h:

#ifdef BSON_USE_LEGACY_GCC_ATOMICS
#undef BSON_IF_GNU_LIKE

Is then later restored with:

#ifdef BSON_USE_LEGACY_GCC_ATOMICS
#undef BSON_IF_GNU_LIKE
#define BSON_IF_GNU_LIKE(...) __VA_ARGS__
#endif

@kevinAlbs kevinAlbs merged commit a1c99c4 into mongodb:master Oct 14, 2024
42 of 44 checks passed
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.

3 participants