Skip to content

CDRIVER-2837 remove deprecated bson_oid_init_sequence #1913

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
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Unreleased (2.0.0)

## Changes


* Passing `batchSize:0` as an option to `mongoc_client_watch`, `mongoc_database_watch`, or `mongoc_collection_watch`
now applies `batchSize:0` to the `aggregate` command. Useful to request an immediate cursor. Previously the value
was ignored.
* `bson_oid_init_sequence` is removed. Use `bson_oid_init` instead.

## Removals

Expand Down
30 changes: 0 additions & 30 deletions src/libbson/doc/bson_oid_init_sequence.rst

This file was deleted.

1 change: 0 additions & 1 deletion src/libbson/doc/bson_oid_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ You can validate that a string containing a hex-encoded ObjectID is valid using
bson_oid_init_from_data
bson_oid_init_from_string
bson_oid_init_from_string_unsafe
bson_oid_init_sequence
bson_oid_is_valid
bson_oid_to_string

Expand Down
13 changes: 0 additions & 13 deletions src/libbson/src/bson/bson-context-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ _bson_context_set_oid_rand (bson_context_t *context, bson_oid_t *oid);
void
_bson_context_set_oid_seq32 (bson_context_t *context, bson_oid_t *oid);

/**
* @brief Write a 64-bit counter from the given context into the OID. Increments
* the context's sequence counter.
*
* @param context The context with the counter to get+update
* @param oid The OID to modify
*
* @note Only used by the deprecated @ref bson_oid_init_sequence
*/
void
_bson_context_set_oid_seq64 (bson_context_t *context, bson_oid_t *oid);


BSON_END_DECLS


Expand Down
12 changes: 0 additions & 12 deletions src/libbson/src/bson/bson-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ _bson_context_set_oid_seq32 (bson_context_t *context, /* IN */
memcpy (&oid->bytes[BSON_OID_SEQ32_OFFSET], ((uint8_t *) &seq) + 1, BSON_OID_SEQ32_SIZE);
}


void
_bson_context_set_oid_seq64 (bson_context_t *context, /* IN */
bson_oid_t *oid) /* OUT */
{
uint64_t seq =
(uint64_t) mcommon_atomic_int64_fetch_add ((int64_t *) &context->seq64, 1, mcommon_memory_order_seq_cst);

seq = BSON_UINT64_TO_BE (seq);
memcpy (&oid->bytes[BSON_OID_SEQ64_OFFSET], &seq, BSON_OID_SEQ64_SIZE);
}

/*
* --------------------------------------------------------------------------
*
Expand Down
29 changes: 6 additions & 23 deletions src/libbson/src/bson/bson-oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ BSON_MAYBE_UNUSED static const uint16_t gHexCharPairs[] = {
#endif
};

static BSON_INLINE void
_oid_init (bson_oid_t *oid, bson_context_t *context, bool add_random)
void
bson_oid_init (bson_oid_t *oid, /* OUT */
bson_context_t *context) /* IN */
{
BSON_ASSERT (oid);
if (!context) {
Expand All @@ -90,27 +91,9 @@ _oid_init (bson_oid_t *oid, bson_context_t *context, bool add_random)
oid->bytes[1] = (uint8_t) (now >> 16);
oid->bytes[2] = (uint8_t) (now >> 8);
oid->bytes[3] = (uint8_t) (now >> 0);
// Maybe add randomness if the caller wants it
if (add_random) {
_bson_context_set_oid_rand (context, oid);
_bson_context_set_oid_seq32 (context, oid);
} else {
_bson_context_set_oid_seq64 (context, oid);
}
}

void
bson_oid_init_sequence (bson_oid_t *oid, /* OUT */
bson_context_t *context) /* IN */
{
_oid_init (oid, context, false /* no randomness */);
}

void
bson_oid_init (bson_oid_t *oid, /* OUT */
bson_context_t *context) /* IN */
{
_oid_init (oid, context, true /* add randomness */);
// Add randomness
_bson_context_set_oid_rand (context, oid);
_bson_context_set_oid_seq32 (context, oid);
}


Expand Down
2 changes: 0 additions & 2 deletions src/libbson/src/bson/bson-oid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ BSON_EXPORT (void)
bson_oid_init_from_data (bson_oid_t *oid, const uint8_t *data);
BSON_EXPORT (void)
bson_oid_init_from_string (bson_oid_t *oid, const char *str);
BSON_DEPRECATED_FOR (bson_oid_init)
BSON_EXPORT (void) bson_oid_init_sequence (bson_oid_t *oid, bson_context_t *context);
BSON_EXPORT (void)
bson_oid_to_string (const bson_oid_t *oid, char str[25]);

Expand Down
23 changes: 0 additions & 23 deletions src/libbson/tests/test-oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,6 @@ test_bson_oid_init (void)
}


static void
test_bson_oid_init_sequence (void)
{
bson_context_t *context;
bson_oid_t oid;
bson_oid_t oid2;
int i;

BEGIN_IGNORE_DEPRECATIONS
context = bson_context_new (BSON_CONTEXT_NONE);
bson_oid_init_sequence (&oid, context);
for (i = 0; i < 10000; i++) {
bson_oid_init_sequence (&oid2, context);
BSON_ASSERT (false == bson_oid_equal (&oid, &oid2));
BSON_ASSERT (0 > bson_oid_compare (&oid, &oid2));
bson_oid_copy (&oid2, &oid);
}
bson_context_destroy (context);
END_IGNORE_DEPRECATIONS
}


static char *
get_time_as_string (const bson_oid_t *oid)
{
Expand Down Expand Up @@ -476,7 +454,6 @@ test_oid_install (TestSuite *suite)
{
TestSuite_Add (suite, "/bson/oid/init", test_bson_oid_init);
TestSuite_Add (suite, "/bson/oid/init_from_string", test_bson_oid_init_from_string);
TestSuite_Add (suite, "/bson/oid/init_sequence", test_bson_oid_init_sequence);
TestSuite_Add (suite, "/bson/oid/init_with_threads", test_bson_oid_init_with_threads);
TestSuite_Add (suite, "/bson/oid/hash", test_bson_oid_hash);
TestSuite_Add (suite, "/bson/oid/compare", test_bson_oid_compare);
Expand Down