mongodb/libbson — pull request #9 by Maxime2 (2013-09-04 01:43:54+00:00)
Title: alignment fix

* size of enum type is depending on implementation you cannot assume it is always 4 bytes.
* structures are aligned according to the element of maximal size; on some platforms pointer can be of 8 bytes long, thus it is better to make flags of bson_uint64_t type.

When I try to build the current master with clang 4.2.1 I get a bunch of warning about changing alignment in explicit type casts (output is below). This patch fixes these warnings.

$ make
make ` if test "x0" = x0; then test -z "" -o "x" = x0 && echo -s; else test "x" = x0 && echo -s; fi` all-am
CC libbson_1_0_la-bson.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson.c:91:31: warning: cast from 'bson_impl_inline_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_impl_alloc_t *alloc = (bson_impl_alloc_t *)impl;
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:140:18: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
(tmp = (bson_impl_alloc_t *)tmp->parent)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:170:35: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
return bson_impl_alloc_grow((bson_impl_alloc_t *)bson, size);
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:183:33: warning: cast from 'const bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_impl_alloc_t *impl = (bson_impl_alloc_t *)bson;
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:269:20: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
(bson = ((bson_impl_alloc_t *)bson)->parent)) {
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:335:33: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_impl_alloc_t *aparent = (bson_impl_alloc_t *)bson;
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:336:32: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_impl_alloc_t *achild = (bson_impl_alloc_t *)child;
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:1249:30: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_impl_alloc_t *impl = (bson_impl_alloc_t *)bson;
^~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:1303:13: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
impl_a = (bson_impl_alloc_t *)b;
^~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:1382:11: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
adst = (bson_impl_alloc_t *)dst;
^~~~~~~~~~~~~~~~~~~~~~~~
bson/bson.c:1473:19: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_free(*((bson_impl_alloc_t *)bson)->buf);
^~~~~~~~~~~~~~~~~~~~~~~~~
12 warnings generated.
CC libbson_1_0_la-bson-context.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-clock.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-error.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson-error.c:40:56: warning: format string is not a string literal [-Wformat-nonliteral]
vsnprintf(error->message, sizeof error->message, format, args);
^~~~~~
2 warnings generated.
CC libbson_1_0_la-bson-iter.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-keys.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-md5.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson-md5.c:177:21: warning: cast from 'const bson_uint8_t *' (aka 'const unsigned char *') to 'const bson_uint32_t *' (aka 'const unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
X = (const bson_uint32_t *)data;
^~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
CC libbson_1_0_la-bson-oid.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-reader.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson-reader.c:116:29: warning: cast from 'bson_reader_t *' to 'bson_reader_fd_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_reader_fd_t *real = (bson_reader_fd_t *)reader;
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:134:29: warning: cast from 'bson_reader_t *' to 'bson_reader_fd_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_reader_fd_t *real = (bson_reader_fd_t *)reader;
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:220:31: warning: cast from 'bson_reader_t *' to 'bson_reader_data_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_reader_data_t *real = (bson_reader_data_t *)reader;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:286:33: warning: cast from 'bson_reader_t *' to 'bson_reader_fd_t *' increases required alignment from 4 to 8 [-Wcast-align]
bson_reader_fd_t *fd = (bson_reader_fd_t *)reader;
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:311:34: warning: cast from 'bson_reader_t *' to 'bson_reader_fd_t *' increases required alignment from 4 to 8 [-Wcast-align]
return bson_reader_fd_read((bson_reader_fd_t *)reader, reached_eof);
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:313:36: warning: cast from 'bson_reader_t *' to 'bson_reader_data_t *' increases required alignment from 4 to 8 [-Wcast-align]
return bson_reader_data_read((bson_reader_data_t *)reader, reached_eof);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:330:34: warning: cast from 'bson_reader_t *' to 'bson_reader_fd_t *' increases required alignment from 4 to 8 [-Wcast-align]
return bson_reader_fd_tell((bson_reader_fd_t *)reader);
^~~~~~~~~~~~~~~~~~~~~~~~~~
bson/bson-reader.c:332:36: warning: cast from 'bson_reader_t *' to 'bson_reader_data_t *' increases required alignment from 4 to 8 [-Wcast-align]
return bson_reader_data_tell((bson_reader_data_t *)reader);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 warnings generated.
CC libbson_1_0_la-bson-string.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson-string.c:136:31: warning: format string is not a string literal [-Wformat-nonliteral]
n = vsnprintf(buf, len, format, my_args);
^~~~~~
2 warnings generated.
CC libbson_1_0_la-bson-utf8.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CC libbson_1_0_la-bson-writer.lo
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
bson/bson-writer.c:81:8: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
b = (bson_impl_alloc_t *)&writer->b;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
CCLD libbson-1.0.la
CC test_bson-test-bson.o
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
./tests/test-bson.c:910:12: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
assert(((bson_impl_alloc_t *)&b)->alloclen == 1024);
^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:90:5: note: expanded from macro 'assert'
((expr) \
^
./tests/test-bson.c:944:12: warning: cast from 'bson_t *' to 'bson_impl_alloc_t *' increases required alignment from 4 to 8 [-Wcast-align]
assert(((bson_impl_alloc_t *)&b)->alloclen == 1024);
^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:90:5: note: expanded from macro 'assert'
((expr) \
^
3 warnings generated.
CCLD test-bson
CC test_bson_clock-test-bson-clock.o
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CCLD test-bson-clock
CC test_bson_error-test-bson-error.o
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CCLD test-bson-error
CC test_bson_iter-test-bson-iter.o
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.
CCLD test-bson-iter
CC test_bson_json-test-bson-json.o
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-