Merge pull request #15 from fluffysquirrels/master
Fix runtime library compiler warnings and errors in GCC.
This commit is contained in:
commit
49031ea638
4 changed files with 34 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -11,6 +11,7 @@ Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
.deps
|
.deps
|
||||||
.libs
|
.libs
|
||||||
|
.dirstamp
|
||||||
|
|
||||||
test-driver
|
test-driver
|
||||||
*.log
|
*.log
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
* of the MIT license. See the LICENSE file for details.
|
* of the MIT license. See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "capnp_c.h"
|
#include "capnp_c.h"
|
||||||
#include "capnp_priv.h"
|
#include "capnp_priv.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -15,10 +19,15 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* Visual Studio notes:
|
/*
|
||||||
* Unless capn_segment is defined with __declspec(align(64)), check_segment_alignment
|
* 8 byte alignment is required for struct capn_segment.
|
||||||
* Fails to compile in x86 mode, as (sizeof(struct capn_segment)&7) -> (44 & 7) evaluates to 4
|
* This struct check_segment_alignment verifies this at compile time.
|
||||||
* Compiles in x64 mode, as (sizeof(struct capn_segment)&7) -> (80 & 7) evaluates to 0
|
*
|
||||||
|
* Unless capn_segment is defined with 8 byte alignment, check_segment_alignment
|
||||||
|
* fails to compile in x86 mode (or on another CPU with 32-bit pointers),
|
||||||
|
* as (sizeof(struct capn_segment)&7) -> (44 & 7) evaluates to 4.
|
||||||
|
* It compiles in x64 mode (or on another CPU with 64-bit pointers),
|
||||||
|
* as (sizeof(struct capn_segment)&7) -> (80 & 7) evaluates to 0.
|
||||||
*/
|
*/
|
||||||
struct check_segment_alignment {
|
struct check_segment_alignment {
|
||||||
unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1;
|
unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
* of the MIT license. See the LICENSE file for details.
|
* of the MIT license. See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "capnp_c.h"
|
#include "capnp_c.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(unix) && !defined(__APPLE__)
|
#if defined(unix) && !defined(__APPLE__)
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -22,6 +24,14 @@
|
||||||
typedef intmax_t ssize_t;
|
typedef intmax_t ssize_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Cross-platform macro ALIGNED_(x) aligns a struct by `x` bytes.
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define ALIGNED_(x) __declspec(align(x))
|
||||||
|
#endif
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define ALIGNED_(x) __attribute__ ((aligned(x)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -93,20 +103,19 @@ struct capn_tree *capn_tree_insert(struct capn_tree *root, struct capn_tree *n);
|
||||||
*
|
*
|
||||||
* cap specifies the segment capacity.
|
* cap specifies the segment capacity.
|
||||||
*
|
*
|
||||||
* When creating new structures len will be incremented until it reaces cap,
|
* When creating new structures len will be incremented until it reaches cap,
|
||||||
* at which point a new segment will be requested via capn->create. The
|
* at which point a new segment will be requested via capn->create. The
|
||||||
* create callback can either create a new segment or expand an existing
|
* create callback can either create a new segment or expand an existing
|
||||||
* one by incrementing cap and returning the expanded segment.
|
* one by incrementing cap and returning the expanded segment.
|
||||||
*
|
*
|
||||||
* data, len, and cap must all by 8 byte aligned
|
* data, len, and cap must all be 8 byte aligned, hence the ALIGNED_(8) macro
|
||||||
|
* on the struct definition.
|
||||||
*
|
*
|
||||||
* data, len, cap, and user should all set by the user. Other values
|
* data, len, cap, and user should all be set by the user. Other values
|
||||||
* should be zero initialized.
|
* should be zero initialized.
|
||||||
*/
|
*/
|
||||||
#ifdef _MSC_VER
|
|
||||||
__declspec(align(64))
|
struct ALIGNED_(8) capn_segment {
|
||||||
#endif
|
|
||||||
struct capn_segment {
|
|
||||||
struct capn_tree hdr;
|
struct capn_tree hdr;
|
||||||
struct capn_segment *next;
|
struct capn_segment *next;
|
||||||
struct capn *capn;
|
struct capn *capn;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue