Skip to content

CDRIVER-5702 rename and relocate common headers #1771

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 15 commits into from
Oct 15, 2024
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
3 changes: 1 addition & 2 deletions .evergreen/scripts/check-preludes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

MONGOC_PREFIX = Path("src/libmongoc/src/mongoc")
BSON_PREFIX = Path("src/libbson/src/bson")
COMMON_PREFIX = Path("src/common")
COMMON_PREFIX = Path("src/common/src")

checks = [
{
Expand All @@ -41,7 +41,6 @@
"name": "libbson",
"headers": list(BSON_PREFIX.glob("*.h")),
"exclusions": [
BSON_PREFIX / "bson-dsl.h",
BSON_PREFIX / "bson-prelude.h",
BSON_PREFIX / "bson.h",
],
Expand Down
4 changes: 2 additions & 2 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ if (ENABLE_DEBUG_ASSERTIONS)
endif ()

configure_file (
"${PROJECT_SOURCE_DIR}/src/common/common-config.h.in"
"${PROJECT_BINARY_DIR}/src/common/common-config.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/common-config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/src/common-config.h"
)
File renamed without changes.
10 changes: 5 additions & 5 deletions src/common/bson-dsl.md → src/common/src/bson-dsl.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using `bson-dsl.h`
# Using `common-bson-dsl-private.h`

The header `<bson-dsl.h>` exposes an embedded domain-specific language
The header `<common-bson-dsl-private.h>` exposes an embedded domain-specific language
(DSL) built upon the C99 preprocessor. The DSL emits valid C99 and C++03 code
that can be used to inspect and construct `bson_t` objects.

Expand Down Expand Up @@ -28,7 +28,7 @@ The following DSL "grammatical elements" are defined:
- [*VisitOperation*](#visitoperation)
- [*Predicate*](#predicate)

**NOTE:** The `bson-dsl.h` header is *not* a public API. It is intended for
**NOTE:** The `common-bson-dsl-private.h` header is *not* a public API. It is intended for
internal use and may be changed, broken, updated, or removed.

# Generating BSON Data
Expand Down Expand Up @@ -899,7 +899,7 @@ correction.

Unfortunately, debugging through macro definitions is still a tricky subject.

`bson-dsl.h` includes a function `_bson_dsl_debug()`, which is invoked for every
`common-bson-dsl-private.h` includes a function `_bson_dsl_debug()`, which is invoked for every
DSL subcommand, including a string expressing the arguments to the command. If
debug is "enabled" for the DSL, `_bson_dsl_debug` will write the debug output to
`stderr`. If it is "disabled", `_bson_dsl_debug` is a no-op.
Expand Down Expand Up @@ -934,7 +934,7 @@ That is, MAP accepts a name `F` and zero or more arguments as `args`. For
each argument `a` in `args`, expand one `F(x)`.

The actual definition of `MAP` is non-trivial. The definition provded in
`bson-dsl.h` can be found near the bottom of the file, and goes by the name
`common-bson-dsl-private.h` can be found near the bottom of the file, and goes by the name
`_bsonDSL_mapMacro`. It is not necessary to understand how `MAP` works to
understand the DSL.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "common-prelude.h"

#ifndef COMMON_B64_PRIVATE_H
#define COMMON_B64_PRIVATE_H
#ifndef MONGO_C_DRIVER_COMMON_B64_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_B64_PRIVATE_H

#include <bson/bson.h>

Expand Down Expand Up @@ -55,4 +55,4 @@ mcommon_b64_ntop (uint8_t const *src, size_t srclength, char *target, size_t tar
int
mcommon_b64_pton (char const *src, uint8_t *target, size_t targsize);

#endif /* COMMON_B64_PRIVATE_H */
#endif /* MONGO_C_DRIVER_COMMON_B64_PRIVATE_H */
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "common-prelude.h"

#ifndef BSON_BSON_DSL_H_INCLUDED
#define BSON_BSON_DSL_H_INCLUDED
#ifndef MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H

/**
* @file bson-dsl.h
* @file common-bson-dsl-private.h
* @brief Define a C-preprocessor DSL for working with BSON objects
*
* This file defines an embedded DSL for working with BSON objects consisely and
Expand Down Expand Up @@ -1274,4 +1274,4 @@ _bsonVisitIterAs_boolean (void)
// clang-format on


#endif // BSON_BSON_DSL_H_INCLUDED
#endif // MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "common-prelude.h"

#ifndef MONGO_C_DRIVER_COMMON_MACROS_H
#define MONGO_C_DRIVER_COMMON_MACROS_H
#ifndef MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H

/* Test only assert. Is a noop unless -DENABLE_DEBUG_ASSERTIONS=ON is set
* during configuration */
Expand Down Expand Up @@ -68,4 +68,4 @@
#define END_IGNORE_DEPRECATIONS
#endif

#endif /* COMMON_MACROS_PRIVATE_H */
#endif /* MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H */
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "common-prelude.h"

#ifndef COMMON_MD5_PRIVATE_H
#define COMMON_MD5_PRIVATE_H
#ifndef MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H

#include "bson/bson.h"

Expand All @@ -36,4 +36,4 @@ mcommon_md5_finish (bson_md5_t *pms, uint8_t digest[16]);

BSON_END_DECLS

#endif /* COMMON_MD5_PRIVATE_H */
#endif /* MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H */
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,57 @@

#include "common-prelude.h"

#ifndef MCD_STRING_H
#define MCD_STRING_H
#ifndef MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H

#include <bson/bson.h>
#include <common-macros-private.h> // BEGIN_IGNORE_DEPRECATIONS

// mcd_string_t is an internal string type intended to replace the deprecated bson_string_t.
// When bson_string_t is removed, migrate the implementation to mcd_string_t.
typedef bson_string_t mcd_string_t;
// mcommon_string_t is an internal string type intended to replace the deprecated bson_string_t.
// When bson_string_t is removed, migrate the implementation to mcommon_string_t.
typedef bson_string_t mcommon_string_t;

static BSON_INLINE mcd_string_t *
mcd_string_new (const char *str)
static BSON_INLINE mcommon_string_t *
mcommon_string_new (const char *str)
{
BEGIN_IGNORE_DEPRECATIONS
return bson_string_new (str);
END_IGNORE_DEPRECATIONS
}
static BSON_INLINE char *
mcd_string_free (mcd_string_t *string, bool free_segment)
mcommon_string_free (mcommon_string_t *string, bool free_segment)
{
BEGIN_IGNORE_DEPRECATIONS
return bson_string_free (string, free_segment);
END_IGNORE_DEPRECATIONS
}
static BSON_INLINE void
mcd_string_append (mcd_string_t *string, const char *str)
mcommon_string_append (mcommon_string_t *string, const char *str)
{
BEGIN_IGNORE_DEPRECATIONS
bson_string_append (string, str);
END_IGNORE_DEPRECATIONS
}
static BSON_INLINE void
mcd_string_append_c (mcd_string_t *string, char str)
mcommon_string_append_c (mcommon_string_t *string, char str)
{
BEGIN_IGNORE_DEPRECATIONS
bson_string_append_c (string, str);
END_IGNORE_DEPRECATIONS
}
static BSON_INLINE void
mcd_string_append_unichar (mcd_string_t *string, bson_unichar_t unichar)
mcommon_string_append_unichar (mcommon_string_t *string, bson_unichar_t unichar)
{
BEGIN_IGNORE_DEPRECATIONS
bson_string_append_unichar (string, unichar);
END_IGNORE_DEPRECATIONS
}

static BSON_INLINE void
mcd_string_append_printf (mcd_string_t *string, const char *format, ...) BSON_GNUC_PRINTF (2, 3);
mcommon_string_append_printf (mcommon_string_t *string, const char *format, ...) BSON_GNUC_PRINTF (2, 3);

static BSON_INLINE void
mcd_string_append_printf (mcd_string_t *string, const char *format, ...)
mcommon_string_append_printf (mcommon_string_t *string, const char *format, ...)
{
va_list args;
char *ret;
Expand All @@ -84,11 +84,11 @@ mcd_string_append_printf (mcd_string_t *string, const char *format, ...)
}

static BSON_INLINE void
mcd_string_truncate (mcd_string_t *string, uint32_t len)
mcommon_string_truncate (mcommon_string_t *string, uint32_t len)
{
BEGIN_IGNORE_DEPRECATIONS
bson_string_truncate (string, len);
END_IGNORE_DEPRECATIONS
}

#endif /* MCD_STRING_H */
#endif /* MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H */
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "common-config.h"
#include "common-macros-private.h"

#ifndef COMMON_THREAD_PRIVATE_H
#define COMMON_THREAD_PRIVATE_H
#ifndef MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H

#define BSON_INSIDE
#include "bson/bson-compat.h"
Expand Down Expand Up @@ -206,4 +206,4 @@ bson_shared_mutex_unlock_shared (bson_shared_mutex_t *mtx)

BSON_END_DECLS

#endif /* COMMON_THREAD_PRIVATE_H */
#endif /* MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H */
File renamed without changes.
6 changes: 3 additions & 3 deletions src/libbson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ target_include_directories(_libbson_build_interface INTERFACE
# The generated src/
${PROJECT_BINARY_DIR}/src/
# The source directories of the common lib:
${mongo-c-driver_SOURCE_DIR}/src/common/
${mongo-c-driver_SOURCE_DIR}/src/common/src/
# Generated:
${mongo-c-driver_BINARY_DIR}/src/common/
${mongo-c-driver_BINARY_DIR}/src/common/src/
)
target_link_libraries(_libbson_build_interface INTERFACE mongo::detail::c_platform)

Expand All @@ -168,7 +168,7 @@ file(GLOB_RECURSE all_sources CONFIGURE_DEPENDS
src/*.c src/*.h
# Include common library source files within libbson itself (names
# will be mangled with MCOMMON_NAME_PREFIX)
"${mongo-c-driver_SOURCE_DIR}/src/common/*.c"
"${mongo-c-driver_SOURCE_DIR}/src/common/src/*.c"
)

# List of the primary BSON library targets that we are building
Expand Down
2 changes: 1 addition & 1 deletion src/libbson/src/bson/bson-decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <bson/bson-decimal128.h>
#include <bson/bson-types.h>
#include <bson/bson-macros.h>
#include <mcd-string.h>
#include <common-string-private.h>
#include <common-cmp-private.h>


Expand Down
2 changes: 1 addition & 1 deletion src/libbson/src/bson/bson-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <bson/bson-config.h>
#include <bson/bson-error.h>
#include <bson/bson-memory.h>
#include <mcd-string.h>
#include <common-string-private.h>
#include <bson/bson-types.h>

// See `bson_strerror_r()` definition below.
Expand Down
4 changes: 2 additions & 2 deletions src/libbson/src/bson/bson-iso8601-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <bson/bson-compat.h>
#include <bson/bson-macros.h>
#include <mcd-string.h>
#include <common-string-private.h>


BSON_BEGIN_DECLS
Expand All @@ -39,7 +39,7 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error
* Appends a date formatted like "2012-12-24T12:15:30.500Z" to @str.
*/
void
_bson_iso8601_date_format (int64_t msecs_since_epoch, mcd_string_t *str);
_bson_iso8601_date_format (int64_t msecs_since_epoch, mcommon_string_t *str);

BSON_END_DECLS

Expand Down
8 changes: 4 additions & 4 deletions src/libbson/src/bson/bson-iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error


void
_bson_iso8601_date_format (int64_t msec_since_epoch, mcd_string_t *str)
_bson_iso8601_date_format (int64_t msec_since_epoch, mcommon_string_t *str)
{
time_t t;
int64_t msecs_part;
Expand All @@ -309,9 +309,9 @@ _bson_iso8601_date_format (int64_t msec_since_epoch, mcd_string_t *str)
#endif

if (msecs_part) {
mcd_string_append_printf (str, "%s.%03" PRId64 "Z", buf, msecs_part);
mcommon_string_append_printf (str, "%s.%03" PRId64 "Z", buf, msecs_part);
} else {
mcd_string_append (str, buf);
mcd_string_append_c (str, 'Z');
mcommon_string_append (str, buf);
mcommon_string_append_c (str, 'Z');
}
}
2 changes: 1 addition & 1 deletion src/libbson/src/bson/bson-keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <stdio.h>

#include <bson/bson-keys.h>
#include <mcd-string.h>
#include <common-string-private.h>
#include <common-cmp-private.h>


Expand Down
2 changes: 1 addition & 1 deletion src/libbson/src/bson/bson-oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <bson/bson-context-private.h>
#include <bson/bson-oid.h>
#include <mcd-string.h>
#include <common-string-private.h>


/*
Expand Down
8 changes: 4 additions & 4 deletions src/libbson/src/bson/bson-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <bson/bson-compat.h>
#include <bson/bson-config.h>
#include <common-cmp-private.h>
#include <mcd-string.h>
#include <common-string-private.h>
#include <bson/bson-memory.h>
#include <bson/bson-utf8.h>
#include <bson/bson-string-private.h>
Expand Down Expand Up @@ -273,7 +273,7 @@ bson_string_append_c (bson_string_t *string, /* IN */
if (BSON_UNLIKELY (string->alloc == (string->len + 1))) {
cc[0] = c;
cc[1] = '\0';
mcd_string_append (string, cc);
mcommon_string_append (string, cc);
return;
}

Expand Down Expand Up @@ -312,7 +312,7 @@ bson_string_append_unichar (bson_string_t *string, /* IN */

if (len <= 6) {
str[len] = '\0';
mcd_string_append (string, str);
mcommon_string_append (string, str);
}
}

Expand Down Expand Up @@ -345,7 +345,7 @@ bson_string_append_printf (bson_string_t *string, const char *format, ...)
va_start (args, format);
ret = bson_strdupv_printf (format, args);
va_end (args);
mcd_string_append (string, ret);
mcommon_string_append (string, ret);
bson_free (ret);
}

Expand Down
Loading