Skip to content

Commit 53fa3bd

Browse files
committed
Merge branch 'CDRIVER-366-cpp' into 1.2.0-dev
* CDRIVER-366-cpp: CDRIVER-366: Update tests to compile using C++ compiler CDRIVER-366: Update examples to compile using C++ compiler CDRIVER-366: Fix enum related casting CDRIVER-366: Cast to correct type CDRIVER-366: Cast void to the actual types on assignments CDRIVER-366: `not` is a reserved keyword in C++ CDRIVER-366: `delete` is a reserved keyword in C++ CDRIVER-366: Cast allocations to correct types
2 parents b27a5da + 493018d commit 53fa3bd

Some content is hidden

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

71 files changed

+297
-293
lines changed

examples/example-scram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ main (int argc,
7171

7272
collection = mongoc_client_get_collection (client, "test", "test");
7373

74-
cursor = mongoc_collection_find (collection, 0, 0, 0, 0, &query, NULL, NULL);
74+
cursor = mongoc_collection_find (collection, (mongoc_query_flags_t)0, 0, 0, 0, &query, NULL, NULL);
7575

7676
mongoc_cursor_next (cursor, &doc);
7777

examples/mongoc-ping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ main (int argc,
5858
bson_init(&ping);
5959
bson_append_int32(&ping, "ping", 4, 1);
6060
database = mongoc_client_get_database(client, "test");
61-
cursor = mongoc_database_command(database, 0, 0, 1, 0, &ping, NULL, NULL);
61+
cursor = mongoc_database_command(database, (mongoc_query_flags_t)0, 0, 1, 0, &ping, NULL, NULL);
6262
if (mongoc_cursor_next(cursor, &reply)) {
6363
str = bson_as_json(reply, NULL);
6464
fprintf(stdout, "%s\n", str);

examples/mongoc-rpc-validate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ validate (const char *name) /* IN */
6767
exit (EXIT_FAILURE);
6868
}
6969

70-
buf = bson_malloc (st.st_size);
70+
buf = (uint8_t *)bson_malloc (st.st_size);
7171
if (buf == NULL) {
7272
fprintf (stderr, "%s: Failed to malloc %d bytes.\n",
7373
name, (int)st.st_size);

examples/mongoc-tail.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ query_collection (mongoc_collection_t *collection,
2626
mongoc_cursor_t *cursor;
2727
bson_t query;
2828
bson_t gt;
29+
int fflags = (MONGOC_QUERY_TAILABLE_CURSOR
30+
| MONGOC_QUERY_AWAIT_DATA
31+
| MONGOC_QUERY_SLAVE_OK);
2932

3033
BSON_ASSERT(collection);
3134

@@ -35,9 +38,7 @@ query_collection (mongoc_collection_t *collection,
3538
bson_append_document_end(&query, &gt);
3639

3740
cursor = mongoc_collection_find(collection,
38-
(MONGOC_QUERY_TAILABLE_CURSOR |
39-
MONGOC_QUERY_AWAIT_DATA |
40-
MONGOC_QUERY_SLAVE_OK),
41+
(mongoc_query_flags_t)fflags,
4142
0,
4243
0,
4344
0,

src/mongoc/mongoc-array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _mongoc_array_init (mongoc_array_t *array,
2828
array->len = 0;
2929
array->element_size = element_size;
3030
array->allocated = 128;
31-
array->data = bson_malloc0(array->allocated);
31+
array->data = (void *)bson_malloc0(array->allocated);
3232
}
3333

3434

@@ -57,7 +57,7 @@ _mongoc_array_copy (mongoc_array_t *dst,
5757
dst->len = src->len;
5858
dst->element_size = src->element_size;
5959
dst->allocated = src->allocated;
60-
dst->data = bson_malloc (dst->allocated);
60+
dst->data = (void *)bson_malloc (dst->allocated);
6161
memcpy (dst->data, src->data, dst->allocated);
6262
}
6363

@@ -87,7 +87,7 @@ _mongoc_array_append_vals (mongoc_array_t *array,
8787
len = (size_t)n_elements * array->element_size;
8888
if ((off + len) > array->allocated) {
8989
next_size = bson_next_power_of_two(off + len);
90-
array->data = bson_realloc(array->data, next_size);
90+
array->data = (void *)bson_realloc(array->data, next_size);
9191
array->allocated = next_size;
9292
}
9393

src/mongoc/mongoc-async-cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mongoc_async_cmd_tls_setup (mongoc_stream_t *stream,
6464
bson_error_t *error)
6565
{
6666
mongoc_stream_t *tls_stream;
67-
const char *host = ctx;
67+
const char *host = (const char *)ctx;
6868

6969
for (tls_stream = stream; tls_stream->type != MONGOC_STREAM_TLS;
7070
tls_stream = mongoc_stream_get_base_stream (tls_stream)) {
@@ -171,7 +171,7 @@ mongoc_async_cmd_new (mongoc_async_t *async,
171171
bson_return_val_if_fail(dbname, NULL);
172172
bson_return_val_if_fail(stream, NULL);
173173

174-
acmd = bson_malloc0 (sizeof (*acmd));
174+
acmd = (mongoc_async_cmd_t *)bson_malloc0 (sizeof (*acmd));
175175
acmd->async = async;
176176
acmd->expire_at = bson_get_monotonic_time () + (timeout_msec * 1000);
177177
acmd->stream = stream;

src/mongoc/mongoc-async.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mongoc_async_cmd (mongoc_async_t *async,
4242
mongoc_async_t *
4343
mongoc_async_new ()
4444
{
45-
mongoc_async_t *async = bson_malloc0 (sizeof (*async));
45+
mongoc_async_t *async = (mongoc_async_t *)bson_malloc0 (sizeof (*async));
4646

4747
return async;
4848
}
@@ -106,7 +106,7 @@ mongoc_async_run (mongoc_async_t *async,
106106
}
107107

108108
if (poll_size < async->ncmds) {
109-
poller = bson_realloc (poller, sizeof (*poller) * async->ncmds);
109+
poller = (mongoc_stream_poll_t *)bson_realloc (poller, sizeof (*poller) * async->ncmds);
110110
poll_size = async->ncmds;
111111
}
112112

src/mongoc/mongoc-buffer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ _mongoc_buffer_init (mongoc_buffer_t *buffer,
6767
}
6868

6969
if (!buf) {
70-
buf = realloc_func (NULL, buflen, NULL);
70+
buf = (uint8_t *)realloc_func (NULL, buflen, NULL);
7171
}
7272

7373
memset (buffer, 0, sizeof *buffer);
@@ -164,7 +164,7 @@ _mongoc_buffer_append_from_stream (mongoc_buffer_t *buffer,
164164
buffer->off = 0;
165165
if (!SPACE_FOR (buffer, size)) {
166166
buffer->datalen = bson_next_power_of_two (size + buffer->len + buffer->off);
167-
buffer->data = buffer->realloc_func (buffer->data, buffer->datalen, NULL);
167+
buffer->data = (uint8_t *)buffer->realloc_func (buffer->data, buffer->datalen, NULL);
168168
}
169169
}
170170

@@ -231,7 +231,7 @@ _mongoc_buffer_fill (mongoc_buffer_t *buffer,
231231

232232
if (!SPACE_FOR (buffer, min_bytes)) {
233233
buffer->datalen = bson_next_power_of_two (buffer->len + min_bytes);
234-
buffer->data = buffer->realloc_func (buffer->data, buffer->datalen,
234+
buffer->data = (uint8_t *)buffer->realloc_func (buffer->data, buffer->datalen,
235235
buffer->realloc_data);
236236
}
237237

@@ -307,7 +307,7 @@ _mongoc_buffer_try_append_from_stream (mongoc_buffer_t *buffer,
307307
buffer->off = 0;
308308
if (!SPACE_FOR (buffer, size)) {
309309
buffer->datalen = bson_next_power_of_two (size + buffer->len + buffer->off);
310-
buffer->data = buffer->realloc_func (buffer->data, buffer->datalen, NULL);
310+
buffer->data = (uint8_t *)buffer->realloc_func (buffer->data, buffer->datalen, NULL);
311311
}
312312
}
313313

src/mongoc/mongoc-bulk-operation.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mongoc_bulk_operation_new (bool ordered)
4949
{
5050
mongoc_bulk_operation_t *bulk;
5151

52-
bulk = bson_malloc0 (sizeof *bulk);
52+
bulk = (mongoc_bulk_operation_t *)bson_malloc0 (sizeof *bulk);
5353
bulk->ordered = ordered;
5454

5555
_mongoc_array_init (&bulk->commands, sizeof (mongoc_write_command_t));
@@ -127,7 +127,7 @@ mongoc_bulk_operation_remove (mongoc_bulk_operation_t *bulk, /* IN */
127127
mongoc_write_command_t,
128128
bulk->commands.len - 1);
129129
if ((last->type == MONGOC_WRITE_COMMAND_DELETE) &&
130-
last->u.delete.multi) {
130+
last->u.delete_.multi) {
131131
_mongoc_write_command_delete_append (last, selector);
132132
EXIT;
133133
}
@@ -158,7 +158,7 @@ mongoc_bulk_operation_remove_one (mongoc_bulk_operation_t *bulk, /* IN */
158158
mongoc_write_command_t,
159159
bulk->commands.len - 1);
160160
if ((last->type == MONGOC_WRITE_COMMAND_DELETE) &&
161-
!last->u.delete.multi) {
161+
!last->u.delete_.multi) {
162162
_mongoc_write_command_delete_append (last, selector);
163163
EXIT;
164164
}
@@ -237,16 +237,15 @@ mongoc_bulk_operation_replace_one (mongoc_bulk_operation_t *bulk,
237237
mongoc_write_command_t command = { 0 };
238238
size_t err_off;
239239
mongoc_write_command_t *last;
240+
int flags = BSON_VALIDATE_DOT_KEYS|BSON_VALIDATE_DOLLAR_KEYS;
240241

241242
bson_return_if_fail (bulk);
242243
bson_return_if_fail (selector);
243244
bson_return_if_fail (document);
244245

245246
ENTRY;
246247

247-
if (!bson_validate (document,
248-
(BSON_VALIDATE_DOT_KEYS | BSON_VALIDATE_DOLLAR_KEYS),
249-
&err_off)) {
248+
if (!bson_validate (document, (bson_validate_flags_t)flags, &err_off)) {
250249
MONGOC_WARNING ("%s(): replacement document may not contain "
251250
"$ or . in keys. Ignoring document.",
252251
__FUNCTION__);
@@ -499,7 +498,7 @@ mongoc_bulk_operation_set_client (mongoc_bulk_operation_t *bulk,
499498
{
500499
bson_return_if_fail (bulk);
501500

502-
bulk->client = client;
501+
bulk->client = (mongoc_client_t *)client;
503502
}
504503

505504

src/mongoc/mongoc-client-pool.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mongoc_client_pool_new (const mongoc_uri_t *uri)
7979

8080
bson_return_val_if_fail(uri, NULL);
8181

82-
pool = bson_malloc0(sizeof *pool);
82+
pool = (mongoc_client_pool_t *)bson_malloc0(sizeof *pool);
8383
mongoc_mutex_init(&pool->mutex);
8484
_mongoc_queue_init(&pool->queue);
8585
pool->uri = mongoc_uri_copy(uri);
@@ -119,7 +119,7 @@ mongoc_client_pool_destroy (mongoc_client_pool_t *pool)
119119

120120
bson_return_if_fail(pool);
121121

122-
while ((client = _mongoc_queue_pop_head(&pool->queue))) {
122+
while ((client = (mongoc_client_t *)_mongoc_queue_pop_head(&pool->queue))) {
123123
mongoc_client_destroy(client);
124124
}
125125

@@ -149,7 +149,7 @@ mongoc_client_pool_pop (mongoc_client_pool_t *pool)
149149
mongoc_mutex_lock(&pool->mutex);
150150

151151
again:
152-
if (!(client = _mongoc_queue_pop_head(&pool->queue))) {
152+
if (!(client = (mongoc_client_t *)_mongoc_queue_pop_head(&pool->queue))) {
153153
if (pool->size < pool->max_pool_size) {
154154
client = _mongoc_client_new_from_uri(pool->uri, pool->topology);
155155
#ifdef MONGOC_ENABLE_SSL
@@ -181,7 +181,7 @@ mongoc_client_pool_try_pop (mongoc_client_pool_t *pool)
181181

182182
mongoc_mutex_lock(&pool->mutex);
183183

184-
if (!(client = _mongoc_queue_pop_head(&pool->queue))) {
184+
if (!(client = (mongoc_client_t *)_mongoc_queue_pop_head(&pool->queue))) {
185185
if (pool->size < pool->max_pool_size) {
186186
client = _mongoc_client_new_from_uri(pool->uri, pool->topology);
187187
#ifdef MONGOC_ENABLE_SSL
@@ -211,7 +211,7 @@ mongoc_client_pool_push (mongoc_client_pool_t *pool,
211211
mongoc_mutex_lock(&pool->mutex);
212212
if (pool->size > pool->min_pool_size) {
213213
mongoc_client_t *old_client;
214-
old_client = _mongoc_queue_pop_head (&pool->queue);
214+
old_client = (mongoc_client_t *)_mongoc_queue_pop_head (&pool->queue);
215215
if (old_client) {
216216
mongoc_client_destroy (old_client);
217217
pool->size--;

0 commit comments

Comments
 (0)