Skip to content
This repository was archived by the owner on Oct 13, 2020. It is now read-only.

Commit 661e096

Browse files
committed
CDRIVER-2005 Replace raw assert()s with BSON_ASSERT
1 parent 0850239 commit 661e096

25 files changed

+975
-992
lines changed

examples/bcon-col-view.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ col_view_create (const char *stub, ...)
6767
keep_going = 0;
6868
break;
6969
default:
70-
assert (0);
70+
BSON_ASSERT (0);
7171
break;
7272
}
7373
}

examples/bcon-speed.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ main (int argc, char *argv[])
5252
return EXIT_FAILURE;
5353
}
5454

55-
assert (argc == 3);
55+
BSON_ASSERT (argc == 3);
5656

5757
n = atoi (argv[1]);
5858
bcon = (argv[2][0] == 'y') ? 1 : 0;

src/bson/bcon.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#define STACK_PUSH_ARRAY(statement) \
5050
do { \
51-
assert (ctx->n < (BCON_STACK_MAX - 1)); \
51+
BSON_ASSERT (ctx->n < (BCON_STACK_MAX - 1)); \
5252
ctx->n++; \
5353
STACK_I = 0; \
5454
STACK_IS_ARRAY = 1; \
@@ -57,24 +57,24 @@
5757

5858
#define STACK_PUSH_DOC(statement) \
5959
do { \
60-
assert (ctx->n < (BCON_STACK_MAX - 1)); \
60+
BSON_ASSERT (ctx->n < (BCON_STACK_MAX - 1)); \
6161
ctx->n++; \
6262
STACK_IS_ARRAY = 0; \
6363
statement; \
6464
} while (0)
6565

6666
#define STACK_POP_ARRAY(statement) \
6767
do { \
68-
assert (STACK_IS_ARRAY); \
69-
assert (ctx->n != 0); \
68+
BSON_ASSERT (STACK_IS_ARRAY); \
69+
BSON_ASSERT (ctx->n != 0); \
7070
statement; \
7171
ctx->n--; \
7272
} while (0)
7373

7474
#define STACK_POP_DOC(statement) \
7575
do { \
76-
assert (!STACK_IS_ARRAY); \
77-
assert (ctx->n != 0); \
76+
BSON_ASSERT (!STACK_IS_ARRAY); \
77+
BSON_ASSERT (ctx->n != 0); \
7878
statement; \
7979
ctx->n--; \
8080
} while (0)
@@ -288,7 +288,7 @@ _bcon_append_single (bson_t *bson,
288288
bson_append_iter (bson, key, -1, val->ITER);
289289
break;
290290
default:
291-
assert (0);
291+
BSON_ASSERT (0);
292292
break;
293293
}
294294
}
@@ -431,7 +431,7 @@ _bcon_extract_single (const bson_iter_t *iter,
431431
memcpy (val->ITER, iter, sizeof *iter);
432432
break;
433433
default:
434-
assert (0);
434+
BSON_ASSERT (0);
435435
break;
436436
}
437437

@@ -461,7 +461,7 @@ _bcon_append_tokenize (va_list *ap, bcon_append_t *u)
461461

462462
mark = va_arg (*ap, char *);
463463

464-
assert (mark != BCONE_MAGIC);
464+
BSON_ASSERT (mark != BCONE_MAGIC);
465465

466466
if (mark == NULL) {
467467
type = BCON_TYPE_END;
@@ -541,7 +541,7 @@ _bcon_append_tokenize (va_list *ap, bcon_append_t *u)
541541
u->ITER = va_arg (*ap, const bson_iter_t *);
542542
break;
543543
default:
544-
assert (0);
544+
BSON_ASSERT (0);
545545
break;
546546
}
547547
} else {
@@ -593,7 +593,7 @@ _bcon_extract_tokenize (va_list *ap, bcon_extract_t *u)
593593

594594
mark = va_arg (*ap, char *);
595595

596-
assert (mark != BCON_MAGIC);
596+
BSON_ASSERT (mark != BCON_MAGIC);
597597

598598
if (mark == NULL) {
599599
type = BCON_TYPE_END;
@@ -673,7 +673,7 @@ _bcon_extract_tokenize (va_list *ap, bcon_extract_t *u)
673673
u->ITER = va_arg (*ap, bson_iter_t *);
674674
break;
675675
default:
676-
assert (0);
676+
BSON_ASSERT (0);
677677
break;
678678
}
679679
} else {
@@ -781,17 +781,17 @@ bcon_append_ctx_va (bson_t *bson, bcon_append_ctx_t *ctx, va_list *ap)
781781
continue;
782782
}
783783

