Skip to content

Commit 1392d21

Browse files
CDRIVER-5702 rename and relocate common headers (#1771)
* rename common headers to `common-*-private.h` * replace `mcd_string_` with `mcommon_string_` * relocate `src/common/*` into `src/common/src` * relocate `test-common-*` to `src/common/tests` * update macro guards for common headers --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent 4b22616 commit 1392d21

File tree

81 files changed

+608
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+608
-608
lines changed

.evergreen/scripts/check-preludes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
MONGOC_PREFIX = Path("src/libmongoc/src/mongoc")
2727
BSON_PREFIX = Path("src/libbson/src/bson")
28-
COMMON_PREFIX = Path("src/common")
28+
COMMON_PREFIX = Path("src/common/src")
2929

3030
checks = [
3131
{
@@ -41,7 +41,6 @@
4141
"name": "libbson",
4242
"headers": list(BSON_PREFIX.glob("*.h")),
4343
"exclusions": [
44-
BSON_PREFIX / "bson-dsl.h",
4544
BSON_PREFIX / "bson-prelude.h",
4645
BSON_PREFIX / "bson.h",
4746
],

src/common/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ if (ENABLE_DEBUG_ASSERTIONS)
66
endif ()
77

88
configure_file (
9-
"${PROJECT_SOURCE_DIR}/src/common/common-config.h.in"
10-
"${PROJECT_BINARY_DIR}/src/common/common-config.h"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/src/common-config.h.in"
10+
"${CMAKE_CURRENT_BINARY_DIR}/src/common-config.h"
1111
)
File renamed without changes.

src/common/bson-dsl.md renamed to src/common/src/bson-dsl.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Using `bson-dsl.h`
1+
# Using `common-bson-dsl-private.h`
22

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

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

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

3434
# Generating BSON Data
@@ -899,7 +899,7 @@ correction.
899899
900900
Unfortunately, debugging through macro definitions is still a tricky subject.
901901
902-
`bson-dsl.h` includes a function `_bson_dsl_debug()`, which is invoked for every
902+
`common-bson-dsl-private.h` includes a function `_bson_dsl_debug()`, which is invoked for every
903903
DSL subcommand, including a string expressing the arguments to the command. If
904904
debug is "enabled" for the DSL, `_bson_dsl_debug` will write the debug output to
905905
`stderr`. If it is "disabled", `_bson_dsl_debug` is a no-op.
@@ -934,7 +934,7 @@ That is, MAP accepts a name `F` and zero or more arguments as `args`. For
934934
each argument `a` in `args`, expand one `F(x)`.
935935

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

File renamed without changes.

src/common/common-b64-private.h renamed to src/common/src/common-b64-private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include "common-prelude.h"
1818

19-
#ifndef COMMON_B64_PRIVATE_H
20-
#define COMMON_B64_PRIVATE_H
19+
#ifndef MONGO_C_DRIVER_COMMON_B64_PRIVATE_H
20+
#define MONGO_C_DRIVER_COMMON_B64_PRIVATE_H
2121

2222
#include <bson/bson.h>
2323

@@ -55,4 +55,4 @@ mcommon_b64_ntop (uint8_t const *src, size_t srclength, char *target, size_t tar
5555
int
5656
mcommon_b64_pton (char const *src, uint8_t *target, size_t targsize);
5757

58-
#endif /* COMMON_B64_PRIVATE_H */
58+
#endif /* MONGO_C_DRIVER_COMMON_B64_PRIVATE_H */
File renamed without changes.

src/common/bson-dsl.h renamed to src/common/src/common-bson-dsl-private.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "common-prelude.h"
22

3-
#ifndef BSON_BSON_DSL_H_INCLUDED
4-
#define BSON_BSON_DSL_H_INCLUDED
3+
#ifndef MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H
4+
#define MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H
55

66
/**
7-
* @file bson-dsl.h
7+
* @file common-bson-dsl-private.h
88
* @brief Define a C-preprocessor DSL for working with BSON objects
99
*
1010
* This file defines an embedded DSL for working with BSON objects consisely and
@@ -1274,4 +1274,4 @@ _bsonVisitIterAs_boolean (void)
12741274
// clang-format on
12751275

12761276

1277-
#endif // BSON_BSON_DSL_H_INCLUDED
1277+
#endif // MONGO_C_DRIVER_COMMON_BSON_DSL_PRIVATE_H
File renamed without changes.
File renamed without changes.

src/common/common-macros-private.h renamed to src/common/src/common-macros-private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include "common-prelude.h"
1818

19-
#ifndef MONGO_C_DRIVER_COMMON_MACROS_H
20-
#define MONGO_C_DRIVER_COMMON_MACROS_H
19+
#ifndef MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H
20+
#define MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H
2121

2222
/* Test only assert. Is a noop unless -DENABLE_DEBUG_ASSERTIONS=ON is set
2323
* during configuration */
@@ -68,4 +68,4 @@
6868
#define END_IGNORE_DEPRECATIONS
6969
#endif
7070

71-
#endif /* COMMON_MACROS_PRIVATE_H */
71+
#endif /* MONGO_C_DRIVER_COMMON_MACROS_PRIVATE_H */

src/common/common-md5-private.h renamed to src/common/src/common-md5-private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include "common-prelude.h"
1818

19-
#ifndef COMMON_MD5_PRIVATE_H
20-
#define COMMON_MD5_PRIVATE_H
19+
#ifndef MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H
20+
#define MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H
2121

2222
#include "bson/bson.h"
2323

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

3737
BSON_END_DECLS
3838

39-
#endif /* COMMON_MD5_PRIVATE_H */
39+
#endif /* MONGO_C_DRIVER_COMMON_MD5_PRIVATE_H */
File renamed without changes.
File renamed without changes.

src/common/mcd-string.h renamed to src/common/src/common-string-private.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,57 @@
1616

1717
#include "common-prelude.h"
1818

19-
#ifndef MCD_STRING_H
20-
#define MCD_STRING_H
19+
#ifndef MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H
20+
#define MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H
2121

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

25-
// mcd_string_t is an internal string type intended to replace the deprecated bson_string_t.
26-
// When bson_string_t is removed, migrate the implementation to mcd_string_t.
27-
typedef bson_string_t mcd_string_t;
25+
// mcommon_string_t is an internal string type intended to replace the deprecated bson_string_t.
26+
// When bson_string_t is removed, migrate the implementation to mcommon_string_t.
27+
typedef bson_string_t mcommon_string_t;
2828

29-
static BSON_INLINE mcd_string_t *
30-
mcd_string_new (const char *str)
29+
static BSON_INLINE mcommon_string_t *
30+
mcommon_string_new (const char *str)
3131
{
3232
BEGIN_IGNORE_DEPRECATIONS
3333
return bson_string_new (str);
3434
END_IGNORE_DEPRECATIONS
3535
}
3636
static BSON_INLINE char *
37-
mcd_string_free (mcd_string_t *string, bool free_segment)
37+
mcommon_string_free (mcommon_string_t *string, bool free_segment)
3838
{
3939
BEGIN_IGNORE_DEPRECATIONS
4040
return bson_string_free (string, free_segment);
4141
END_IGNORE_DEPRECATIONS
4242
}
4343
static BSON_INLINE void
44-
mcd_string_append (mcd_string_t *string, const char *str)
44+
mcommon_string_append (mcommon_string_t *string, const char *str)
4545
{
4646
BEGIN_IGNORE_DEPRECATIONS
4747
bson_string_append (string, str);
4848
END_IGNORE_DEPRECATIONS
4949
}
5050
static BSON_INLINE void
51-
mcd_string_append_c (mcd_string_t *string, char str)
51+
mcommon_string_append_c (mcommon_string_t *string, char str)
5252
{
5353
BEGIN_IGNORE_DEPRECATIONS
5454
bson_string_append_c (string, str);
5555
END_IGNORE_DEPRECATIONS
5656
}
5757
static BSON_INLINE void
58-
mcd_string_append_unichar (mcd_string_t *string, bson_unichar_t unichar)
58+
mcommon_string_append_unichar (mcommon_string_t *string, bson_unichar_t unichar)
5959
{
6060
BEGIN_IGNORE_DEPRECATIONS
6161
bson_string_append_unichar (string, unichar);
6262
END_IGNORE_DEPRECATIONS
6363
}
6464

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

6868
static BSON_INLINE void
69-
mcd_string_append_printf (mcd_string_t *string, const char *format, ...)
69+
mcommon_string_append_printf (mcommon_string_t *string, const char *format, ...)
7070
{
7171
va_list args;
7272
char *ret;
@@ -84,11 +84,11 @@ mcd_string_append_printf (mcd_string_t *string, const char *format, ...)
8484
}
8585

8686
static BSON_INLINE void
87-
mcd_string_truncate (mcd_string_t *string, uint32_t len)
87+
mcommon_string_truncate (mcommon_string_t *string, uint32_t len)
8888
{
8989
BEGIN_IGNORE_DEPRECATIONS
9090
bson_string_truncate (string, len);
9191
END_IGNORE_DEPRECATIONS
9292
}
9393

94-
#endif /* MCD_STRING_H */
94+
#endif /* MONGO_C_DRIVER_COMMON_STRING_PRIVATE_H */

src/common/common-thread-private.h renamed to src/common/src/common-thread-private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "common-config.h"
1919
#include "common-macros-private.h"
2020

21-
#ifndef COMMON_THREAD_PRIVATE_H
22-
#define COMMON_THREAD_PRIVATE_H
21+
#ifndef MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H
22+
#define MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H
2323

2424
#define BSON_INSIDE
2525
#include "bson/bson-compat.h"
@@ -206,4 +206,4 @@ bson_shared_mutex_unlock_shared (bson_shared_mutex_t *mtx)
206206

207207
BSON_END_DECLS
208208

209-
#endif /* COMMON_THREAD_PRIVATE_H */
209+
#endif /* MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H */
File renamed without changes.

src/libbson/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ target_include_directories(_libbson_build_interface INTERFACE
157157
# The generated src/
158158
${PROJECT_BINARY_DIR}/src/
159159
# The source directories of the common lib:
160-
${mongo-c-driver_SOURCE_DIR}/src/common/
160+
${mongo-c-driver_SOURCE_DIR}/src/common/src/
161161
# Generated:
162-
${mongo-c-driver_BINARY_DIR}/src/common/
162+
${mongo-c-driver_BINARY_DIR}/src/common/src/
163163
)
164164
target_link_libraries(_libbson_build_interface INTERFACE mongo::detail::c_platform)
165165

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

174174
# List of the primary BSON library targets that we are building

src/libbson/src/bson/bson-decimal128.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <bson/bson-decimal128.h>
2323
#include <bson/bson-types.h>
2424
#include <bson/bson-macros.h>
25-
#include <mcd-string.h>
25+
#include <common-string-private.h>
2626
#include <common-cmp-private.h>
2727

2828

src/libbson/src/bson/bson-error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <bson/bson-config.h>
2323
#include <bson/bson-error.h>
2424
#include <bson/bson-memory.h>
25-
#include <mcd-string.h>
25+
#include <common-string-private.h>
2626
#include <bson/bson-types.h>
2727

2828
// See `bson_strerror_r()` definition below.

src/libbson/src/bson/bson-iso8601-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <bson/bson-compat.h>
2525
#include <bson/bson-macros.h>
26-
#include <mcd-string.h>
26+
#include <common-string-private.h>
2727

2828

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

4444
BSON_END_DECLS
4545

src/libbson/src/bson/bson-iso8601.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error
282282

283283

284284
void
285-
_bson_iso8601_date_format (int64_t msec_since_epoch, mcd_string_t *str)
285+
_bson_iso8601_date_format (int64_t msec_since_epoch, mcommon_string_t *str)
286286
{
287287
time_t t;
288288
int64_t msecs_part;
@@ -309,9 +309,9 @@ _bson_iso8601_date_format (int64_t msec_since_epoch, mcd_string_t *str)
309309
#endif
310310

311311
if (msecs_part) {
312-
mcd_string_append_printf (str, "%s.%03" PRId64 "Z", buf, msecs_part);
312+
mcommon_string_append_printf (str, "%s.%03" PRId64 "Z", buf, msecs_part);
313313
} else {
314-
mcd_string_append (str, buf);
315-
mcd_string_append_c (str, 'Z');
314+
mcommon_string_append (str, buf);
315+
mcommon_string_append_c (str, 'Z');
316316
}
317317
}

src/libbson/src/bson/bson-keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <stdio.h>
1919

2020
#include <bson/bson-keys.h>
21-
#include <mcd-string.h>
21+
#include <common-string-private.h>
2222
#include <common-cmp-private.h>
2323

2424

src/libbson/src/bson/bson-oid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <bson/bson-context-private.h>
2727
#include <bson/bson-oid.h>
28-
#include <mcd-string.h>
28+
#include <common-string-private.h>
2929

3030

3131
/*

src/libbson/src/bson/bson-string.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <bson/bson-compat.h>
2222
#include <bson/bson-config.h>
2323
#include <common-cmp-private.h>
24-
#include <mcd-string.h>
24+
#include <common-string-private.h>
2525
#include <bson/bson-memory.h>
2626
#include <bson/bson-utf8.h>
2727
#include <bson/bson-string-private.h>
@@ -273,7 +273,7 @@ bson_string_append_c (bson_string_t *string, /* IN */
273273
if (BSON_UNLIKELY (string->alloc == (string->len + 1))) {
274274
cc[0] = c;
275275
cc[1] = '\0';
276-
mcd_string_append (string, cc);
276+
mcommon_string_append (string, cc);
277277
return;
278278
}
279279

@@ -312,7 +312,7 @@ bson_string_append_unichar (bson_string_t *string, /* IN */
312312

313313
if (len <= 6) {
314314
str[len] = '\0';
315-
mcd_string_append (string, str);
315+
mcommon_string_append (string, str);
316316
}
317317
}
318318

@@ -345,7 +345,7 @@ bson_string_append_printf (bson_string_t *string, const char *format, ...)
345345
va_start (args, format);
346346
ret = bson_strdupv_printf (format, args);
347347
va_end (args);
348-
mcd_string_append (string, ret);
348+
mcommon_string_append (string, ret);
349349
bson_free (ret);
350350
}
351351

0 commit comments

Comments
 (0)