784-
assert (type == BCON_TYPE_UTF8);
784+
BSON_ASSERT (type == BCON_TYPE_UTF8);
785785

786786
key = u.UTF8;
787787
}
788788

789789
type = _bcon_append_tokenize (ap, &u);
790-
assert (type != BCON_TYPE_END);
790+
BSON_ASSERT (type != BCON_TYPE_END);
791791

792792
switch ((int) type) {
793793
case BCON_TYPE_BCON:
794-
assert (STACK_IS_ARRAY);
794+
BSON_ASSERT (STACK_IS_ARRAY);
795795
_bson_concat_array (STACK_BSON_CHILD, u.BCON, ctx);
796796

797797
break;
@@ -870,13 +870,13 @@ bcon_extract_ctx_va (bson_t *bson, bcon_extract_ctx_t *ctx, va_list *ap)
870870
continue;
871871
}
872872

873-
assert (type == BCON_TYPE_RAW);
873+
BSON_ASSERT (type == BCON_TYPE_RAW);
874874

875875
key = u.key;
876876
}
877877

878878
type = _bcon_extract_tokenize (ap, &u);
879-
assert (type != BCON_TYPE_END);
879+
BSON_ASSERT (type != BCON_TYPE_END);
880880

881881
if (type == BCON_TYPE_DOC_END) {
882882
STACK_POP_DOC (_noop ());

src/bson/bson-macros.h

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#endif
2525

2626

27-
#include <assert.h>
2827
#include <stdio.h>
2928

3029
#ifdef __cplusplus

src/bson/bson.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ BSON_BEGIN_DECLS
8080
*
8181
* bson_t *doc = bson_new();
8282
* bson_clear (&doc);
83-
* assert (doc == NULL);
83+
* BSON_ASSERT (doc == NULL);
8484
*/
8585
#define bson_clear(bptr) \
8686
do { \

src/jsonsl/jsonsl.c

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
#include "jsonsl.h"
7-
#include <assert.h>
87
#include <limits.h>
98
#include <ctype.h>
109
#include <bson-memory.h>

tests/TestSuite.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <bson.h>
1818

19-
#include <assert.h>
2019
#include <fcntl.h>
2120
#include <stdarg.h>
2221

@@ -220,7 +219,7 @@ TestSuite_SeedRand (TestSuite *suite, /* IN */
220219
unsigned seed;
221220
if (fd != -1) {
222221
n_read = read (fd, &seed, 4);
223-
assert (n_read == 4);
222+
BSON_ASSERT (n_read == 4);
224223
close (fd);
225224
test->seed = seed;
226225
return;

tests/TestSuite.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern "C" {
3535
#ifdef ASSERT
3636
#undef ASSERT
3737
#endif
38-
#define ASSERT assert
38+
#define ASSERT BSON_ASSERT
3939

4040

4141
#ifdef ASSERT_OR_PRINT

tests/bson-tests.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
BSON_BEGIN_DECLS
2828

2929

30-
#define assert_cmpstr(a, b) \
30+
#define BSON_ASSERT_CMPSTR(a, b) \
3131
do { \
3232
if (((a) != (b)) && !!strcmp ((a), (b))) { \
3333
fprintf (stderr, \
@@ -40,7 +40,7 @@ BSON_BEGIN_DECLS
4040
} while (0)
4141

4242

43-
#define assert_cmpint(a, eq, b) \
43+
#define BSON_ASSERT_CMPINT(a, eq, b) \
4444
do { \
4545
if (!((a) eq (b))) { \
4646
fprintf (stderr, \
@@ -112,15 +112,15 @@ bson_open (const char *filename, int flags, ...)
112112
int fd1 = bson_open ("failure.bad.bson", O_RDWR | O_CREAT, 0640); \
113113
int fd2 = \
114114
bson_open ("failure.expected.bson", O_RDWR | O_CREAT, 0640); \
115-
assert (fd1 != -1); \
116-
assert (fd2 != -1); \
117-
assert ((bson)->len == bson_write (fd1, bson_data, (bson)->len)); \
118-
assert ((expected)->len == \
115+
BSON_ASSERT (fd1 != -1); \
116+
BSON_ASSERT (fd2 != -1); \
117+
BSON_ASSERT ((bson)->len == bson_write (fd1, bson_data, (bson)->len)); \
118+
BSON_ASSERT ((expected)->len == \
119119
bson_write (fd2, expected_data, (expected)->len)); \
120120
bson_close (fd1); \
121121
bson_close (fd2); \
122122
} \
123-
assert (0); \
123+
BSON_ASSERT (0); \
124124
} \
125125
} while (0)
126126

tests/json-test.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ assemble_path (const char *parent_path,
4444
int path_len = (int) strlen (parent_path);
4545
int name_len = (int) strlen (child_name);
4646

47-
assert (path_len + name_len + 1 < MAX_TEST_NAME_LENGTH);
47+
BSON_ASSERT (path_len + name_len + 1 < MAX_TEST_NAME_LENGTH);
4848

4949
memset (dst, '\0', MAX_TEST_NAME_LENGTH * sizeof (char));
5050
strncat (dst, parent_path, path_len);
@@ -88,7 +88,7 @@ collect_tests_from_dir (char (*paths)[MAX_TEST_NAME_LENGTH] /* OUT */,
8888
}
8989

9090
while (1) {
91-
assert (paths_index < max_paths);
91+
BSON_ASSERT (paths_index < max_paths);
9292

9393
if (_findnext (handle, &info) == -1) {
9494
break;
@@ -117,9 +117,9 @@ collect_tests_from_dir (char (*paths)[MAX_TEST_NAME_LENGTH] /* OUT */,
117117
DIR *dir;
118118

119119
dir = opendir (dir_path);
120-
assert (dir);
120+
BSON_ASSERT (dir);
121121
while ((entry = readdir (dir))) {
122-
assert (paths_index < max_paths);
122+
BSON_ASSERT (paths_index < max_paths);
123123
if (strcmp (entry->d_name, "..") == 0 ||
124124
strcmp (entry->d_name, ".") == 0) {
125125
continue;
@@ -210,7 +210,7 @@ get_bson_from_json_file (char *filename)
210210
* test into a BSON blob and call the provided callback for
211211
* evaluation.
212212
*
213-
* It is expected that the callback will assert on failure, so if
213+
* It is expected that the callback will BSON_ASSERT on failure, so if
214214
* callback returns quietly the test is considered to have passed.
215215
*
216216
*-----------------------------------------------------------------------
@@ -233,9 +233,9 @@ install_json_test_suite (TestSuite *suite,
233233
for (i = 0; i < num_tests; i++) {
234234
test = get_bson_from_json_file (test_paths[i]);
235235
skip_json = strstr (test_paths[i], "/json") + strlen ("/json");
236-
assert (skip_json);
236+
BSON_ASSERT (skip_json);
237237
ext = strstr (skip_json, ".json");
238-
assert (ext);
238+
BSON_ASSERT (ext);
239239
ext[0] = '\0';
240240

241241
TestSuite_AddWC (suite,

tests/test-atomic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test1 (void)
2626
int32_t v = 0;
2727

2828
bson_atomic_int_add (&v, 1);
29-
assert (v == 1);
29+
BSON_ASSERT (v == 1);
3030
}
3131

3232

@@ -36,7 +36,7 @@ test2 (void)
3636
int64_t v = 0;
3737

3838
bson_atomic_int64_add (&v, 1);
39-
assert (v == 1);
39+
BSON_ASSERT (v == 1);
4040
}
4141

4242

0 commit comments

Comments
 (0)